Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if Chrome browser is headless in selenium?

I'm writing a selenium test which has different behavior given whether the chrome browser was started as headless or not. My question is in my test how do I detect if the browser is headless for my conditional flow?

like image 927
DubiousDan Avatar asked Jul 13 '18 14:07

DubiousDan


People also ask

Can headless Chrome be detected?

Nonetheless, instrumenting Headless Chrome with a framework such as Puppeteer will still leave traces that make it possible to detect it as a non-human user.

Can headless browser be detected?

There are many ways to detect whether a request is coming from a headless browser, but whether it will be easy to do so depends greatly on how the headless browser is configured. If used for web scraping, hackers do their absolute best to obscure detection.

Does Selenium use headless Chrome?

Headless testing is simply running your Selenium tests using a headless browser. It operates as your typical browser would, but without a user interface, making it excellent for automated testing.

Which Chrome version is headless?

Note: Headless mode has been available on Mac and Linux since Chrome 59.


1 Answers

https://antoinevastel.com/bot%20detection/2018/01/17/detect-chrome-headless-v2.html#:~:text=In%20order%20to%20automate%20Chrome,possible%20to%20detect%20Chrome%20headless.

driver.execute_script("return navigator.plugins.length == 0")
like image 200
user123456789 Avatar answered Nov 01 '22 10:11

user123456789