Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix(mcp): pass noDefaults for extension CDP connections (#42119)
Yury Semikhatsky539fd2c1047e
diff --git a/packages/playwright-core/src/tools/mcp/extensionContextFactory.ts b/packages/playwright-core/src/tools/mcp/extensionContextFactory.tsindex c8c8d1d8cc..4d8b554d92 100644--- a/packages/playwright-core/src/tools/mcp/extensionContextFactory.ts+++ b/packages/playwright-core/src/tools/mcp/extensionContextFactory.ts@@ -39,7 +39,7 @@ export async function createExtensionBrowser(channel: string, executablePath: sttry {await relay.establishExtensionConnection(clientName);- const browser = await playwright.chromium.connectOverCDP(relay.cdpEndpoint(), { isLocal: true, timeout: 0 });+ const browser = await playwright.chromium.connectOverCDP(relay.cdpEndpoint(), { isLocal: true, timeout: 0, noDefaults: true });browser.on('disconnected', () => relay.stop());return browser;} catch (error) {diff --git a/tests/extension/extension.spec.ts b/tests/extension/extension.spec.tsindex 9945ca5a74..ba6a64a1f6 100644--- a/tests/extension/extension.spec.ts+++ b/tests/extension/extension.spec.ts@@ -173,6 +173,37 @@ test(`snapshot of an existing page`, async ({ browserWithExtension, startClient,});});+test(`extension connection uses noDefaults`, {+ annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/42117' },+}, async ({ browserWithExtension, startClient, server }) => {+ const browserContext = await browserWithExtension.launch();++ const page = await browserContext.newPage();+ await page.goto(server.HELLO_WORLD);+ await page.emulateMedia({ media: 'print' });+ expect(await page.evaluate(() => matchMedia('print').matches)).toBe(true);++ const client = await startWithExtensionFlag(browserWithExtension, startClient);++ const confirmationPagePromise = browserContext.waitForEvent('page', page => {+ return page.url().startsWith(`chrome-extension://${extensionId}/connect.html`);+ });++ const snapshotResponse = client.callTool({+ name: 'browser_snapshot',+ arguments: { },+ });++ const selectorPage = await confirmationPagePromise;+ await clickAllowAndSelect(selectorPage, 'Title');++ expect(await snapshotResponse).toHaveResponse({+ inlineSnapshot: expect.stringContaining(`Hello, world!`),+ });++ expect(await page.evaluate(() => matchMedia('print').matches)).toBe(true);+});+testWithOldExtensionVersion(`works with old extension version`, async ({ startExtensionClient, server }) => {// Prelaunch the browser, so that it is properly closed after the test.const { browserContext, client } = await startExtensionClient();