The session not created: DevToolsActivePort file does not exist error occurs when ChromeDriver launches the Chrome binary, but Chrome fails to start, crashes immediately, or cannot write its temporary debugging port file (DevToolsActivePort) to disk. This is primarily caused by missing sandbox permissions in containerized environments, insufficient shared memory allocating /dev/shm, or port collisions during headless execution on Linux systems.
Quick Fix
Add --headless=new, --no-sandbox, and --disable-dev-shm-usage to your ChromeOptions configuration:
options.add_argument("--headless=new")
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")
Step-by-Step Resolution
- Locate your ChromeDriver initialization code in your test suite or automation script.
- **Instantiate
ChromeOptions**and inject the required arguments to resolve memory allocation and process isolation conflicts. - Set the binary location explicitly if multiple Chrome/Chromium versions exist on the system (e.g., in
/usr/bin/google-chromeor/usr/bin/chromium-browser).
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
options = Options()
# Core fix flags for headless/containerized execution
options.add_argument("--headless=new")
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")
# Optional stability flags for headless environments
options.add_argument("--disable-gpu")
options.add_argument("--remote-debugging-port=9222")
# Explicit binary path (uncomment if using custom installation)
# options.binary_location = "/usr/bin/google-chrome"
service = Service() # Automatically managed by Selenium 4 Manager or pass executable_path
driver = webdriver.Chrome(service=service, options=options)
driver.get("https://example.com")
print(driver.title)
driver.quit()
Why This Fails for Some Users
- Docker
/dev/shmSize Limits: Docker defaults to a 64MB shared memory partition (/dev/shm), which causes Chrome to crash on resource-heavy web pages unless--disable-dev-shm-usageforces Chrome to write temporary files to/tmpinstead, or the container is started with--shm-size=2gb. - Root Execution Constraints: Running Chrome as the
rootuser (common in CI/CD containers like Jenkins or GitHub Actions) causes Chrome’s process sandbox to fail on startup unless--no-sandboxis specified. - Chrome and ChromeDriver Version Mismatch: Major version disparities between the installed Chrome browser and the ChromeDriver executable will prevent DevTools socket initialization.
- Zombie Chrome Processes: Residual background Chrome or ChromeDriver processes hanging on port
9222can block the creation of new debugging ports, requiring a process purge (pkill -f chrome).