skip to Main Content

I want to randomly execute a bunch of strings within the same script.

I’d like to run it randomly so that I get a different screen resolution every time I start the browser, instead of being stuck at 1920*1080 for example.

(I’m using violentmonkey by the way)
Thanks.

Run it (1920×1080)

Object.defineProperty(window.screen, "availWidth", { get: function(){return 1920; }});
Object.defineProperty(window.screen, "width", { get: function(){return 1920; }});

Object.defineProperty(window.screen, "availHeight", { get: function(){return 1080; }});
Object.defineProperty(window.screen, "height", { get: function(){return 1080; }});

Object.defineProperty(window, "innerWidth", { get: function(){return 1920; }});
Object.defineProperty(window, "innerHeight", { get: function(){return 974; }});

Object.defineProperty(window, "outerWidth", { get: function(){return 1920; }});
Object.defineProperty(window, "outerHeight", { get: function(){return 1040; }});

Object.defineProperty(window, "devicePixelRatio", { get: function(){return 1; }});

or this one (could be 2560 x 1440)

Object.defineProperty(window.screen, "availWidth", { get: function(){return ; }});
Object.defineProperty(window.screen, "width", { get: function(){return ; }});

Object.defineProperty(window.screen, "availHeight", { get: function(){return ; }});
Object.defineProperty(window.screen, "height", { get: function(){return ; }});

Object.defineProperty(window, "innerWidth", { get: function(){return ; }});
Object.defineProperty(window, "innerHeight", { get: function(){return ; }});

Object.defineProperty(window, "outerWidth", { get: function(){return ; }});
Object.defineProperty(window, "outerHeight", { get: function(){return ; }});

Object.defineProperty(window, "devicePixelRatio", { get: function(){return ; }});

or that one… (could be 1280 x 720)

Object.defineProperty(window.screen, "availWidth", { get: function(){return ; }});
Object.defineProperty(window.screen, "width", { get: function(){return ; }});

Object.defineProperty(window.screen, "availHeight", { get: function(){return ; }});
Object.defineProperty(window.screen, "height", { get: function(){return ; }});

Object.defineProperty(window, "innerWidth", { get: function(){return ; }});
Object.defineProperty(window, "innerHeight", { get: function(){return ; }});

Object.defineProperty(window, "outerWidth", { get: function(){return ; }});
Object.defineProperty(window, "outerHeight", { get: function(){return ; }});

Object.defineProperty(window, "devicePixelRatio", { get: function(){return ; }});

I haven’t tried anything, even though I’ve spent hours trying to find a way to do it.

2

Answers


  1. Chosen as BEST ANSWER

    I don't want to randomly select objects but rather have different resolution settings already in place (1920*1080, 1280 x 720, 2560 x 1440) so that the script can randomly choose between these different resolutions to run. Randomly selecting each object would be weird and a pretty nonsensical idea to begin with since I'd end up with an outside width of 2560 and an available width of 3840..... which is impossible and would make me stick out like a sore thumb and therefore be more identifiable.


  2. You can define an object with all necessary consistent parameters:

    {
      "availWidth": 1920,
      "width": 1920,
      "availHeight": 1080,
      "height": 1080,
      "innerWidth": 1920,
      "innerHeight": 974,
      "outerWidth": 1920,
      "outerHeight": 1040,
      "devicePixelRatio": 1
    }
    

    Now, make as many of them as you like, and store them all in an array. Then, select on of these objects at random:

    const choices = [ {
      "availWidth": 1920,
      ...
    }, {
      "availWidth": ...
    }, {
      ...
    }];
    
    const choice = choices[Math.floor(Math.random() * choices.length)];
    

    Finally, use choice to define the properties:

    Object.defineProperty(window.screen, "availWidth", { get: function() { return choice.availWidth; }});
    Object.defineProperty(...);
    ...
    

    Important note:

    I assume you are trying to do this to resist fingerprinting, since I "fingerprinted" the use of spaces and newlines in the code and found out it likely comes from here.

    Firstly, be aware that this code is only half-baked. You’d need an additional bind(null) to hide the source code that modified the value (source). The same source also mentions that choosing random values actually makes you stand out more, so rather than randomizing, they recommend using just one very common set of values and stick with that.

    Secondly, various people on various websites keep pointing out that iframe and canvas fingerprinting exists. Frankly speaking, there’s a rabbit hole to go down about all methods and possible data points. You can spend hours trying to cover up all of them, until you probably end up using native browser features (if available, e.g. Firefox) and/or one of the hundreds of extensions which attempt to do this already (way too many to list, and that would be out of scope for Stack Overflow).

    And lastly, whatever you do, keep in mind that doing/enabling/installing any spoofing may be detectable and then existence and methodology themselves become even better data points for fingerprinting.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search