Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature request] Add Scrollbar width detection #11

Open
MiddleSchoolStudent opened this issue Dec 4, 2024 · 4 comments
Open

[feature request] Add Scrollbar width detection #11

MiddleSchoolStudent opened this issue Dec 4, 2024 · 4 comments
Labels
enhancement New feature or request Lies Related to lied fingerprints

Comments

@MiddleSchoolStudent
Copy link

First of all, I want to express my admiration for your work. Thank you for your efforts in the field of bot and antibot technologies.

I’d like to suggest a detection method that has been used in strict antibot solutions (eg, AdScore) for several years. However, this method has not yet been widely implemented in mainstream antibots like Shape, Akamai, Cloudflare, px

The proposed method involves detecting the scrollbar width, as demonstrated in the following function:

function scrollbarWidth() {
    const div1 = document.createElement("div");
    div1.style.visibility = "hidden";
    div1.style.overflow = "scroll";
    div1.style.msOverflowStyle = "scrollbar";
    document.body.appendChild(div1);
    const div2 = document.createElement("div");
    div1.appendChild(div2);
    const width = div1.offsetWidth - div2.offsetWidth;
    document.body.removeChild(div1);
    return width;
}

Based on testing:

  • On Windows (Chrome), the value is 17.
  • On macOS, it is 15.
  • On Ubuntu, it is also 15.

For bots, this value should correspond to the OS being emulated. For antibots, this could serve as a straightforward lied detection method.

I hope this idea proves useful to your project(s), thanks.

@kaliiiiiiiiii
Copy link
Owner

Thanks for your suggestion!
Does this only depend on the OS?
What about different scaling, screen size, viewport etc. ?

@kaliiiiiiiiii kaliiiiiiiiii added enhancement New feature or request Lies Related to lied fingerprints labels Dec 4, 2024
@MiddleSchoolStudent
Copy link
Author

MiddleSchoolStudent commented Dec 4, 2024

Thanks for your suggestion! Does this only depend on the OS? What about different scaling, screen size, viewport etc. ?

  • Does this only depend on the OS?

    The scrollbar width is indeed dependent on the OS. For example, in Windows, Chromium retrieves this value using the Windows API ::GetSystemMetrics. This method consistently returned a value of 17 for Windows:

using System.Runtime.InteropServices;

[DllImport("user32.dll")]
static extern int GetSystemMetrics(int nIndex);

const int SM_CXVSCROLL = 2;
int scrollBarWidth = GetSystemMetrics(SM_CXVSCROLL);
Console.WriteLine($"Scrollbar width: {scrollBarWidth}"); // 17
  • What about scaling, screen size, viewport, etc.?

    By default, when opening a new page in the browser, the zoom level is set to 100%. This means that the scrollbar width calculation in a fresh page is consistent with the OS's default settings. However, relying solely on this assumption may not be sufficient for all scenarios, as user-specific settings or other factors could still influence the results.

    For a more robust solution, we could add a detection mechanism to account for scaling factors. For example, using window.devicePixelRatio can help refine the scrollbar width measurement by compensating for scaling introduced by the user or the system.

function getScrollbarWidth() {
    const container = document.createElement("div");
    container.style.position = "absolute";
    container.style.top = "-9999px";
    container.style.width = "100px"; 
    container.style.height = "100px"; 
    container.style.overflow = "scroll";
    container.style.msOverflowStyle = "scrollbar"; 
    document.body.appendChild(container);

    const inner = document.createElement("div");
    inner.style.width = "100%";
    inner.style.height = "100%";
    container.appendChild(inner);

    const rawScrollbarWidth = container.offsetWidth - inner.offsetWidth;
    const devicePixelRatio = window.devicePixelRatio;
    const actualScrollbarWidth = rawScrollbarWidth * devicePixelRatio;
    document.body.removeChild(container);

    return { devicePixelRatio: devicePixelRatio, actualScrollbarWidth };
}

This approach helps ensure that the computed value reflects the scaling factor, offering a more robust and accurate method for detecting the scrollbar width.

@kaliiiiiiiiii
Copy link
Owner

kaliiiiiiiiii commented Dec 4, 2024

This approach helps ensure that the computed value reflects the scaling factor, offering a more robust and accurate method for detecting the scrollbar width.

Hmm this really sounds AI generated to me - I get the point but will have to do more testing on that before implementing

The OS part makes sense to me though

@MiddleSchoolStudent
Copy link
Author

MiddleSchoolStudent commented Dec 4, 2024

This approach helps ensure that the computed value reflects the scaling factor, offering a more robust and accurate method for detecting the scrollbar width.

Hmm this really sounds AI generated to me - I get the point but will have to do more testing on that before implementing

The OS part makes sense to me though

How wise of you I had AI generate the code for me and I copied it right over lol , wait for your results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Lies Related to lied fingerprints
Projects
None yet
Development

No branches or pull requests

2 participants