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): identify downloads explicitly (#41933)

Simon Knott15c4f55879e4
diff --git a/packages/playwright-core/src/tools/backend/tab.ts b/packages/playwright-core/src/tools/backend/tab.ts
index 441f8a9f75..d696b157ca 100644
--- a/packages/playwright-core/src/tools/backend/tab.ts
+++ b/packages/playwright-core/src/tools/backend/tab.ts
@@ -338,12 +338,10 @@ export class Tab extends EventEmitter<TabEventsInterface> {
abortDownloadEvent();
} catch (_e: unknown) {
const e = _e as Error;
- const mightBeDownload =
- e.message.includes('net::ERR_ABORTED') // chromium
- || e.message.includes('Download is starting'); // firefox + webkit
- if (!mightBeDownload)
+ if (!e.message.includes('Download is starting')) {
+ abortDownloadEvent();
throw e;
- // on chromium, the download event is fired *after* page.goto rejects, so we wait a lil bit
+ }
const download = await downloadEvent;
if (!download)
throw e;
diff --git a/tests/mcp/crash.spec.ts b/tests/mcp/crash.spec.ts
index 51fb603984..55eb486bd1 100644
--- a/tests/mcp/crash.spec.ts
+++ b/tests/mcp/crash.spec.ts
@@ -28,19 +28,24 @@ test.describe('crash recovery', () => {
});
});
- test('resets to about:blank and logs the crash', async ({ client, server }) => {
- await client.callTool({
+ test('reports the navigation error, then resets and logs the crash', async ({ client, server }) => {
+ expect(await client.callTool({
name: 'browser_navigate',
arguments: { url: 'chrome://crash' },
+ })).toHaveResponse({
+ error: expect.stringContaining('net::ERR_ABORTED'),
+ isError: true,
});
- const response = parseResponse(await client.callTool({
- name: 'browser_snapshot',
- }));
- expect(response.page).toBe('- Page URL: about:blank');
+ await expect(async () => {
+ const response = parseResponse(await client.callTool({
+ name: 'browser_snapshot',
+ }));
+ expect(response.page).toBe('- Page URL: about:blank');
- const log = await consoleEntries(response);
- expect(log).toContain('Page crashed and was reset to about:blank.');
+ const log = await consoleEntries(response);
+ expect(log).toContain('Page crashed and was reset to about:blank.');
+ }).toPass();
expect(await client.callTool({
name: 'browser_navigate',
@@ -52,8 +57,15 @@ test.describe('crash recovery', () => {
test('lists only one tab', async ({ client }) => {
await client.callTool({
- name: 'browser_navigate',
- arguments: { url: 'chrome://crash' },
+ name: 'browser_run_code_unsafe',
+ arguments: {
+ code: `async page => {
+ await Promise.all([
+ page.waitForEvent('crash'),
+ page.goto('chrome://crash').catch(() => {}),
+ ]);
+ }`,
+ },
});
expect(await client.callTool({
@@ -66,12 +78,16 @@ test.describe('crash recovery', () => {
test('marks non-current crashed tab in the tab list', async ({ client, server }) => {
await client.callTool({
- name: 'browser_tabs',
- arguments: { action: 'new', url: 'chrome://crash' },
- });
- await client.callTool({
- name: 'browser_tabs',
- arguments: { action: 'select', index: 0 },
+ name: 'browser_run_code_unsafe',
+ arguments: {
+ code: `async page => {
+ const otherPage = await page.context().newPage();
+ await Promise.all([
+ otherPage.waitForEvent('crash'),
+ otherPage.goto('chrome://crash').catch(() => {}),
+ ]);
+ }`,
+ },
});
expect(await client.callTool({