Can a website detect when you are using selenium with chromedriver?

后端 未结 19 2676
情歌与酒
情歌与酒 2020-11-21 05:41

I\'ve been testing out Selenium with Chromedriver and I noticed that some pages can detect that you\'re using Selenium even though there\'s no automation at all. Even when I

19条回答
  •  被撕碎了的回忆
    2020-11-21 06:12

    Additionally to the great answer of @Erti-Chris Eelmaa - there's annoying window.navigator.webdriver and it is read-only. Event if you change the value of it to false it will still have true. Thats why the browser driven by automated software can still be detected. MDN

    The variable is managed by the flag --enable-automation in chrome. The chromedriver launches chrome with that flag and chrome sets the window.navigator.webdriver to true. You can find it here. You need to add to "exclude switches" the flag. For instance (golang):

    package main
    
    import (
        "github.com/tebeka/selenium"
        "github.com/tebeka/selenium/chrome"
    )
    
    func main() {
    
    caps := selenium.Capabilities{
        "browserName": "chrome",
    }
    
    chromeCaps := chrome.Capabilities{
        Path:            "/path/to/chrome-binary",
        ExcludeSwitches: []string{"enable-automation"},
    }
    caps.AddChrome(chromeCaps)
    
    wd, err := selenium.NewRemote(caps, fmt.Sprintf("http://localhost:%d/wd/hub", 4444))
    }
    

提交回复
热议问题