Skip to content

Headless isolated launch fails as root without --no-sandbox #261

@mamoru127

Description

@mamoru127

Summary

Running chrome-devtools-mcp as the root user causes Chrome to exit immediately with Running as root without --no-sandbox is not supported, so the MCP client receives Target closed / Connection closed
errors.

Environment

  • chrome-devtools-mcp 0.6.0
  • Node.js 22.20.0
  • OS: Linux container (root user)
  • Command: node build/src/index.js --headless --isolated

Steps to Reproduce

  1. Checkout v0.6.0
  2. Run npm install && npm run build
  3. Execute node build/src/index.js --headless --isolated as root
  4. Observe Chrome crashing with the log above and the MCP server exiting

Expected Behavior

The bundled Chrome should launch successfully even when the server runs as root (typical for containers/CI), without requiring extra flags from the user.

Suggested Fix

Automatically add sandbox flags when running as root. For example in src/browser.ts:

const args = [
  ...(options.args ?? []),
  '--hide-crash-restore-bubble',
];

if (process.getuid?.() === 0 && !args.some(arg => arg.startsWith('--no-sandbox'))) {
  args.push('--no-sandbox', '--disable-setuid-sandbox');
}

Then rebuild (npm run build) so the generated build/src/browser.js picks up the same logic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions