Any way to start Google Chrome in headless mode?

I carefully revised the list of switches at http://peter.sh/experiments/chromium-command-line-switches/#chrome-frame and I couldn't find anything that would launch Chrome in a hidden background process.

The closest I was able to is --keep-alive-for-test + custom packaged app, but the app fails to execute any passed code because (the way it reports) "no window - ChromeHidden".


TL;DR

google-chrome --headless --remote-debugging-port=9222 http://example.com

You'd also need --disable-gpu temporarily.


Tutorial:

https://developers.google.com/web/updates/2017/04/headless-chrome


There's a work in progress: https://code.google.com/p/chromium/issues/detail?id=546953

The main deliverables are:

  1. A library which headless applications can link to to.
  2. A sample application which demonstrates the use of headless APIs.

So it would be possible to create a simple application that runs in console without connecting to display.

Update Apr 18 '16: The work is mainly done. There's a public forum now:

https://groups.google.com/a/chromium.org/forum/#!forum/headless-dev

Documentation is being in progress:

https://chromium.googlesource.com/chromium/src/+/master/headless/README.md

Update Sep 20 '16: It looks like chrome will eventually get the "--headless" parameter: https://bugs.chromium.org/p/chromium/issues/detail?id=612904

There was a presentation on BlinkOn 6 (June 16/17, 2016)

Update Nov 29 '16: Design doc for --headless flag: https://docs.google.com/document/d/1aIJUzQr3eougZQp90bp4mqGr5gY6hdUice8UPa-Ys90/edit#heading=h.qxqfzv2lj12s

Update Dec 13 '16: --headless flag is expected to be available in Canary builds soon

Update Mar 12 '17: Chrome 57 has a --headless flag working. Waiting for Selenium and other tools to catch up. User guide: https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md


This guy managed to run Chrome headlessly by using Xvfb (X virtual frame buffer) to trick Chrome into thinking it was displaying a window:

http://e-method.blogspot.fr/2010/11/google-chrome-with-xvfb-headless-server.html

If you're on Linux you could try that.

So basically you need to install X virtual frame buffer and Google Chrome via:

root@localhost: ~# apt-get install xvfb imagemagick
root@localhost: ~# apt-get install google-chrome

Then run the browser on the display:

root@localhost: ~# xvfb-run --server-args='-screen 0, 1024x768x24' \
google-chrome -start-maximized http://www.example.com \
> & /dev/null &
root@localhost: ~# DISPLAY=:99 import -window root myimage.png