Skip to content

Commit 8534271

Browse files
authored
test(webkit): no pageerror for a caught fetch during pending navigation (#44090)
1 parent 622b3db commit 8534271

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

‎tests/page/page-event-pageerror.spec.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
import { test as it, expect } from './pageTest';
19+
import type { ServerResponse } from 'http';
1920

2021
it('ER-001 should fire', {
2122
annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/43450' },
@@ -284,3 +285,31 @@ it('ER-013 should fire illegal character error', {
284285
else
285286
expect(error.message).toContain('illegal character');
286287
});
288+
289+
it('ER-022 should not fire for a caught fetch rejected by a pending navigation', {
290+
annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/44015' },
291+
}, async ({ page, server }) => {
292+
await page.goto(server.EMPTY_PAGE);
293+
const errors: string[] = [];
294+
page.on('pageerror', error => errors.push(error.message));
295+
const waitResponse = new Promise<ServerResponse>(resolve => server.setRoute('/wait', (req, res) => resolve(res)));
296+
const replacementResponse = new Promise<ServerResponse>(resolve => server.setRoute('/replacement', (req, res) => resolve(res)));
297+
const fetchDone = page.waitForEvent('console', message => message.text() === 'fetch done');
298+
// Chromium does not run evaluate during a pending navigation, so the page starts the second fetch.
299+
await page.evaluate(() => {
300+
void fetch('/wait').catch(() => {}).then(() => fetch('/empty.html')).catch(() => {}).then(() => console.log('fetch done'));
301+
});
302+
const navigation = page.goto(server.PREFIX + '/replacement');
303+
const response = await replacementResponse;
304+
// WebKit rejects the second fetch, because the document is about to go away.
305+
(await waitResponse).end();
306+
await fetchDone;
307+
response.end('replacement');
308+
await navigation;
309+
const [error] = await Promise.all([
310+
page.waitForEvent('pageerror'),
311+
page.evaluate(() => setTimeout(() => { throw new Error('genuine error'); }, 0)),
312+
]);
313+
expect(error.message).toBe('genuine error');
314+
expect(errors).toEqual(['genuine error']);
315+
});

‎tests/registry.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2064,6 +2064,7 @@ subsystem, add a row to the Subsystems table. Then update this file:
20642064
| `ER-019` | `library/page-event-crash.spec.ts` | should be able to close context when page crashes |
20652065
| `ER-020` | `library/page-event-crash.spec.ts` | should be able to close page after crash |
20662066
| `ER-021` | `library/page-event-crash.spec.ts` | should reject in-flight worker.evaluate when page crashes |
2067+
| `ER-022` | `page/page-event-pageerror.spec.ts` | should not fire for a caught fetch rejected by a pending navigation |
20672068

20682069
### ES — Eval on selector
20692070

0 commit comments

Comments
 (0)