Skip to content

fix(mcp): resolve browser version mismatch path reporting and environ…#41943

Open
Vrindakr3300 wants to merge 1 commit into
microsoft:mainfrom
Vrindakr3300:fix/playwright-mcp-lm-studio-fixes
Open

fix(mcp): resolve browser version mismatch path reporting and environ…#41943
Vrindakr3300 wants to merge 1 commit into
microsoft:mainfrom
Vrindakr3300:fix/playwright-mcp-lm-studio-fixes

Conversation

@Vrindakr3300

Copy link
Copy Markdown

Summary

This PR addresses two compounding issues affecting the Playwright MCP server when integrating with sandboxed hosts (such as LM Studio):

  1. Browser Version Mismatch Diagnostics: When a managed browser binary is missing on disk, the MCP server previously caught playwright-core's original error message (which includes the specific versioned directory path, e.g. firefox-1534\firefox.exe) and rethrew a generic "Browser is not installed" error, dropping the path. This made version mismatches very difficult to diagnose. We now append the original error message to the rethrown error.
  2. Environment Variable Propagation: When spawning the browser subprocess, process.env was completely replaced if options.env was defined. Under Electron sandbox environments like LM Studio, this resulted in crucial environment variables (like PLAYWRIGHT_BROWSERS_PATH and system PATH parameters) being stripped. We now merge process.env with the custom options.env when spawning the browser process.

Changes

  • packages/playwright-core/src/tools/mcp/browserFactory.ts: Modified throwIfExecutableMissing to append the original error.message to the thrown error message.
  • packages/playwright-core/src/server/browserType.ts: Merges process.env with the custom options.env when launching browser processes.
  • tests/mcp/launch.spec.ts: Added missing browser path in error message test case to assert that both the installation instructions and the exact missing path are reported, skipping system channels like chrome and msedge.

Closes #41871

@Vrindakr3300

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

} = options;

const env = options.env ? envArrayToObject(options.env) : process.env;
const env = options.env ? { ...process.env, ...envArrayToObject(options.env) } : process.env;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this conflicts with existing documented behavior

the whole idea of options.env is to be able to replace the default process.env

also, i dont think options.env is set by MCP so it should already be using process.env

throw new Error(`${label} is not installed. Run \`playwright-cli install-browser ${target}\` to install`);
throw new Error(`${label} is not installed. Run \`npx @playwright/mcp install-browser ${target}\` to install`);
throw new Error(`${label} is not installed. Run \`playwright-cli install-browser ${target}\` to install${suffix}`);
throw new Error(`${label} is not installed. Run \`npx @playwright/mcp install-browser ${target}\` to install${suffix}`);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this was already fixed in #41941

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.

[Bug]: Playwright MCP Server Fails in LM Studio: Browser Version Mismatch + Electron Env Var Propagation Failure

2 participants