Skip to content

feat: support passing args to Chrome - #338

Merged
OrKoN merged 2 commits into
mainfrom
orkon/chrome-args
Oct 10, 2025
Merged

OrKoN merged 2 commits into
mainfrom
orkon/chrome-args

Conversation

@OrKoN

@OrKoN OrKoN commented Oct 10, 2025 •

Copy link
Copy Markdown
Collaborator

Drive-by: removes custom devtools frontend as a dedicated argument.

Closes #261

@OrKoN
OrKoN force-pushed the orkon/chrome-args branch 2 times, most recently from 293bd38 to ae9d695 Compare October 10, 2025 14:41
@OrKoN
OrKoN requested a review from jackfranklin October 10, 2025 14:41
@OrKoN
OrKoN force-pushed the orkon/chrome-args branch from ae9d695 to e96f34d Compare October 10, 2025 15:01
@OrKoN
OrKoN enabled auto-merge (squash) October 10, 2025 15:01
@OrKoN
OrKoN merged commit e1b5363 into main Oct 10, 2025
@OrKoN
OrKoN deleted the orkon/chrome-args branch October 10, 2025 15:05
OrKoN pushed a commit that referenced this pull request Oct 10, 2025
AlinaVarkki pushed a commit that referenced this pull request Oct 13, 2025
Drive-by: removes custom devtools frontend as a dedicated argument.

Closes #261
eacp1991 pushed a commit to eacp1991/chrome-devtools-mcp that referenced this pull request Sep 15, 2026
…s#2634)

Follow-up to ChromeDevTools#261. That issue was closed by ChromeDevTools#338, which added
`--chrome-arg` so the sandbox can be disabled explicitly. The flag
works, but the failure it fixes is still undiscoverable — you cannot
find out that `--chrome-arg=--no-sandbox` is the answer.

### Problem

`launch()` uses `pipe: true`. In pipe mode Puppeteer never calls
`waitForLineOutput()`, which is the only place Chrome's stderr makes it
into the thrown error. So when Chrome exits at startup with

```
Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
```

that line is dropped, and what reaches the MCP client is:

```
Protocol error (Target.setDiscoverTargets): Target closed
```

Reproduced on `main` (v1.8.0) by pointing `executablePath` at a stub
that prints Chrome's message to stderr and exits 1 — exactly the symptom
reported in ChromeDevTools#261. The `catch` in `launch()` only recognised `The browser
is already running`.

### Fix

Detect the case and rethrow with an explanation. Deliberately **not**
disabling the sandbox automatically, per
ChromeDevTools#261 (comment):

```
Chrome failed to start: Protocol error (Target.setDiscoverTargets): Target closed

chrome-devtools-mcp is running as root and Chrome does not start as root unless its
sandbox is disabled (https://crbug.com/638180). Prefer running chrome-devtools-mcp as
a non-root user. If that is not possible, for example in a container, pass
--chrome-arg=--no-sandbox. That disables the Chrome sandbox, so only do it for content
you trust.
```

Notes on the shape of the check:

- It runs **only on a failed launch**, so root with a properly installed
setuid sandbox is unaffected.
- The original error is kept in the message and as `cause`, so an
unrelated failure under root is never masked or mislabelled.
- `--no-sandbox` present in the args short-circuits it: root is then not
what stopped Chrome.
- `--disable-setuid-sandbox` and `--no-sandbox-and-elevated` do **not**
count as opting out — Chrome's zygote check requires `--no-sandbox`
specifically. Covered by a test.
- On Windows `process.getuid` is undefined, so the check is a no-op.

Also adds a "Running as root" section to `docs/troubleshooting.md`, next
to the existing "Operating system sandboxes".

### Testing

Five unit tests in `tests/browser.test.ts` covering root / non-root /
no-uid platforms, the already-opted-out args, and the near-miss args
above.

The pre-existing integration tests in that file cannot run in my
environment — Chrome reports `No usable sandbox! ... AppArmor userns
restrictions` there, on a clean checkout as well as with this change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants