How to connect to Chromium Headless using Selenium

I think the readme is a little bit misleading. You don't have to start Chromium itself and you can use the RemoteWebDriver. Make sure that a chromedriver is installed (https://sites.google.com/a/chromium.org/chromedriver/home).

  • Start chromedriver (e.g. ./chromedriver or ./chromedriver --port=9515)
  • Then you have tell the chromedriver to use Chromium instead of Chrome
  • Add --headless as an additional argument

Code should look like this:

final ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setBinary("/usr/bin/chromium-browser");
chromeOptions.addArguments("--headless");
desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
WebDriver driver = new RemoteWebDriver(url, desiredCapabilities);

Worked for me on Ubuntu Linux.


Alternatively if your running it locally you can just do it like this. In scala.

val chromeOptions = new ChromeOptions
chromeOptions.addArguments("--headless")
new ChromeDriver(chromeOptions)