User Agents

Web browsers and everyday web tech, explained

Run Chrome DevTools MCP in Headless Mode

· 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

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

  1. Install the MCP server package
    Run npm 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.
  2. Verify Chrome/Chromium is available
    Check if Chrome is installed: which google-chrome or which chromium. If not, install it via your package manager (e.g., apt install chromium on Debian/Ubuntu). Alternatively, let Puppeteer download a compatible version by running npx puppeteer browsers install chrome.
  3. Create a configuration file for your MCP client
    Most MCP clients read a JSON config. For example, in Claude Desktop, edit claude_desktop_config.json and add the server entry under mcpServers. Include the command and arguments to launch the server with headless flags.
  4. 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 --headless flag runs Chrome without a UI; --no-sandbox is often needed in containerized environments.
  5. 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.
  6. 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.
  7. Use MCP tools for automation
    Once running, you can use tools like navigate, evaluate (to run JavaScript), captureScreenshot, and getPerformanceMetrics to interact with pages programmatically.
  8. Stop the server when done
    Close the client or kill the process. The headless Chrome will terminate automatically.

Common Mistakes

  • Forgetting the --headless flag – 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-sandbox in 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-gpu to reduce resource usage in headless mode.
  • Set a custom user data directory with --user-data-dir=/tmp/chrome-profile to avoid conflicts.
  • For debugging, add --remote-debugging-port=9222 to 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 --executablePath argument.
  • Error: "Running as root without --no-sandbox is not supported"
    Add --no-sandbox to 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 the navigate tool and wait for the load event before capturing. Also, ensure the viewport is set properly.
  • Performance traces are empty
    Make sure you call startPerformanceTrace before 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.