Skip to content

Instantly share code, notes, and snippets.

@SkyzohKey
Last active June 4, 2024 10:23
Show Gist options
  • Save SkyzohKey/1f8fe7c070cfe9e98f5dc9ec0c5caee2 to your computer and use it in GitHub Desktop.
Save SkyzohKey/1f8fe7c070cfe9e98f5dc9ec0c5caee2 to your computer and use it in GitHub Desktop.
~ Spoof the reported window.screen as the most common one so that it can't be used to fingerprint browser.
// ==UserScript==
// @name Spoof screen resolution & color depth
// @namespace https://skyzohlabs.be
// @version 1.0.5
// @description Spoof the reported window.screen as the most common one so that it can't be used to fingerprint browser.
// @author SkyzohKey
// @include http://*
// @include https://*
// @run-at document-end
// @grant none
// @downloadURL https://gist.github.com/SkyzohKey/1f8fe7c070cfe9e98f5dc9ec0c5caee2/raw/screen-spoofer.user.js
// @updateURL https://gist.github.com/SkyzohKey/1f8fe7c070cfe9e98f5dc9ec0c5caee2/raw/screen-spoofer.user.js
// ==/UserScript==
(function() {
"use strict";
/**
* Define property on an object.
*/
var defineProp = function(obj, prop, val) {
Object.defineProperty(obj, prop, {
enumerable: true,
configurable: true,
value: val
});
};
/**
* Return screen attributes based on the most commons ones.
*/
var getScreenAttrs = function() {
return {
width: 1366,
height: 768,
colorDepth: 24,
pixelDepth: 24
};
};
/**
* Spoof screen resolution.
*/
var spoofScreenResolution = function() {
var screen = getScreenAttrs();
defineProp(window.screen, "width", screen.width);
defineProp(window.screen, "height", screen.height);
defineProp(window.screen, "availWidth", screen.width);
defineProp(window.screen, "availHeight", screen.height);
defineProp(window.screen, "top", 0);
defineProp(window.screen, "left", 0);
defineProp(window.screen, "availTop", 0);
defineProp(window.screen, "availLeft", 0);
defineProp(window.screen, "colorDepth", screen.colorDepth);
defineProp(window.screen, "pixelDepth", screen.pixelDepth);
/**
* @todo Implement window.innerHeight, window.innerWidth, etc...
* @see https://developer.mozilla.org/en-US/docs/Web/API/Screen
*/
};
/**
* Initialize script
*/
var init = function() {
// LET SPOOF THAT FUCKIN' RES/COLOR DEPTH
spoofScreenResolution();
};
init();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment