From 9623857d155b973f909acdccede7d0c75da27dcb Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Wed, 23 Sep 2026 19:51:52 +0100 Subject: [PATCH] test(mcp): work around Chromium losing WebMCP tools in same-origin iframes Fixes: https://github.com/microsoft/playwright/issues/42869 --- tests/mcp/cli-webmcp.spec.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/mcp/cli-webmcp.spec.ts b/tests/mcp/cli-webmcp.spec.ts index 3b447626ce8d5..70e55813b5d5b 100644 --- a/tests/mcp/cli-webmcp.spec.ts +++ b/tests/mcp/cli-webmcp.spec.ts @@ -49,6 +49,12 @@ function serveMain(server: any, body: string) { }); } +// Reloading the frame once replaces the initial blank page's window in Chromium +// and works around the bug where tools do not register. +function iframe(src: string) { + return ``; +} + test('webmcp-list and webmcp-call', async ({ cli, server, mcpBrowser }, testInfo) => { await writeWebMCPConfig(mcpBrowser, testInfo); serveMain(server, ``); + serveMain(server, `${iframe('/frame.html')}`); server.setRoute('/frame.html', (req: any, res: any) => { res.writeHead(200, { 'Content-Type': 'text/html' }); res.end(``); + serveMain(server, `${iframe('/frame.html')}`); server.setRoute('/frame.html', (req: any, res: any) => { res.writeHead(200, { 'Content-Type': 'text/html' }); res.end(``); @@ -191,7 +197,7 @@ test('webmcp-call disambiguates same-name tools in identical same-origin frames' // Two iframes of the very same URL each own a tool called "echo", so the frame URL alone // cannot address them and the listing falls back to the frame position. - serveMain(server, ``); + serveMain(server, `${iframe('/widget.html')}${iframe('/widget.html')}`); server.setRoute('/widget.html', (req: any, res: any) => { res.writeHead(200, { 'Content-Type': 'text/html' }); res.end(`