User Agents

Web browsers and everyday web tech, explained

Fix Chrome Not Reachable in Headless Chrome

· 4 min read · Browsers

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Fixing the "Chrome not reachable" error in headless Chrome ensures automated browser tasks run reliably without crashing or timing out. This error typically occurs during automated testing or scraping when Chrome fails to start or respond despite being launched. The root cause often lies in incorrect launch arguments, resource limits, or environment constraints. Resolving it requires adjusting Chrome's startup configuration and ensuring the host system supports headless operation. This guide walks through reliable fixes, common misconfigurations, and troubleshooting steps to restore stable headless Chrome execution.

What You'll Need

  • A system running Chrome or Chromium (version 59 or later)
  • Command-line access or script environment (Node.js, Python, etc.)
  • Basic understanding of Chrome launch arguments
  • Admin or sudo privileges (if modifying system-level settings)
  • Network access to download ChromeDriver if needed

Step-by-Step

  1. Verify Chrome or Chromium is installed and accessible. Run google-chrome --version or chromium --version in the terminal. If not found, install it using your package manager (e.g., apt install chromium-browser on Debian/Ubuntu).
  2. Use the correct executable path in your script. If Chrome isn't in the default path, specify the full path like /usr/bin/chromium-browser or C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe.
  3. Add essential headless launch arguments. Always include --headless=new (modern headless mode) or --headless=chrome for older versions. Also include --disable-gpu to prevent GPU-related hangs.
  4. Set a display size using --window-size=1920,1080. Headless Chrome may fail silently without a defined viewport.
  5. Disable sandboxing in restricted environments using --no-sandbox. This is often needed in Docker or CI environments but should be used cautiously.
  6. Add --disable-dev-shm-usage to avoid crashes due to limited shared memory, especially in Docker containers where /dev/shm is small.
  7. Set --remote-debugging-port=9222 to a free port. Ensure no other service is using this port. If needed, change it to another available port like 9223.
  8. Include --disable-background-timer-throttling and --disable-backgrounding-occluded-windows to prevent Chrome from throttling or pausing in background.
  9. Use --disable-sync and --disable-extensions to reduce startup complexity and avoid extension-related hangs.
  10. Launch Chrome with a user data directory using --user-data-dir=/tmp/chrome-profile. This prevents conflicts with existing profiles and permissions issues.
  11. Wait for Chrome to fully initialize before connecting. Add a 2–5 second delay or poll the debugging port using curl http://localhost:9222/json until it returns a response.
  12. If using Puppeteer or Selenium, ensure version compatibility. Match Puppeteer version to Chrome version. Use puppeteer.launch() with executablePath and args properly configured.
  13. Clean up after tests. Kill Chrome processes using pkill -f chrome or taskkill on Windows to prevent port conflicts on restart.

Common Mistakes

One frequent error is omitting --disable-gpu, which can cause hangs even in headless mode. Another is forgetting --no-sandbox in Docker or CI environments, where sandboxing is unsupported. Relying on /dev/shm without --disable-dev-shm-usage leads to memory issues in containers. Using --headless without =new or =chrome may trigger deprecated behavior. Hardcoding ports without checking availability causes connection failures. Skipping the user data directory results in permission errors on shared systems. Finally, attempting to connect too quickly before Chrome is ready triggers "not reachable" errors.

Tips

Run Chrome with --dump-render-tree only for debugging, not production. Always log Chrome's stdout and stderr to catch startup errors. Use absolute paths for executables and data directories to avoid path resolution issues. In Docker, mount /tmp as a volume to avoid disk space problems. For CI pipelines, reuse Chrome instances only if properly managed. Set timeouts higher (30+ seconds) when launching in slow environments. Use --single-process sparingly—it helps debugging but reduces stability. Prefer --headless=new unless compatibility is required.

Troubleshooting

If Chrome still isn't reachable, first check if the process started using ps aux | grep chrome. If not, review launch arguments for typos. If it started but isn't responding, verify the debugging port is open with netstat -tuln | grep 9222. If port 9222 is in use, change it in your script. If Chrome crashes immediately, enable logging with --log-level=0 --enable-logging and inspect the output. In Docker, ensure the container has enough memory (at least 512MB) and CPU. If using Selenium, confirm ChromeDriver version matches Chrome. If Chrome hangs, try removing --disable-gpu temporarily—rarely, this helps on GPU-enabled VMs. If all else fails, run Chrome in non-headless mode briefly to confirm installation integrity.

Frequently Asked Questions

Why does Chrome not reachable happen only in Docker?

Docker containers often have limited shared memory and no sandbox support. Use --no-sandbox and --disable-dev-shm-usage to resolve this.

Is --no-sandbox safe to use?

It reduces security and should only be used in trusted environments like CI or isolated containers, not on public-facing servers.

Does --headless=new work on older Chrome versions?

No. Use --headless=new only on Chrome 112+. For older versions, use --headless=chrome or --headless.

How do I check if Chrome is running headless?

Open chrome://version in the browser or check process arguments via ps. The command line should show --headless.

Can I run multiple headless Chrome instances?

Yes, but each needs a unique user data directory and debugging port to avoid conflicts.

Why does it work locally but fail on CI?

CI environments often lack display, GPU, or sufficient resources. Replicate CI conditions locally using Docker to debug.