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(cli): don't crash the response when navigating closes the last tab (#41675)
Simon Knott1fbd702e7250
diff --git a/packages/playwright-core/src/tools/backend/response.ts b/packages/playwright-core/src/tools/backend/response.tsindex 431d4c28ab..78a2980970 100644--- a/packages/playwright-core/src/tools/backend/response.ts+++ b/packages/playwright-core/src/tools/backend/response.ts@@ -275,7 +275,8 @@ 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.find(h => h.current) ?? tabHeaders[0]));+ if (tabHeaders.length)+ addSection('Page', renderTabMarkdown(tabHeaders.find(h => h.current) ?? tabHeaders[0]));}// Handle modal states.diff --git a/tests/mcp/cli-navigation.spec.ts b/tests/mcp/cli-navigation.spec.tsindex 74f606fadf..3d07790288 100644--- a/tests/mcp/cli-navigation.spec.ts+++ b/tests/mcp/cli-navigation.spec.ts@@ -52,3 +52,10 @@ test('run-code', async ({ cli, server }) => {const { output } = await cli('run-code', '() => page.title()');expect(output).toContain('"Title"');});++test('goto chrome:// page that closes the tab does not crash the response', async ({ cli, server, mcpBrowser }) => {+ test.skip(mcpBrowser !== 'chromium' && mcpBrowser !== 'chrome', 'chrome:// pages are chromium-specific');+ await cli('open', server.HELLO_WORLD);+ const { output } = await cli('goto', 'chrome://extensions/');+ expect(output).toContain('No open tabs. Navigate to a URL to create one.');+});