Access with Selenium as a countermeasure for navigator.webdriver

enable-automation or use Automation Extension did not work as expected

I want to scrape for some reason, but it was an NG site if it was a navigator.webdriver = true browser. I want to correspond. Because it seems that it can be done. Reference: If navigator.webdriver = true, it will be a robot. Is there a workaround? puppeteer seems to be able to do it But I'm using Selenium, I've never used puppeteer, and I can't do anything about it. ..

Settings when it does not work

I found some articles that seem to be possible with Selenium.

Reference 1: https://stackoverflow.com/questions/53039551/selenium-webdriver-modifying-navigator-webdriver-flag-to-prevent-selenium-detec

Reference 2: https://help.applitools.com/hc/en-us/articles/360007189411--Chrome-is-being-controlled-by-automated-test-software-notification

I tried it.

    capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
      accept_insecure_certs: true,
      chromeOptions: {
        args: [
          '-window-size=1920,1080',
          '--user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36'
        ],
        excludeSwitches: ['enable-automation'], #add to
        useAutomationExtension: false #add to
      }
    )
    driver = Selenium::WebDriver.for(
      :remote,
      url: 'http://chrome:4444/wd/hub',
      desired_capabilities: capabilities,
      http_client: Selenium::WebDriver::Remote::Http::Default.new
    )

Even if I actually move it, true is returned. It was no good.

driver.execute_script('return navigator.webdriver')
>>> true

Worked settings

Removed ʻenable-automation and ʻuse Automation Extension. Set the driver as before.

    capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
      accept_insecure_certs: true,
      chromeOptions: {
        args: [
          '-window-size=1920,1080',
          '--user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36'
        ],
      }
    )
    driver = Selenium::WebDriver.for(
      :remote,
      url: 'http://chrome:4444/wd/hub',
      desired_capabilities: capabilities,
      http_client: Selenium::WebDriver::Remote::Http::Default.new
    )

    #Add the following
    driver.execute_script('const newProto = navigator.__proto__;delete newProto.webdriver;navigator.__proto__ = newProto;')

When you actually move it, undefined is returned. Works similar to puppeteer. Was good.

driver.execute_script('return navigator.webdriver')
>>> undefined

Recommended Posts

Access with Selenium as a countermeasure for navigator.webdriver
Rubocop-daemon as a countermeasure for the problem that RuboCop starts slowly
Use FacesContext as a Mock with PowerMockito
Creating a browser automation tool with Ruby + Selenium
A note for those who live with JMockit
Play down with Raspberry PI4 as a server. Part 2
Create a widget template for iOS14 with Intent Configuration.
[Java basics] Let's make a triangle with a for statement