Is it possible to run Google Chrome in headless mode with extensions?

EDIT: This answer is no longer correct, see https://stackoverflow.com/a/73079789/934239

No, it's not possible, and Chrome developers decided against implementing it in any near future due to complexity of the task.

If you look at that issue you may get the idea that they are still considering it due to ChromeDriver requirements - but instead they decided to make ChromeDriver work without extensions (through DevTools).


You can use pyvirtualdisplay to run the chrome with zero display on your server. The best thing is you can run extensions by using this trick.

Here is my implementation:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
from pyvirtualdisplay import Display

display = Display(visible=0, size=(800, 600))
display.start()

chrome_options = Options()

chrome_options.add_extension("proxy.zip")

driver = webdriver.Chrome(
    executable_path='/usr/bin/chromedriver', 
    chrome_options=chrome_options
)
time.sleep(3)
driver.get("https://ipinfo.io/json")
print(driver.page_source)
driver.close()

display.stop()

You need to install xvfb on your server/machine:

sudo apt install -y xvfb
pip install pyvirtualdisplay

Running it on my AWS Server

aws server


You can run Chrome with extensions headless using Xvfb.

  1. Install Xvfb. On Fedora sudo dnf install xorg-x11-server-Xvfb
  2. xvfb-run google-chrome --remote-debugging-port=9222 --disable-gpu https://www.google.com
  3. Use chrome-remote-interface (or another Chrome Debug Protocol client) to trigger the screenshot.

More complicated, but it does work. It's what we use for headless chrome extension testing.