How do you disable "navigator.webdriver" in chromedriver?

Viewed 8575

After hours of searching for methods, I was not able to find any ways that would simply work.

The only way I could find was Setting the "pageLoadingStrategy" capability value to "eager", and then immediately executing some javascript so it could change the navigator.webdriver value before the page was rendered. But then you need to change the value after every request and it's not really reliable.

How do you set this before executing any requests? Is there a flag?

2 Answers

After looking at the chrome source code for a good while, I finally figured out what flag needs to be used to disable that navigator.webdriver nuisance.

Here is the flag that needs to be used when starting chromedriver. It completely disables "webdriver=true" from even showing up. :)

--disable-blink-features=AutomationControlled

Also here's some more features that can be enabled/disabled.

Features

Enable Flag:
--enable-blink-features=example1,example2,example3

Disable Flag
--disable-blink-features=example1,example2,example3

Hopefully this helps someone who has also come across this problem. Thanks for looking

from selenium.webdriver import Chrome
driver = Chrome('./chromedriver')
driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
  "source": """
    Object.defineProperty(navigator, 'webdriver', {
     get: () => undefined
    })
  """
})
driver.get('https://intoli.com/blog/not-possible-to-block-chrome-headless/chrome-headless-test.html')

success for chrome version 80.

Related