chrome 59 introduces headless chrome (git), which allows you to run chrome with all modern web platform features provided by chromium and blink but without a user interface; this is very helpful for automated testing and web scraping;

command line examples

these examples are actually tested with chromium, but should also work with chrome;

to start headless chrome, run chrome with --headless option (also add option --disable-gpu if buggy):

chrome --headless --disable-gpu

to print the dom:

chrome --headless --disable-gpu --dump-dom

to create a pdf:

chrome --headless --disable-gpu --print-to-pdf

to take a screenshot:

chrome --headless --disable-gpu --screenshot --window-size=1920,1080

headless chrome is very helpful for web scraping because page content may be dynamically loaded via javascript; traditional downloaders (eg: wget) will only download static page content, which is usually not what users finally see after page is rendered; on the contrary, headless chrome can download dynamic page content using its --dump-dom option; if dynamic content takes some time to load, we can make headless chrome wait for some time before considering page is ready, by using the --virtual-time-budget={ms} option (doc):

chrome --headless --disable-gpu --virtual-time-budget=500000 --dump-dom

use with selenium

these examples are tested with selenium python binding (doc), which can be installed using pip:

pip install selenium

selenium requires a driver to work with a chosen browser; for chrome, this is chromedriver; on fedora 28, we can install it using package manager dnf:

dnf install chromedriver

now run our python code to download a screenshot of rendered page:

#!/usr/bin/env python3

from selenium.webdriver import Chrome
from import Options
from selenium.webdriver.common.keys import Keys

options = Options()
browser = Chrome(options=options)
elem = browser.find_element_by_css_selector('input[type=text]')
elem.send_keys('google' + Keys.RETURN)

a list of available options can be found here;