Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 772
pau.moreno Avatar asked Jul 28 '17 11:07

pau.moreno


People also ask

Can chrome extensions be used offline?

Chromebook user or not, as long as you're a Chrome user, you can install offline extensions (and apps) for common tasks like note taking and editing PDFs.

How do I run a Chrome headless driver?

How to run Chrome in headless mode. In order to run your tests in headless mode, you will need to use the ChromeOptions as follows. ChromeOptions options = new ChromeOptions(); options. addArguments("--headless");

Does headless Chrome run faster?

Headless Browsers are Faster than Real Browsers But you will typically see a 2x to 15x faster performance when using a headless browser. So if performance is critical for you, headless browsers may be a way to go.

Does Chromium support headless?

Headless Chromium allows running Chromium in a headless/server environment. Expected use cases include loading web pages, extracting metadata (e.g., the DOM) and generating bitmaps from page contents -- using all the modern web platform features provided by Chromium and Blink.


2 Answers

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.

like image 80
Graham King Avatar answered Oct 14 '22 04:10

Graham King


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).

like image 39
Xan Avatar answered Oct 14 '22 04:10

Xan