Using Google Chrome Headless

Published on September 5, 2017

webdriver, cucumberjs, chrome

Firstly, in order to use this headless browser in your webdriver tests, you will need to install specific version of Chrome 59 (Canary), as headless feature is not yet part of main Chrome build.

Google Chrome Canary Download

On Mac

brew install Caskroom/versions/google-chrome-canary

Locate the binary

sudo find / -type d -name "*Chrome Canary.app"

Tweak the webdriver config file

capabilities: {
    browserName: 'chrome',
    # specify location of Chrome Canary app
    chromeOptions: {
        binary: '/Applications/Google Chrome Canary.app',
        args: ['headless', 'no-sandbox', 'disable-gpu'],
    },
};

On Linux/Windows(shell)

wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - "
echo 'deb http://dl.google.com/linux/chrome/deb/ stable main' >> /etc/apt/sources.list.d/google.list
apt-get update
apt-get install -y google-chrome-stable

Locate the binary

which google-chrome

Tweak the webdriver config file

capabilities: {
    browserName: 'chrome',
    # specify location of Chrome Canary app
    chromeOptions: {
        binary: '/usr/bin/google-chrome-stable',
        args: ['headless', 'no-sandbox', 'disable-gpu'],
    },
};