Search code examples
pythongoogle-chromeselenium-webdriverselenium-chromedriverchromium

Selenium Headless Chrome empty page source (not UA issue)


so I am trying to open some pages with selenium Chrome, and everything works fine while headless mode isn't used. But when I use headless mode, the page source returns

<html><head></head><body></body></html>

Searched for something that'd help, but to no avail. I tried adding User Agent as most of the forums suggest, but it didn't help. Neither did using a bunch of other options (such as --allow-insecure-localhost)

Tried looking for answers in similar questions, but none helped. Also tried a bunch of chrome options.


Solution

  • I actually found the answer, thanks to dhruv's answer here: https://stackoverflow.com/a/77081435/14829049

    The answer is to use --headless=new instead of --headless

    So technically, the --headless is actually a separate chrome implementation, not a mode of operation; While the new --headless=new uses the same chrome as in the headfull mode. In case anyone would like to read a bit more about it: https://developer.chrome.com/articles/new-headless/