Skip to content

fix(mcp): launch the browser MCP from playwright-mcp, not npx - #331

Merged
BaaRai merged 3 commits into
BaaRai:mainfrom
Coff0xc:fix/browser-mcp-npx
Nov 18, 2026
Merged

BaaRai merged 3 commits into
BaaRai:mainfrom
Coff0xc:fix/browser-mcp-npx

Conversation

@Coff0xc

@Coff0xc Coff0xc commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

npx @playwright/mcp hits the npm registry on every start even with the global install, so the image pin is not what runs and offline/egress-filtered starts fail. Playwright MCP then defaults to the chrome channel, and its playwright-core wants Chromium 1247 while playwright install puts 1248 in the cache.

  • Seed playwright-mcp --headless --browser chromium
  • Rewrite leftover stock npx @playwright/mcp rows once (browser_mcp_direct_bin_v1), including the common -y form; a playwright-mcp row with no --browser gets --browser chromium; any other command or package is left alone
  • Install the Chromium build nested in @playwright/mcp's playwright-core (resolved via require.resolve)
  • syncBrowserMCPProxy / stdio spawn do not assume args[0] is npx

Tested: go test ./db ./server -run TestRewriteStockNpxBrowserMCP|TestRewriteBrowserMCPRow|TestStripProxyArgsLeavesBrowserMCPFlags pass. PG migrate tests skipped (no DSN). Did not rebuild the image.

Fixes #329

Copilot AI balanced review requested due to automatic review settings November 18, 2026 11:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@Coff0xc
Coff0xc force-pushed the fix/browser-mcp-npx branch from 96d2784 to fe5748e Compare November 18, 2026 11:30

@BaaRai BaaRai left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix itself is right: the global binary avoids the registry, --browser chromium matches the image, and the one-time migration leaves custom commands alone. Two things before merge.

  1. CI does not build the Docker image, so the new node ... playwright-core/cli.js install chromium line is the only part I cannot verify from the diff. Please paste the successful docker build line for that invocation, on the same base image.
  2. The rewrite includes explicitly pinned npx @playwright/mcp@version rows, which silently move them to the image's global build. Either say so in the CHANGELOG or leave pinned rows alone. A custom image that ships Chrome also gets --browser chromium once; document that in the migration note.

@Coff0xc
Coff0xc force-pushed the fix/browser-mcp-npx branch from fe5748e to c9e030b Compare November 18, 2026 17:05
@BaaRai

BaaRai commented Nov 18, 2026

Copy link
Copy Markdown
Owner

One correction to the Dockerfile, pushed as f6e9b75.

The require.resolve line never installed the second Chromium build, and the build still succeeded. playwright-core's exports map does not expose ./cli.js, so the inner node -p threw ERR_PACKAGE_PATH_NOT_EXPORTED, $() swallowed it, the outer node got an empty script path, and node "" exits 0. A full build produced an image with chromium-1248 only.

It now runs the binary npm links for @playwright/mcp, which is the copy MCP actually loads:

"$(npm root -g)/@playwright/mcp/node_modules/.bin/playwright-core" install chromium

Verified with a full docker build: chromium-1247 and chromium-1248 are both in /root/.cache/ms-playwright, and @playwright/mcp's playwright-core launches 155.0.8059.12. @playwright/cli's playwright-core is the same 1.64.0-alpha build and expects 1247 too, so one install covers both.

@BaaRai BaaRai left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Docker line is fixed and proven: both Chromium builds are in the image and MCP own playwright-core launches 155.0.8059.12. Approving.

Coff0xc and others added 3 commits November 18, 2026 22:42
npx @playwright/mcp queries the npm registry on every start even with
the package installed globally, so the image's pin did not decide what
ran and offline starts failed. Seed playwright-mcp --headless --browser
chromium, rewrite leftover stock npx rows once, and install the Chromium
build the MCP's own playwright-core expects.

Fixes BaaRai#329
The stock seed was npx @playwright/mcp, but the UI mock and common
invocations use npx -y, which the first pass left untouched. Also add
--browser chromium to a leftover playwright-mcp --headless row, resolve
the MCP's playwright-core CLI via require.resolve, and cover proxy-arg
stripping so capture sync does not depend on args[0].
playwright-core's exports map does not expose ./cli.js, so
require.resolve threw inside the command substitution, the outer node
got an empty script path, and the build still succeeded without
installing chromium v1247. Run the binary npm links for @playwright/mcp
instead. Verified with docker build: both v1247 and v1248 are in the
cache, and @playwright/mcp's playwright-core launches 155.0.8059.12.
@BaaRai
BaaRai force-pushed the fix/browser-mcp-npx branch from f6e9b75 to 5a4af1b Compare November 18, 2026 21:42
@BaaRai
BaaRai merged commit 8f3a9a8 into BaaRai:main Nov 18, 2026
5 checks passed
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.

Browser MCP: npx @playwright/mcp queries the npm registry on every start despite the global install

3 participants