Skip to content

Playwright MCP plugin can't launch a browser in claude-code-sandbox, and the existing ARM64 patch is broken in claude-code too #85

Closed

Description

@gatezh

Summary

The Playwright MCP plugin (playwright@claude-plugins-official) cannot launch a browser in containers built from this repo. Two related problems:

  1. claude-code-sandbox has no chromium binary, no Playwright OS deps, and the firewall blocks apt-get install, so there is no in-container path to add them later. Playwright is structurally unavailable in the sandbox variant.
  2. claude-code ships chromium at /usr/bin/chromium and sets PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH, which works for @playwright/test but not for @playwright/mcp — MCP defaults to the chrome channel (Google Chrome stable at /opt/google/chrome/chrome), which the env var doesn't redirect.

Independently, the optional init-plugins.sh snippet that ships in this repo has three bugs that compound the problem on both variants:

  • It writes --browser chromium into the plugin's .mcp.json, but newer @playwright/mcp rejects that value (--browser only accepts chrome|firefox|webkit|msedge). The patch was previously a no-op; with the rejected value it now actively breaks MCP startup.
  • It uses find … -print -quit, which patches only the first match. Plugin updates land in fresh cache dirs (e.g. ~/.claude/plugins/cache/claude-plugins-official/playwright/<hash>/); each new version arrives unpatched.
  • It runs only at postCreateCommand. After a plugin update, the un-patched cache dir is what Claude Code uses, and init-plugins.sh never revisits it.

Reproducing in claude-code-sandbox

In a sandbox container (e.g. ghcr.io/gatezh/devcontainers/claude-code-sandbox:latest):

$ which chromium && /usr/bin/chromium --version    # not found
$ ls /home/node/.cache/ms-playwright               # only chromium_headless_shell-* if `playwright install --only-shell` ran
$ ldd /home/node/.cache/ms-playwright/chromium_headless_shell-*/chrome-linux/headless_shell | grep "not found"
libglib-2.0.so.0 => not found
libnspr4 => not found
libnss3 => not found
libgbm.so.1 => not found
… (around twenty more)
$ sudo npx playwright install-deps chromium
…
Could not connect to debian.map.fastlydns.net:80 - connect (113: No route to host)
Failed to install browser dependencies

In Claude Code, mcp__plugin_playwright_playwright__browser_navigate then fails with:

Chromium distribution 'chrome' is not found at /opt/google/chrome/chrome
Run "npx playwright install chrome"

Reproducing in claude-code (default)

The same browser_navigate call fails the same way: MCP looks at /opt/google/chrome/chrome, not /usr/bin/chromium. The PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH env var doesn't apply to the chrome channel. So even on the default variant, MCP is unusable out of the box — it just isn't blocked on missing OS deps the way sandbox is.

Proposed fix

Three coordinated changes. They land in claude-code/.devcontainer/Dockerfile, a new claude-code/.devcontainer/playwright-mcp-launcher.sh, and the existing claude-code/.devcontainer/init-plugins.sh.

1. Mirror the default target's chromium install into sandbox

Today the chromium install lives in the default target with the explicit comment "Kept out of the base stage so the sandbox target stays lean." That trade-off was reasonable when sandbox didn't need to render pages, but the value of MCP browser tooling in the sandbox variant outweighs the ~150 MB image-size cost. The deps cannot be added after image build (firewall blocks deb.debian.org) and the larger Microsoft Playwright base image is more disruptive than this one apt step.

Add to the FROM base AS sandbox stage:

RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
    --mount=type=cache,target=/var/lib/apt/lists,sharing=locked \
    apt-get update && apt-get install -y --no-install-recommends \
      chromium \
      fonts-freefont-ttf
USER node
ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 \
    PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=/usr/bin/chromium

The chromium apt package transitively pulls every shared lib it needs (libnss3, libglib2.0-0, libgbm1, libxkbcommon0, libdbus-1-3, libdrm2, libcairo2, libpango-1.0-0, libxcomposite1, libxdamage1, libxext6, libxfixes3, libxrandr2, libcups2t64, libxcb1, libx11-6, libatk1.0-0t64, libatk-bridge2.0-0t64, libatspi2.0-0t64, libasound2t64, …). No need to enumerate them by hand the way playwright install-deps does.

