Skip to content

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

chore: tab header fix (#39281)

Pavel Feldmanc4a8008e474a
diff --git a/packages/playwright/src/mcp/browser/response.ts b/packages/playwright/src/mcp/browser/response.ts
index 19cc3e3755..9ede782e3d 100644
--- a/packages/playwright/src/mcp/browser/response.ts
+++ b/packages/playwright/src/mcp/browser/response.ts
@@ -190,7 +190,7 @@ export class Response {
if (this._includeSnapshot !== 'none' || tabHeaders.some(header => header.changed)) {
if (tabHeaders.length !== 1)
addSection('Open tabs', renderTabsMarkdown(tabHeaders));
- addSection('Page', renderTabMarkdown(tabHeaders[0]));
+ addSection('Page', renderTabMarkdown(tabHeaders.find(h => h.current) ?? tabHeaders[0]));
}
// Handle modal states.
diff --git a/tests/mcp/tabs.spec.ts b/tests/mcp/tabs.spec.ts
index cf10d0dca8..69e386d91b 100644
--- a/tests/mcp/tabs.spec.ts
+++ b/tests/mcp/tabs.spec.ts
@@ -74,6 +74,12 @@ test('create new tab', async ({ client }) => {
- generic [active] [ref=e1]: Body two
\`\`\``,
});
+ expect(await client.callTool({
+ name: 'browser_snapshot',
+ arguments: {},
+ })).toHaveResponse({
+ page: expect.stringContaining('Page URL: data:text/html,<title>Tab two</title><body>Body two</body>'),
+ });
});
test('select tab', async ({ client }) => {