Undetected Chromedriver is not bypassing in headless mode

Viewed 538

I've tried to run my python selenium bot in --headless mode. Unfortunately with --headless mode it is not bypassing Cloudflare bot protection. Any ideas what would work there?

options = uc.ChromeOptions()
options.headless=True
options.add_argument("--window-size=1920,1080")
options.add_argument('--ignore-certificate-errors')
options.add_argument('--allow-running-insecure-content')
options.add_argument('--headless')

scrap = uc.Chrome(use_subprocess=True,options=options)

screen of Cloudflare bot protection

1 Answers

Use a virtual display such as Xvfb so that you don't need to use headless mode on a headless machine such as Linux servers.

There's a Selenium Python framework, https://github.com/seleniumbase/SeleniumBase, with built-in integration to undetected-chromedriver for that exact thing. When running your tests, add --uc as a pytest command-line option for your SeleniumBase tests. Eg:

pytest --uc --xvfb

That lets you successfully run Selenium Python tests on a Linux headless machine in undetected-chromedriver mode. (With SeleniumBase)

Related