The --no-install-recommends keeps the install minimal; on Trixie this currently sits around ~150 MB compressed. That is the correct cost: the user gets a working Playwright in sandbox without changing the base image.

(agent-browser is the other thing the default target adds; it does not need to ship in sandbox unless someone asks for it.)

2. Bake a launcher script into both image targets

Add claude-code/.devcontainer/playwright-mcp-launcher.sh:

#!/usr/bin/env bash
# Launches @playwright/mcp against the chromium binary present in this image.
#
# Background: @playwright/mcp's `--browser` flag only accepts chrome|firefox|
# webkit|msedge. The default channel `chrome` looks for /opt/google/chrome/chrome,
# which we don't install. The `PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH` env var
# only redirects the `chromium` browser, not the `chrome` channel — so MCP
# needs an explicit `--executable-path`.
#
# Resolution order:
#   1. $PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH (set by Dockerfile)
#   2. /usr/bin/chromium (system apt-installed)
#   3. ~/.cache/ms-playwright/chromium-*/chrome-linux/chrome (full Playwright install)
#   4. ~/.cache/ms-playwright/chromium_headless_shell-*/chrome-linux/headless_shell

set -euo pipefail

resolve_chromium() {
    if [ -n "${PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH:-}" ] \
       && [ -x "$PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH" ]; then
        echo "$PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH"; return
    fi
    if [ -x /usr/bin/chromium ]; then
        echo "/usr/bin/chromium"; return
    fi
    local cache="${PLAYWRIGHT_BROWSERS_PATH:-$HOME/.cache/ms-playwright}"
    local bin
    bin="$(find "$cache" -path '*/chromium-*/chrome-linux/chrome' -print -quit 2>/dev/null || true)"
    [ -z "$bin" ] && bin="$(find "$cache" -path '*/chromium_headless_shell-*/chrome-linux/headless_shell' -print -quit 2>/dev/null || true)"
    echo "$bin"
}

BIN="$(resolve_chromium)"
if [ -z "$BIN" ]; then
    echo "playwright-mcp-launcher: no chromium binary found." >&2
    echo "  Expected /usr/bin/chromium (image apt) or under \$HOME/.cache/ms-playwright." >&2
    exec npx @playwright/mcp@latest "$@"  # let MCP error with its own message
fi

exec npx @playwright/mcp@latest \
    --executable-path "$BIN" \
    --headless \
    --no-sandbox \
    "$@"

--no-sandbox is required: chromium's sandbox needs setuid or unprivileged user namespaces, which devcontainers commonly disable. --headless is required because there's no display.

In the Dockerfile, install it into both targets (or, simpler, into base):

COPY .devcontainer/playwright-mcp-launcher.sh /usr/local/bin/playwright-mcp-launcher
RUN chmod 0755 /usr/local/bin/playwright-mcp-launcher

3. Fix init-plugins.sh: drop the broken ARM64 block, loop over every cached .mcp.json, point at the launcher

Replace the existing ARM64 block:

# ── Playwright MCP: route through devcontainer-aware launcher ───────────────
# @playwright/mcp's default channel `chrome` looks for /opt/google/chrome/chrome,
# which isn't installed. Newer @playwright/mcp also dropped `chromium` from
# --browser, so the previous --browser chromium workaround no longer parses.
#
# Loop over every cached version because plugin updates land in fresh cache
# dirs; previously `find -print -quit` only patched the first one.
LAUNCHER="/usr/local/bin/playwright-mcp-launcher"
if [ -x "$LAUNCHER" ]; then
    find "$HOME/.claude/plugins/cache" -path "*/playwright*/.mcp.json" 2>/dev/null \
    | while read -r MCP_CONFIG; do
        jq --arg cmd "$LAUNCHER" \
            '.playwright = {command: $cmd, args: []}' \
            "$MCP_CONFIG" > /tmp/playwright-mcp.json \
            && mv /tmp/playwright-mcp.json "$MCP_CONFIG" \
            && echo "✔ Playwright MCP patched: $MCP_CONFIG"
    done
