21

In python-selenium chrome_options, What exactly is the difference between the following two options, I know both runs the selenium script without opening the browser.

chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
Mahesh Kumaran
  • 887
  • 2
  • 12
  • 30
  • see https://stackoverflow.com/questions/53657215/running-selenium-with-headless-chrome-webdriver – Ammar Nov 26 '19 at 09:21
  • 1
    Personally, I have to use both in conjunction with each other for headless to work reliably. – CEH Nov 26 '19 at 14:37

2 Answers2

14

You saw it right. Adding the argument --headless initiates the Chrome Browsing Context in headless mode.

However the purpose of the argument --disable-gpu was to enable on platform. It was needed as SwiftShader fails an assert on Windows in headless mode earlier.

This issue was resolved through Headless: make --disable-gpu flag unnecessary

You can find a relevant detailed discussion in ERROR:gpu_process_transport_factory.cc(1007)-Lost UI shared context : while initializing Chrome browser through ChromeDriver in Headless mode

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
7

--disable-gpu doesn't run the script without opening the browser, only --headless. It used to be needed on Windows Issue 737678: Headless: make --disable-gpu flag unnecessary, but this bug was fixed. chrome_options.add_argument('--headless') is all you need.

Guy
  • 46,488
  • 10
  • 44
  • 88