In order to make my Chrome Browser undetectable when using Selenium I'm trying to modify the get function on the webdriver to answer always with false. To do so, I've created a Chrome Extension that consist of two files:
1) Manifest.json (It essentialy says that my custom javascript should be injected in the page ASAP)
{
"manifest_version": 2,
"name": "webdriverInjector",
"version": "1.0.0",
"content_scripts": [
{
"matches": ["*://*/*"],
"js": ["injected-javascript.js"],
"run_at": "document_start"
}
]
}
2) Injected-javascript.js
if (document.readyState === "loading") {
Object.defineProperty(navigator, 'webdriver', {
get: () => false,
});
console.log(window.navigator);
}
I was able to successfully install the Extension on Chrome and it works: on the console I can see that the property is set:
But after the page is fully loaded I'm not able to see the same property because it seems that it doesn't exist anymore and this is really strange. Isn't my property supposed to exist even after other script execution?
Here is the result of the console.log(navigator) I get after the page is fully loaded:
And if I try to console.log the navigator.webdriver variable I get "undefined" (if I was using Chrome without Selenium) or I get "true" (if I was using Chrome with Selenium) but never "false" as expected.
What am I doing wrong?