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
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.
You can define an object with all necessary consistent parameters:
Now, make as many of them as you like, and store them all in an array. Then, select on of these objects at random:
Finally, use
choice
to define the properties: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
andcanvas
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.