I want to spoof some attributes in the Navigator object for experimenting with anti fingerprinting by writing a Chrome extension.
I used techniques discussed here: Access variables and functions defined in page context from an extension
I tried both method 1 and 4. (code below is method 1 modified according to: Chrome Extension: Accessing `window` works on remote websites, but not possible in localhost)
While this changes the User-Agent and seems to actually work it gets detected as a bot on pages like https://www.browserscan.net/bot-detection why is that? Is there any way around it?
Note: The spoofed user agent is same as the authentic user agent to make sure that this is not the problem.
manifest.json
{
"manifest_version": 3,
"name": "Helper",
"description": "Base Level Extension",
"version": "1.0",
"background": {"service_worker": "bg.js"},
"host_permissions": ["<all_urls>"],
"permissions": [
"scripting",
"contentSettings",
"tabs",
"storage",
"declarativeNetRequest",
"declarativeNetRequestWithHostAccess"
],
"declarative_net_request": {
"rule_resources": [{
"id": "ruleset",
"enabled": true,
"path": "rules.json"
}]
},
"action": {
"default_popup": "helper.html",
"default_icon": "helper.png"
}
bg.js
chrome.runtime.onInstalled.addListener(async () => {
const old = await chrome.scripting.getRegisteredContentScripts();
if (old[0]) await chrome.scripting.unregisterContentScripts({ids: old.map(s => s.id)});
await chrome.scripting.registerContentScripts([{
id: 'write',
js: ['write.js'],
matches: ['<all_urls>'],
runAt: 'document_start',
world: 'MAIN',
}]);
write.js
var navigator = window.navigator;
var modifiedNavigator;
if ('userAgent' in Navigator.prototype) {
modifiedNavigator = Navigator.prototype;
} else {
modifiedNavigator = Object.create(navigator);
Object.defineProperty(window, 'navigator', {
value: modifiedNavigator,
configurable: false,
enumerable: false,
writable: false
});
}
console.info(navigator.userAgent)
console.info(navigator.appName)
console.info(navigator.appVersion)
console.info(navigator.platform)
var ua = navigator.userAgent
// I tried this
modifiedNavigator.__defineGetter__('userAgent', function () { return ua; });
// As well as this
Object.defineProperties(modifiedNavigator, {
userAgent: {
value: navigator.userAgent.replace(/([^)]+)/, 'Windows NT 5.1'),
configurable: false,
enumerable: true,
writable: false
}
});