Skip to content

Fix browser MCP standalone runtime#60

Merged
waydelyle merged 1 commit into
swarmclawai:mainfrom
borislavnnikolov:fix/browser-mcp-standalone-runtime
Apr 24, 2026
Merged

Fix browser MCP standalone runtime#60
waydelyle merged 1 commit into
swarmclawai:mainfrom
borislavnnikolov:fix/browser-mcp-standalone-runtime

Conversation

@borislavnnikolov
Copy link
Copy Markdown
Contributor

Summary

  • copy Playwright MCP runtime packages into Next standalone output
  • launch host Playwright MCP with cached chromium instead of system Chrome
  • add tests for standalone packaging and browser startup args

Tests

  • npm run test:cli -- scripts/run-next-build.test.mjs
  • npx tsx --test src/lib/server/session-tools/web-browser-config.test.ts
  • npm run build

Copilot AI review requested due to automatic review settings April 24, 2026 16:10
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR targets reliability of the Playwright MCP “browser” runtime when running a Next.js standalone build, ensuring the packaged output includes the required Playwright MCP runtime packages and that the MCP server is launched against Chromium with the expected startup configuration.

Changes:

  • Force Playwright MCP stdio server launches to use chromium (CLI args + env) when not attaching to a CDP endpoint.
  • Add a standalone build repair step to copy Playwright MCP runtime packages into .next/standalone/node_modules.
  • Add tests covering the new browser args/env behavior and the standalone repair copy behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/lib/server/session-tools/web-utils.ts Adds explicit Chromium selection for Playwright MCP stdio server launches.
src/lib/server/session-tools/web-browser-config.test.ts Extends tests to validate Chromium args/env and CDP behavior.
scripts/run-next-build.mjs Introduces repairStandaloneBrowserMcpRuntime and invokes it after successful builds.
scripts/run-next-build.test.mjs Adds a test verifying standalone repair copies required Playwright MCP runtime packages.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

for (const packageName of REQUIRED_STANDALONE_BROWSER_PACKAGES) {
const sourceDir = path.join(cwd, 'node_modules', ...packageName.split('/'))
const targetDir = path.join(standaloneNodeModules, ...packageName.split('/'))
if (fs.existsSync(targetDir)) continue
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

repairStandaloneBrowserMcpRuntime skips copying when targetDir already exists, but Next.js output tracing can create partially-populated package directories. In that case existsSync(targetDir) will be true even though required files (e.g. package.json / cli.js) are missing, and the repair will incorrectly no-op. Consider changing the guard to verify a sentinel file (like package.json or cli.js) or always copying/merging into targetDir with overwrite to ensure the runtime is complete.

Suggested change
if (fs.existsSync(targetDir)) continue
const targetPackageJson = path.join(targetDir, 'package.json')
if (fs.existsSync(targetPackageJson)) continue

Copilot uses AI. Check for mistakes.

assert.equal(params.command, process.execPath)
assert.equal(params.args.includes('--browser'), true)
assert.equal(params.args.includes('chromium'), true)
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

The assertion params.args.includes('chromium') can be a false positive if the profile/output paths ever contain the substring chromium. Make this robust by asserting that the argument immediately following --browser is exactly chromium (e.g., check args[indexOf('--browser') + 1]).

Suggested change
assert.equal(params.args.includes('chromium'), true)
assert.equal(params.args[params.args.indexOf('--browser') + 1], 'chromium')

Copilot uses AI. Check for mistakes.
Comment on lines 136 to 151
@@ -145,6 +146,7 @@ export function buildBrowserStdioServerParams(
env: {
...env,
...(cdpEndpoint ? { PLAYWRIGHT_MCP_CDP_ENDPOINT: cdpEndpoint } : {
PLAYWRIGHT_MCP_BROWSER: 'chromium',
PLAYWRIGHT_MCP_USER_DATA_DIR: profileDir,
PLAYWRIGHT_MCP_HEADLESS: '1',
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

'chromium' is duplicated in both the CLI args and env block. Consider extracting a single constant (e.g., const browserName = 'chromium') to avoid future drift if the default browser is changed again.

Copilot uses AI. Check for mistakes.
@waydelyle waydelyle merged commit 0f64612 into swarmclawai:main Apr 24, 2026
4 of 5 checks passed
@waydelyle
Copy link
Copy Markdown
Member

Thanks @borislavnnikolov. I verified the CLI/build tests, type-check, and production build, merged this into main, and included it in the v1.5.71 release notes.

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.

3 participants