Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(mcp-extension): properly resolve chrome-for-testing executable location (#39936)

Yury Semikhatskyc68820a5395d
diff --git a/packages/playwright-core/src/tools/mcp/cdpRelay.ts b/packages/playwright-core/src/tools/mcp/cdpRelay.ts
index 9a50b18aaa..a24190d53b 100644
--- a/packages/playwright-core/src/tools/mcp/cdpRelay.ts
+++ b/packages/playwright-core/src/tools/mcp/cdpRelay.ts
@@ -99,11 +99,11 @@ export class CDPRelayServer {
return `${this._wsHost}${this._extensionPath}`;
}
- async ensureExtensionConnectionForMCPContext(clientInfo: ClientInfo, forceNewTab: boolean) {
+ async ensureExtensionConnectionForMCPContext(clientInfo: ClientInfo) {
debugLogger('Ensuring extension connection for MCP context');
if (this._extensionConnection)
return;
- this._connectBrowser(clientInfo, forceNewTab);
+ this._connectBrowser(clientInfo);
debugLogger('Waiting for incoming extension connection');
await Promise.race([
this._extensionConnectionPromise,
@@ -114,7 +114,7 @@ export class CDPRelayServer {
debugLogger('Extension connection established');
}
- private _connectBrowser(clientInfo: ClientInfo, forceNewTab: boolean) {
+ private _connectBrowser(clientInfo: ClientInfo) {
const mcpRelayEndpoint = `${this._wsHost}${this._extensionPath}`;
// Need to specify "key" in the manifest.json to make the id stable when loading from file.
const url = new URL('chrome-extension://mmlmfjhmonkocbjadbfplnigmagldckm/connect.html');
@@ -125,16 +125,15 @@ export class CDPRelayServer {
};
url.searchParams.set('client', JSON.stringify(client));
url.searchParams.set('protocolVersion', process.env.PWMCP_TEST_PROTOCOL_VERSION ?? protocol.VERSION.toString());
- if (forceNewTab)
- url.searchParams.set('newTab', 'true');
const token = process.env.PLAYWRIGHT_MCP_EXTENSION_TOKEN;
if (token)
url.searchParams.set('token', token);
const href = url.toString();
+ const channel = registry.isChromiumAlias(this._browserChannel) ? 'chromium' : this._browserChannel;
let executablePath = this._executablePath;
if (!executablePath) {
- const executableInfo = registry.findExecutable(this._browserChannel);
+ const executableInfo = registry.findExecutable(channel);
if (!executableInfo)
throw new Error(`Unsupported channel: "${this._browserChannel}"`);
executablePath = executableInfo.executablePath();
@@ -145,7 +144,7 @@ export class CDPRelayServer {
const args: string[] = [];
if (this._userDataDir)
args.push(`--user-data-dir=${this._userDataDir}`);
- if (os.platform() === 'linux' && this._browserChannel === 'chromium')
+ if (os.platform() === 'linux' && channel === 'chromium')
args.push('--no-sandbox');
args.push(href);
spawn(executablePath, args, {
diff --git a/packages/playwright-core/src/tools/mcp/extensionContextFactory.ts b/packages/playwright-core/src/tools/mcp/extensionContextFactory.ts
index 07865abc83..edeabcf436 100644
--- a/packages/playwright-core/src/tools/mcp/extensionContextFactory.ts
+++ b/packages/playwright-core/src/tools/mcp/extensionContextFactory.ts
@@ -34,6 +34,6 @@ export async function createExtensionBrowser(config: FullConfig, clientInfo: Cli
config.browser.launchOptions.executablePath);
debugLogger(`CDP relay server started, extension endpoint: ${relay.extensionEndpoint()}.`);
- await relay.ensureExtensionConnectionForMCPContext(clientInfo, /* forceNewTab */ false);
+ await relay.ensureExtensionConnectionForMCPContext(clientInfo);
return await playwright.chromium.connectOverCDP(relay.cdpEndpoint(), { isLocal: true });
}
diff --git a/tests/mcp/cli-fixtures.ts b/tests/mcp/cli-fixtures.ts
index fc82631455..2f9d7e48c3 100644
--- a/tests/mcp/cli-fixtures.ts
+++ b/tests/mcp/cli-fixtures.ts
@@ -91,7 +91,7 @@ function cliEnv() {
return {
PLAYWRIGHT_SERVER_REGISTRY: test.info().outputPath('registry'),
PLAYWRIGHT_DAEMON_SESSION_DIR: test.info().outputPath('daemon'),
- PLAYWRIGHT_SOCKETS_DIR: path.join(test.info().project.outputDir, 'ds'),
+ PLAYWRIGHT_SOCKETS_DIR: path.join(test.info().project.outputDir, 'ds', String(test.info().parallelIndex)),
};
}