Skip to content

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

chore(download): make chromium throw same error as others (#37082)

Simon Knottb457aefe736b
diff --git a/packages/playwright-core/src/server/chromium/crPage.ts b/packages/playwright-core/src/server/chromium/crPage.ts
index 34e9e892d2..c019cac28b 100644
--- a/packages/playwright-core/src/server/chromium/crPage.ts
+++ b/packages/playwright-core/src/server/chromium/crPage.ts
@@ -577,6 +577,8 @@ class FrameSession {
async _navigate(frame: frames.Frame, url: string, referrer: string | undefined): Promise<frames.GotoResult> {
const response = await this._client.send('Page.navigate', { url, referrer, frameId: frame._id, referrerPolicy: 'unsafeUrl' });
+ if (response.isDownload)
+ throw new frames.NavigationAbortedError(response.loaderId, 'Download is starting');
if (response.errorText)
throw new frames.NavigationAbortedError(response.loaderId, `${response.errorText} at ${url}`);
return { newDocumentId: response.loaderId };
diff --git a/tests/library/download.spec.ts b/tests/library/download.spec.ts
index 4ae222a47f..0c9572febe 100644
--- a/tests/library/download.spec.ts
+++ b/tests/library/download.spec.ts
@@ -51,7 +51,8 @@ it.describe('download event', () => {
});
});
- it('should report download when navigation turns into download @smoke', async ({ browser, server, browserName, mode }) => {
+ it('should report download when navigation turns into download @smoke', async ({ browser, server, browserName, browserMajorVersion }) => {
+ it.skip(browserName === 'chromium' && browserMajorVersion < 140, 'old chromium throws net::ERR_ABORTED, depends on https://chromium-review.googlesource.com/c/chromium/src/+/6696011');
const page = await browser.newPage();
const [download, responseOrError] = await Promise.all([
page.waitForEvent('download'),
@@ -62,22 +63,17 @@ it.describe('download event', () => {
const path = await download.path();
expect(fs.existsSync(path)).toBeTruthy();
expect(fs.readFileSync(path).toString()).toBe('Hello world');
- if (browserName === 'chromium') {
- expect(responseOrError instanceof Error).toBeTruthy();
- expect(responseOrError.message).toContain('net::ERR_ABORTED');
- expect(page.url()).toBe('about:blank');
- } else if (browserName === 'webkit') {
- expect(responseOrError instanceof Error).toBeTruthy();
- expect(responseOrError.message).toContain('Download is starting');
+
+ expect(responseOrError instanceof Error).toBeTruthy();
+ expect(responseOrError.message).toContain('Download is starting');
+
+ if (browserName !== 'firefox')
expect(page.url()).toBe('about:blank');
- } else {
- expect(responseOrError instanceof Error).toBeTruthy();
- expect(responseOrError.message).toContain('Download is starting');
- }
await page.close();
});
- it('should work with Cross-Origin-Opener-Policy', async ({ browser, server, browserName }) => {
+ it('should work with Cross-Origin-Opener-Policy', async ({ browser, server, browserName, browserMajorVersion }) => {
+ it.skip(browserName === 'chromium' && browserMajorVersion < 140, 'old chromium throws net::ERR_ABORTED, depends on https://chromium-review.googlesource.com/c/chromium/src/+/6696011');
const page = await browser.newPage();
const [download, responseOrError] = await Promise.all([
page.waitForEvent('download'),
@@ -88,18 +84,10 @@ it.describe('download event', () => {
const path = await download.path();
expect(fs.existsSync(path)).toBeTruthy();
expect(fs.readFileSync(path).toString()).toBe('Hello world');
- if (browserName === 'chromium') {
- expect(responseOrError instanceof Error).toBeTruthy();
- expect(responseOrError.message).toContain('net::ERR_ABORTED');
- expect(page.url()).toBe('about:blank');
- } else if (browserName === 'webkit') {
- expect(responseOrError instanceof Error).toBeTruthy();
- expect(responseOrError.message).toContain('Download is starting');
+ expect(responseOrError instanceof Error).toBeTruthy();
+ expect(responseOrError.message).toContain('Download is starting');
+ if (browserName !== 'firefox')
expect(page.url()).toBe('about:blank');
- } else {
- expect(responseOrError instanceof Error).toBeTruthy();
- expect(responseOrError.message).toContain('Download is starting');
- }
await page.close();
});