简体   繁体   中英

How to unset navigator.webdriver in headless chrome using selenium?

How can i make navigator.webdriver disappear in a headless chrome?

options.setExperimentalOption("excludeSwitches", Arrays.asList("enable-automation"));
The above line can make navigator.webdriver disappear in a non headless chrome.But it doesn't work with a headless chrome.
I found evaluateOnNewDocument from puppeteer that can set that property just before page to load.But how to achieve the same with selenium?

await page.evaluateOnNewDocument(() => {
  Object.defineProperty(navigator, 'webdriver', {
    get: () => false,
  });
});

The best way is to use older version of chromedriver. Chrome driver version 2.34 with Chromuim browser version 63 dont implement navigator.webdriver property.

i did it.i downloaded chrome version 62.0.3202.45 and the corresponding chromedriver . no automatic webdriver property and allow headless download.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM