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 https://www.google.com/

to create a pdf:

chrome --headless --disable-gpu --print-to-pdf https://www.google.com/

to take a screenshot:

chrome --headless --disable-gpu --screenshot --window-size=1920,1080 https://www.google.com/

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 https://www.google.com/

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 selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys

options = Options()
options.add_argument('--headless')
options.add_argument('--disable-gpu')
options.add_argument('--window-position=0,0')
options.add_argument('--window-size=1280,720')
browser = Chrome(options=options)
browser.implicitly_wait(30)
browser.get('https://www.google.com/')
elem = browser.find_element_by_css_selector('input[type=text]')
elem.send_keys('google' + Keys.RETURN)
browser.get_screenshot_as_file('google.png')
browser.close()

a list of available options can be found here;

references