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): report the actual remote browser name in browserInfo (#42228)

Pavel Feldman290c16d9c95a
diff --git a/packages/playwright-core/src/tools/index.ts b/packages/playwright-core/src/tools/index.ts
index 5fdad4331b..1b42c015a4 100644
--- a/packages/playwright-core/src/tools/index.ts
+++ b/packages/playwright-core/src/tools/index.ts
@@ -25,7 +25,7 @@ export { createConnection } from './mcp/index';
export { resolveCLIConfigForCLI, resolveCLIConfigForMCP } from './mcp/config';
export { outputDir } from './backend/context';
export { isSystemDirectory } from '@utils/fileUtils';
-export { isProfileLocked } from './mcp/browserFactory';
+export { createBrowserWithInfo, isProfileLocked } from './mcp/browserFactory';
export { compareSemver } from './utils/socketConnection';
export { extractTrace, DirTraceLoaderBackend } from './trace/traceParser';
export { decorateMCPCommand } from './mcp/program';
diff --git a/packages/playwright-core/src/tools/mcp/browserFactory.ts b/packages/playwright-core/src/tools/mcp/browserFactory.ts
index 8cd9656dd5..5ca1c20b7a 100644
--- a/packages/playwright-core/src/tools/mcp/browserFactory.ts
+++ b/packages/playwright-core/src/tools/mcp/browserFactory.ts
@@ -152,7 +152,7 @@ async function createRemoteBrowser(config: FullConfig): Promise<BrowserWithInfo>
// created, so create one when attaching to such a server.
if (!browser.contexts().length)
await browser.newContext(config.browser.contextOptions);
- return { browser, browserInfo: browserInfo(browser, config), canBind: false, ownership: 'attached' };
+ return { browser, browserInfo: { ...browserInfo(browser, config), browserName: browser._browserName }, canBind: false, ownership: 'attached' };
}
async function createPersistentBrowser(config: FullConfig, clientInfo: ClientInfo): Promise<playwrightTypes.Browser> {
diff --git a/tests/mcp/remote-endpoint.spec.ts b/tests/mcp/remote-endpoint.spec.ts
index 42521074bb..4b0ce13b78 100644
--- a/tests/mcp/remote-endpoint.spec.ts
+++ b/tests/mcp/remote-endpoint.spec.ts
@@ -16,6 +16,10 @@
import { test, expect } from './fixtures';
+import { tools } from '../../packages/playwright-core/lib/coreBundle';
+
+const { resolveCLIConfigForMCP, createBrowserWithInfo } = tools;
+
test.skip(({ mcpBrowser }) => mcpBrowser !== 'chromium', 'Run only on the chromium project; the remote server connection is browser-agnostic.');
test('connect without headers fails on run-server endpoint', async ({ startClient, server, runServerEndpoint }) => {
@@ -60,6 +64,18 @@ test('remoteEndpoint accepts ConnectOptions object with headers', async ({ start
});
});
+test('browserInfo reports the browser running on the remote endpoint, not the configured one', async ({ wsEndpoint }, testInfo) => {
+ // Empty env to isolate the test from the host environment.
+ const config = await resolveCLIConfigForMCP({ browser: 'firefox', endpoint: wsEndpoint }, {});
+ const { browser, browserInfo } = await createBrowserWithInfo(config, { clientName: 'test-client', cwd: testInfo.outputPath() }, {});
+ try {
+ expect(config.browser.browserName).toBe('firefox');
+ expect(browserInfo.browserName).toBe('chromium');
+ } finally {
+ await browser.close();
+ }
+});
+
test('back-compat: remoteHeaders config still selects the browser on run-server endpoint', async ({ startClient, server, runServerEndpoint }) => {
const { client } = await startClient({
config: {