Run Chrome without chrome, it brings all modern web platform features provided by Chromium and the Blink rendering engine to the command line.

A headless browser is a great tool for automated testing and server environments where you don’t need a visible UI shell.

Starting Headless (CLI)

The easiest way to get started with headless mode is to open the Chrome binary from the command line. If you’ve got Chrome 59+ installed, start Chrome with the -- headless flag:

1
2
3
4
5
chrome \
--headless \ # Runs Chrome in headless mode
--disable-gpu \ # Temporarily needed for now
--remote-debugging-port=9222 \
https://www.chromestatus.com # URL to open. Defaults to about:blank

chrome should point to your installation of Chrome.

Command line features

In some cases, you may not need to programmatically script Headless Chrome. There are some useful command line flags to perform common tasks.

Printing the DOM

The --dump-dom flag prints document.body.innerHTML to stdout:

1
chrome --headless --disable-gpu --dump-dom https://www.chromestatus.com/

Create a PDF

The --print-to-pdf flag creates a PDF of the page

1
chrome --headless --disable-gpu --print-to-pdf https://chromestatus.com/

Taking screenshots

To capture a screenshot of a page, use the --screenshot flag:

1
2
3
4
chrome --headless --disable-gpu --screenshot https://chromestatus.com/

# Size of a standard letterhead.
chrome --headless -disable-gpu --screenshot --window-size=1280,1696 https://chromestatus.com/

REPL mode

The --repl flag runs Headless in a mode where you can evaluate JS expression in the browser, right from the command line:

1
2
3
4
5
chrome --headless --disable-gpu --repl https://chromestatus.com/

>>> location.href
{"result":{"type":"string","value":"https://www.chromestatus.com/features"}}
>>> quit