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

pau.moreno picture pau.moreno · Jul 28, 2017 · Viewed 29.5k times · Source

I cannot use my currently installed extensions in Google Chrome using headless mode. Is there any way to enable them?

An easy way to check if the extensions work is by adding, for example, the "Comic Sans Everything" extension.

So Google looks like that:

Google looks beautiful

However, if I take a screenshot of the page using the headless mode (google-chrome --headless --disable-gpu --screenshot https://www.google.com), the result is:

Google in headless mode

Answer

Graham King picture Graham King · Sep 28, 2017

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.