Chrome "unknown error: Chrome failed to start: crashed" in CI
Chrome launched under WebDriver but the process crashed before it was ready. In CI the fix is almost always startup flags: --no-sandbox for root containers, --headless=new since there is no display, and --disable-dev-shm-usage for a small /dev/shm.
What this error means
Selenium fails with "unknown error: Chrome failed to start: crashed. (chrome not reachable)" or "DevToolsActivePort file doesn't exist" when launching Chrome in a container.
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start:
crashed.
(chrome not reachable)
(The process started from chrome location /usr/bin/google-chrome is no longer running,
so ChromeDriver is assuming that Chrome has crashed.)Common causes
The sandbox cannot run as root
The container runs as root, so Chrome's sandbox fails and the process dies without --no-sandbox.
No display or too little shared memory
Without headless mode there is no display to attach to, and a tiny /dev/shm makes Chrome crash unless --disable-dev-shm-usage is set.
How to fix it
Add the standard CI Chrome flags
Pass the flags that make Chrome run headless in a root container with limited shared memory.
from selenium.webdriver.chrome.options import Options
opts = Options()
opts.add_argument('--headless=new')
opts.add_argument('--no-sandbox')
opts.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome(options=opts)Install the browser libraries too
A crash can also come from missing OS libraries; install them so the process stays up.
sudo apt-get update
sudo apt-get install -y libnss3 libgbm1 libasound2How to prevent it
- Always run headless in CI with
--headless=new. - Pass
--no-sandboxfor root containers and--disable-dev-shm-usagefor small /dev/shm. - Install Chrome's OS libraries so the process does not crash at startup.