How to Fix Selenium Screenshot Failing with DevToolsActivePort Error
“DevToolsActivePort file doesn't exist” is a Chrome startup symptom, not a diagnosis. Check driver compatibility, startup logs, headless mode, browser paths, and profiles.
The message DevToolsActivePort file doesn't exist means ChromeDriver could not connect to Chrome through the expected DevTools startup port. It is a symptom, not a diagnosis: Chrome may have exited, the wrong browser or driver may have been selected, or the runtime may not support the launch configuration. Start by checking Chrome and ChromeDriver versions and reading the startup logs; change flags only when the evidence points to an environment constraint.
The steps below use Python. They separate browser startup from screenshot capture so you can identify which operation is failing.
1. Check versions and executable paths
Record the Selenium package version, Chrome version, and ChromeDriver version before changing options. Chrome and ChromeDriver should have compatible major versions. Selenium documents that Selenium Manager has shipped with Selenium since version 4.6 and can resolve drivers when one is not already provided. If a manually installed driver is on PATH, Selenium may use it instead of resolving another one.
python --version
python -m pip show selenium
chromedriver --version
# Linux examples; use the equivalent command for your OS:
google-chrome --version
which google-chrome
which chromedriver
On Windows, check the actual Chrome and ChromeDriver executable paths and run each with --version. On macOS, Chrome is commonly inside /Applications/Google Chrome.app; the installed location can differ. If the version commands report different ChromeDriver and Chrome major versions, update the driver or let a current Selenium Manager resolve it. See Selenium’s Chrome documentation and Selenium Manager documentation.
2. Try a minimal headless session and screenshot
On a machine without a graphical display, use headless Chrome. Keep the first attempt small: do not add a copied list of flags before you know whether the browser starts. This runnable script opens a page, saves a screenshot, and always attempts to close the session.
# install with: python -m pip install -U selenium
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("--headless")
# Selenium Manager can resolve ChromeDriver when it is not supplied separately.
driver = webdriver.Chrome(options=options)
try:
driver.set_window_size(1440, 1000)
driver.get("https://example.com")
driver.save_screenshot("example.png")
finally:
driver.quit()
Chrome’s current headless mode shares the main Chrome implementation with headful mode. Since Chrome 132.0.6793.0, the older headless implementation is distributed separately as chrome-headless-shell. If a script or container specifically expects the old implementation, verify which Chrome binary it launches and which version the recipe targets; see Chrome Headless mode.
If Chrome starts in headful mode on your workstation but not on a server, the machine’s display setup is a relevant difference. If headless mode also exits, continue to the logs and paths rather than assuming headless itself is the fix.
3. Read ChromeDriver and Selenium startup logs
Look for the first meaningful error immediately before Chrome exits. Useful clues include the browser binary ChromeDriver selected, profile directory, driver version, permission errors, missing shared libraries, and whether Chrome starts at all. The DevToolsActivePort line often appears after the more specific cause.
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
options = Options()
options.add_argument("--headless")
service = Service(log_output="chromedriver.log")
driver = webdriver.Chrome(service=service, options=options)
try:
driver.get("https://example.com")
driver.save_screenshot("example.png")
finally:
driver.quit()
For Selenium’s own Python logs, add a handler as well:
import logging
logger = logging.getLogger("selenium")
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler()
handler.setLevel(logging.DEBUG)
logger.addHandler(handler)
Run the failing case again and compare timestamps and paths in both logs. The Selenium logging guide describes collecting execution details, and the Chrome-specific Selenium guide shows ChromeDriver service logging options.
4. Verify the Chrome binary and profile
ChromeDriver normally creates a temporary profile for a session. If you configured a custom user-data-dir, check that the path exists or is writable and that no other Chrome process is using that profile. Concurrent sessions must not share the same active profile directory. For diagnosis, remove the custom profile argument and let ChromeDriver create a temporary one.
If Chrome is installed in a non-standard location, explicitly point Selenium at that executable and confirm the file is the intended Chrome build:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("--headless")
options.binary_location = "/path/to/chrome"
driver = webdriver.Chrome(options=options)
try:
driver.get("https://example.com")
driver.save_screenshot("example.png")
finally:
driver.quit()
Replace /path/to/chrome with the actual executable path for your OS. ChromeDriver capabilities document temporary and custom profiles as well as selecting a non-standard browser binary: ChromeDriver capabilities and ChromeOptions.
5. Add launch flags only to test a specific constraint
ChromeOptions passes command-line arguments to Chrome, but a flag is not a general-purpose fix for this message. In particular, do not add --no-sandbox, --disable-dev-shm-usage, a fixed --remote-debugging-port, or a large copied flag bundle by default. First identify a likely constraint from the logs or runtime configuration, then test one change at a time and keep the before-and-after logs.
- If a container has a constrained shared-memory mount, investigate its configuration and Chrome’s error output before testing a shared-memory-related adjustment.
- If the process runs under a restricted account or container, investigate its permissions and sandbox requirements. Disabling sandbox protections changes the security posture and should not be treated as a routine workaround.
- Avoid a fixed remote debugging port for parallel sessions unless the environment requires it and you manage port allocation. A port collision can create a separate startup problem.
The supported way to supply Chrome arguments is through ChromeOptions; the official capability reference explains argument configuration. It does not establish the flags above as universal remedies.
6. Check managed-browser policy when the evidence points there
If the same script works with an unmanaged Chrome installation but fails with a centrally managed browser, ask the administrator whether policy restricts remote debugging or WebDriver automation. Treat policy as a targeted lead when the environment points to it, not as the default explanation for every DevToolsActivePort failure. A community report can illustrate that such restrictions occur, but it cannot establish the cause in a different environment.
7. Separate session startup from screenshot capture
Once webdriver.Chrome(...) returns successfully, the browser session has started. Then test navigation and screenshot saving independently:
driver.get("https://example.com")
print("title:", driver.title)
print("current URL:", driver.current_url)
print("screenshot saved:", driver.save_screenshot("example.png"))
If session creation fails, investigate browser startup, driver compatibility, paths, profiles, runtime resources, and policy. If session creation succeeds but navigation or saving fails, investigate that later operation separately. A screenshot call cannot fix a Chrome process that never started.
Or skip the browser setup
If your task is to capture a page rather than operate a local Selenium browser, ScreenshotNeo provides a screenshot API and MCP server. Its one-request API returns an image or PDF. The request below saves a WebP response; create an API key before replacing the placeholder. See the ScreenshotNeo API documentation.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp
import requests
r = requests.get(
"https://api.screenshotneo.com/v1/shot",
params={"access_key": "YOUR_API_KEY", "url": "https://example.com"},
timeout=90,
)
r.raise_for_status()
with open("shot.webp", "wb") as f:
f.write(r.content)
const q = new URLSearchParams({
access_key: 'YOUR_API_KEY',
url: 'https://example.com'
});
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`Screenshot request failed: ${res.status}`);
await Bun.write('shot.webp', res); // Or write the response bytes with your Node.js runtime.
ScreenshotNeo accepts cookie banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before the capture; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers report the page verdict and billing status. Its MCP server offers take_screenshot, get_page_info, and capture_pdf for AI agents. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots. Sign up for 1,000 free screenshots a month, with no card.
Troubleshooting checklist
| Symptom | Likely area to inspect | Next action |
|---|---|---|
| Chrome and ChromeDriver major versions differ | Driver resolution or stale driver on PATH | Update Selenium, remove the unintended driver from PATH, or provide a compatible driver. |
| Chrome starts locally but fails on a server | Display availability, runtime libraries, permissions, or container setup | Use headless mode where appropriate and inspect logs for the first startup error. |
| Failure began after adding a custom profile | Profile path, permissions, or concurrent use | Remove the custom profile to test; use a unique writable profile for each parallel session. |
| ChromeDriver launches the wrong Chrome | Binary discovery or custom installation location | Set binary_location to the intended executable and record the selected path. |
| Managed browser fails while unmanaged Chrome works | Enterprise policy or managed configuration | Ask the administrator to review relevant automation and remote debugging policy. |
| Session starts, but screenshot fails | Navigation, page readiness, output path, or file permissions | Test navigation and save_screenshot separately and inspect their errors. |
Performance, reliability, and cost
Browser startup and driver discovery add work before a screenshot can be captured. Selenium Manager caches resolved assets, which can avoid repeated downloads; a cold run may still need network access to resolve or download a driver. Pinning compatible browser and Selenium versions in CI makes runs easier to reproduce, while updating them deliberately helps catch compatibility changes.
For repeatable automation, record the OS or container image, Selenium version, Chrome version, ChromeDriver source and version, binary path, profile behavior, and launch arguments. Ensure each parallel browser session has isolated profile and output paths. Preserve logs for failed startup attempts, but avoid exposing credentials or sensitive page data in shared logs.
With Selenium, the infrastructure and browser runtime are yours to operate; the exact cost depends on where and how you run them. ScreenshotNeo charges only for clean shots under the stated plan quotas, and its documented plan prices are Free (1,000/month), Starter ($5 for 3,000), Growth ($15 for 15,000), Pro ($39 for 60,000), Scale ($99 for 250,000), and Business ($249 for 1,000,000). Yearly billing gives two months free. All listed features are available on every plan.
FAQ
Does this error mean Selenium’s screenshot method is broken?
Usually the message is emitted during Chrome startup or connection. Confirm that session creation succeeds before diagnosing the screenshot operation.
Should I always add --no-sandbox in CI?
No. The error alone does not show that sandboxing is the cause. Check the logs and runtime constraints, then assess any security implications before changing sandbox behavior.
Will Selenium Manager fix every Chrome startup failure?
No. It can manage driver resolution when applicable, but it cannot fix a browser binary that exits because of an unrelated path, profile, runtime, or policy problem.
Can I use headless mode with current Chrome?
Yes. Chrome documents headless mode for automation. Check the installed version if a recipe depends on the older headless implementation, which is now distributed separately.


