Run Chrome DevTools MCP in Headless Mode
In this article
Running Chrome DevTools MCP (Model Context Protocol) in headless mode lets you automate browser interactions, capture performance traces, and test web pages without a visible UI. This is ideal for CI/CD pipelines, server-side scripts, or any environment without a display. You'll need Node.js (v18 or later), the MCP server package, and a basic understanding of MCP clients. Here's how to set it up.
What You'll Need
- Node.js (v18+) installed on your system
- Chrome or Chromium browser (can be installed via Puppeteer if needed)
- An MCP client (like Claude Desktop, VS Code with MCP extension, or a custom script)
- Basic command-line familiarity
Step-by-Step
- Install the MCP server package
Runnpm install -g @modelcontextprotocol/server-chrome-devtools(or the package name you're using). This installs the server globally so it can be invoked from anywhere. - Verify Chrome/Chromium is available
Check if Chrome is installed:which google-chromeorwhich chromium. If not, install it via your package manager (e.g.,apt install chromiumon Debian/Ubuntu). Alternatively, let Puppeteer download a compatible version by runningnpx puppeteer browsers install chrome. - Create a configuration file for your MCP client
Most MCP clients read a JSON config. For example, in Claude Desktop, editclaude_desktop_config.jsonand add the server entry undermcpServers. Include the command and arguments to launch the server with headless flags. - Add headless flags to the server launch command
The server usually accepts browser launch options. In the config, set the command to something like:
"command": "npx", "args": ["-y", "@modelcontextprotocol/server-chrome-devtools", "--headless", "--no-sandbox"]
The--headlessflag runs Chrome without a UI;--no-sandboxis often needed in containerized environments. - Start your MCP client
Launch your client (e.g., restart Claude Desktop). It should connect to the MCP server, which will spawn a headless Chrome instance. - Test with a simple prompt
Ask your client to "navigate to example.com and take a screenshot". If it works, the server will return a screenshot file path or data URL, confirming headless mode is active. - Use MCP tools for automation
Once running, you can use tools likenavigate,evaluate(to run JavaScript),captureScreenshot, andgetPerformanceMetricsto interact with pages programmatically. - Stop the server when done
Close the client or kill the process. The headless Chrome will terminate automatically.
Common Mistakes
- Forgetting the
--headlessflag – The server might default to headed mode, causing errors in headless environments. - Not installing Chrome – The server expects a browser binary; if missing, it fails silently or with a confusing error.
- Using wrong config path – MCP clients look for config in specific locations; placing it elsewhere won't work.
- Missing
--no-sandboxin root/container – Chrome's sandbox requires privileges; without it, the process crashes. - Assuming headless equals invisible – Headless still uses system resources; ensure your environment has enough memory/CPU.
Tips
- Use
--disable-gputo reduce resource usage in headless mode. - Set a custom user data directory with
--user-data-dir=/tmp/chrome-profileto avoid conflicts. - For debugging, add
--remote-debugging-port=9222to the args and connect via DevTools protocol manually. - If you need to run multiple instances, use separate user data dirs.
- Consider using Puppeteer's bundled Chrome to ensure version compatibility:
npx puppeteer browsers install chrome.
Troubleshooting
- Server starts but Chrome doesn't launch
Check the server logs for errors. Ensure the Chrome binary is in PATH or specify its path via--executablePathargument. - Error: "Running as root without --no-sandbox is not supported"
Add--no-sandboxto the server args. This is common in Docker or CI environments. - Connection refused when client tries to connect
Verify the MCP server is running and the client config uses the correct command. Check if the server process is alive (e.g.,ps aux | grep mcp). - Screenshots return blank or black images
This often happens when the page hasn't finished loading. Use thenavigatetool and wait for theloadevent before capturing. Also, ensure the viewport is set properly. - Performance traces are empty
Make sure you callstartPerformanceTracebefore performing actions, and stop it before retrieving data. - MCP client doesn't see the server
Restart the client after config changes. Also check the config file syntax (JSON) and that the path is correct.
Frequently Asked Questions
Can I run headless Chrome DevTools MCP without installing Chrome separately?
Yes, you can let Puppeteer download a compatible Chrome version. Use npx puppeteer browsers install chrome and then set the executablePath in the server args to the downloaded path.
Does headless mode support all DevTools features?
Most features work, including network interception, performance metrics, and JavaScript evaluation. Some features like device emulation work, but you may need to set viewport and user agent manually.
How do I pass custom Chrome flags to the MCP server?
Add them as additional arguments in the server's args array in your MCP client config. For example, "--disable-web-security" for CORS testing.
Can I use this in a Docker container?
Yes, but you'll need to install Chrome inside the container, include --no-sandbox, and ensure the container has enough resources. Also, use a non-root user if possible.
Is there a way to see what the headless browser is doing?
You can enable remote debugging by adding --remote-debugging-port=9222 and then open http://localhost:9222 in a regular browser to inspect the headless instance.
How do I stop the headless Chrome process after use?
The MCP server typically kills Chrome when the client disconnects. If not, you can manually kill the process with pkill chrome or pkill chromium.