How do I mimic or set plugin for Chrome Headless

Viewed 1509

How do I mimic or set plugins length for Selenium chrome headless? I am following this guide

I cannot find anything on doing this through Chrome options.

The reason I want this is I want to make chrome headless as undetectable as possible.

Try the following. Plugin length is still an issue.

from selenium.webdriver.chrome.options import Options
from selenium import webdriver
options = Options()
options.add_argument("--headless");
user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3240.0 Safari/537.36'
options.add_argument(f'user-agent={user_agent}')
options.add_argument("--lang=en-US,en");

driver = webdriver.Chrome(chrome_options=options)

driver.get('https://intoli.com/blog/making-chrome-headless-undetectable/chrome-headless-test.html')
driver.save_screenshot("screenshot5.png")

driver.close()

As you can see below, plugin length is still quite detectable.

enter image description here

Is this possible or just a limitation of selenium python?

1 Answers
driver.execute_cdp_cmd('Page.addScriptToEvaluateOnNewDocument', {
  "source": "
     Object.defineProperty(navigator, 'plugins', {
       get: () => [1, 2, 3, 4, 5]
     });
"})

This is the solution for plugins.length

The author mentioned solution in the post. I confirmed it works perfectly.

Related