fi

Notes:

  • No more aarch64 conditional — the issue is universal (no Chrome on either arch in this image), not ARM-specific.
  • No -print -quit — patches every cached version.
  • Idempotent: re-running rewrites to the same value.

Follow-up: keep the patch in sync with plugin updates

init-plugins.sh runs at postCreateCommand, i.e. once per container creation. When the Claude plugin manager auto-updates playwright@claude-plugins-official, it extracts a fresh cache dir whose .mcp.json is the un-patched default — and init-plugins.sh doesn't run again to re-patch it. Until the user rebuilds the container, MCP silently breaks again.

Two ways to address this in the same change:

Option A — re-run patching on every container start. Move the MCP-config block out of init-plugins.sh and into a small standalone script (patch-playwright-mcp.sh), invoked from postStartCommand in the consumer's devcontainer.json (templates can include this by default). Cheap to run (it's three find+jq calls), idempotent, catches every plugin update.

Option B — bypass the plugin's .mcp.json entirely. Define mcpServers.playwright directly in ~/.claude/settings.json (enabledPlugins.playwright@claude-plugins-official: false, and ship a settings.json fragment that points at the launcher). The plugin's bundled MCP config is never read, so updates can't break us. The cost is that the user loses any other artifacts the plugin might bundle (skills, agents) — none today, but a future plugin version could add some.

I'd lean Option A: it's a 10-line script, doesn't fight the plugin system, and stays correct under plugin updates. Option B is a bigger architectural commitment.

Trade-offs / alternatives I considered and rejected

  • Switch the base image to mcr.microsoft.com/playwright:vX.Y.Z-noble. Ships chromium + deps + Playwright versioned together. Rejected because it gives up control over the rest of the toolchain (mise, fish, starship, gh, the entire sandbox/default split) and pins Playwright versions at the image layer.
  • Open up the sandbox firewall to allow deb.debian.org so the user can playwright install-deps at devcontainer creation. Rejected: widens the firewall in a way that runs counter to the sandbox variant's reason to exist, and adds ~30s of apt churn to every container creation.
  • Patch each consumer project's .devcontainer/init-plugins.sh and ship a launcher per repo. Rejected: this is the workaround consumer projects currently apply locally, but it's exactly the kind of cross-project drift this devcontainer repo exists to prevent.

Verification plan

  1. Rebuild both targets locally:
    docker build --target default -t claude-code:default .
    docker build --target sandbox -t claude-code:sandbox .
  2. In each, confirm:
    /usr/bin/chromium --version
    ldd /usr/bin/chromium | grep -c 'not found'   # expect 0
    /usr/local/bin/playwright-mcp-launcher --version   # expect "Version X.Y.Z" from MCP
  3. In a Claude Code session against each target, after a plugin install, run init-plugins.sh and confirm every .mcp.json under ~/.claude/plugins/cache/claude-plugins-official/playwright/*/ has been rewritten:
    cat ~/.claude/plugins/cache/claude-plugins-official/playwright/*/.mcp.json
    Expected: each shows {"playwright": {"command": "/usr/local/bin/playwright-mcp-launcher", "args": []}}.
  4. Restart Claude Code, then call mcp__plugin_playwright_playwright__browser_navigate to about:blank. Expected: succeeds (no "Chromium distribution 'chrome' is not found").
  5. Simulate a plugin update by creating a dummy un-patched .mcp.json (e.g. ~/.claude/plugins/cache/claude-plugins-official/playwright/zzzz/.mcp.json with the default content) and re-run init-plugins.sh (Option A: also re-run the standalone patch-playwright-mcp.sh). Expected: the dummy config is now patched.

Why this matters for consumer projects

Without this change, every project using these images has to ship its own patched init-plugins.sh plus a launcher, OR write a project-local SKILL.md that hard-codes a workaround. Both drift quickly across a fleet of similar projects. Centralizing the fix here means one well-maintained launcher and one canonical skill (the generic discovery-driven sandbox-playwright/SKILL.md that this issue's filer can also contribute to claude-code/.claude/skills/).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions