Chrome WebDriver crashes in headless mode on Ubuntu CLI with DevToolsActivePort error

I’m running automated tests on an Ubuntu server through command line interface and keep getting this frustrating error when trying to use Chrome in headless mode.

The error message I see is:

FAILURE: org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally (unknown error: DevToolsActivePort file doesn't exist) (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

I have both Chrome browser and ChromeDriver properly installed in /usr/bin/ directory. Here’s my current setup code:

System.setProperty("webdriver.chrome.driver", "/usr/bin/chromedriver");
ChromeOptions options = new ChromeOptions();
options.setBinary(System.getProperty("user.dir") + "/usr/bin/chromedriver");
options.addArguments("--no-sandbox");
options.addArguments("--disable-dev-shm-usage");
options.addArguments("--headless");
WebDriver browser = new ChromeDriver(options);
browser.navigate().to("file://" + htmlFilePath);

What could be causing Chrome to crash during startup in headless mode?

hey emmad, your setBinary line’s pointing to chromedriver instead of chrome itself. change options.setBinary(System.getProperty("user.dir") + "/usr/bin/chromedriver"); to options.setBinary("/usr/bin/google-chrome"); - it needs the chrome executable, not the driver

Been down this rabbit hole way too many times. The DevToolsActivePort error means Chrome can’t write to its default data directory.

Add --user-data-dir=/tmp/chrome-data to your ChromeOptions. Also fix that setBinary line - it should point to /usr/bin/google-chrome, not chromedriver.

Honestly though, debugging Selenium setup is a massive time sink. I switched to Latenode for browser automation and never looked back. It handles all the Chrome config automatically in the cloud, so no more headless crashes or server environment headaches.

You can set up the same scraping or testing workflow without touching ChromeDriver configs. Way cleaner than managing browser instances yourself.

Chrome needs extra arguments when running on servers without displays. Fix your setBinary path first, then add --disable-gpu and --remote-debugging-port=9222 to ChromeOptions. I had the same crashes on headless Ubuntu until I added --disable-extensions and --disable-background-timer-throttling. Check your Chrome permissions too - the browser can’t create temp files if access is restricted. Run google-chrome --version in terminal to make sure it works before trying WebDriver.