Running browsers headless

April 26th, 2017

A headless computer is a computer running without a monitor or a display server, much like an internet server.

Running browsers headless means extra options to automate testing of websites and web apps. Chromium (on which Google Chrome is based) on Linux is able to run headless since version 57, but Ubuntu now already offers version 58.

How to run Chromium headless

chromium-browser --headless https://dev.webonomic.nl

At the moment `–headless` mode uses a different user-agent then normal mode.

user-agent headless mode chromium

"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/58.0.3029.81 HeadlessChrome/58.0.3029.81 Safari/537.36"

user-agent normal mode chromium

"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/58.0.3029.81 Chrome/58.0.3029.81 Safari/537.36"

Run Chromium with different user-agent

chromium-browser --user-agent "Mozilla/5.0 (Windows NT 6.1; rv:45.0) Gecko/20100101 Firefox/45.0" --headless https://dev.webonomic.nl

This should work but it doesn’t (anymore). This cli switch must have been removed. Poorly documented.

Apparently Google doesn’t want to give you the opportunity to imitate a normal chrome with a headless chrome.

What about Firefox

As it seems, headless isn’t yet supported for Firefox, but developers are working on it.

Leave a Reply