Skip to content

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

chore: ensure progress runs with a timeout in fetch() (#36192)

Dmitry Gozmana0eb89188005
diff --git a/packages/playwright-core/src/server/fetch.ts b/packages/playwright-core/src/server/fetch.ts
index 53b0d9a11d..6d0d2281fc 100644
--- a/packages/playwright-core/src/server/fetch.ts
+++ b/packages/playwright-core/src/server/fetch.ts
@@ -208,7 +208,7 @@ export abstract class APIRequestContext extends SdkObject {
const controller = new ProgressController(metadata, this);
const fetchResponse = await controller.run(progress => {
return this._sendRequestWithRetries(progress, requestUrl, options, postData, params.maxRetries);
- });
+ }, timeout);
const fetchUid = this._storeResponseBody(fetchResponse.body);
this.fetchLog.set(fetchUid, controller.metadata.log);
const failOnStatusCode = params.failOnStatusCode !== undefined ? params.failOnStatusCode : !!defaults.failOnStatusCode;
diff --git a/tests/library/browsercontext-fetch.spec.ts b/tests/library/browsercontext-fetch.spec.ts
index fa6f01edc4..23beb0d186 100644
--- a/tests/library/browsercontext-fetch.spec.ts
+++ b/tests/library/browsercontext-fetch.spec.ts
@@ -877,7 +877,7 @@ it('should support timeout option', async function({ context, server }) {
});
const error = await context.request.get(server.PREFIX + '/slow', { timeout: 10 }).catch(e => e);
- expect(error.message).toContain(`Request timed out after 10ms`);
+ expect(error.message).toContain(`apiRequestContext.get: Timeout 10ms exceeded`);
});
it('should support a timeout of 0', async function({ context, server }) {
@@ -908,7 +908,7 @@ it('should respect timeout after redirects', async function({ context, server })
context.setDefaultTimeout(100);
const error = await context.request.get(server.PREFIX + '/redirect').catch(e => e);
- expect(error.message).toContain(`Request timed out after 100ms`);
+ expect(error.message).toContain(`apiRequestContext.get: Timeout 100ms exceeded`);
});
it('should not hang on a brotli encoded Range request', async ({ context, server, nodeVersion }) => {
diff --git a/tests/library/global-fetch.spec.ts b/tests/library/global-fetch.spec.ts
index 95b0555db3..2bece94e45 100644
--- a/tests/library/global-fetch.spec.ts
+++ b/tests/library/global-fetch.spec.ts
@@ -70,7 +70,7 @@ it('should support global timeout option', async ({ playwright, server }) => {
const request = await playwright.request.newContext({ timeout: 100 });
server.setRoute('/empty.html', (req, res) => {});
const error = await request.get(server.EMPTY_PAGE).catch(e => e);
- expect(error.message).toContain('Request timed out after 100ms');
+ expect(error.message).toContain('apiRequestContext.get: Timeout 100ms exceeded');
await request.dispose();
});
diff --git a/tests/page/page-request-intercept.spec.ts b/tests/page/page-request-intercept.spec.ts
index 0b299ca91b..3ea6655566 100644
--- a/tests/page/page-request-intercept.spec.ts
+++ b/tests/page/page-request-intercept.spec.ts
@@ -218,7 +218,7 @@ it('should support timeout option in route.fetch', async ({ page, server, isElec
});
await page.route('**/*', async route => {
const error = await route.fetch({ timeout: 1000 }).catch(e => e);
- expect(error.message).toContain(`Request timed out after 1000ms`);
+ expect(error.message).toContain(`route.fetch: Timeout 1000ms exceeded`);
});
const error = await page.goto(server.PREFIX + '/slow', { timeout: 2000 }).catch(e => e);
expect(error.message).toContain(`Timeout 2000ms exceeded`);
diff --git a/tests/playwright-test/playwright.spec.ts b/tests/playwright-test/playwright.spec.ts
index 520fcfb7f1..51ec450d19 100644
--- a/tests/playwright-test/playwright.spec.ts
+++ b/tests/playwright-test/playwright.spec.ts
@@ -760,15 +760,15 @@ test('should use actionTimeout for APIRequestContext', async ({ runInlineTest, s
'a.test.ts': `
import { test, expect } from '@playwright/test';
test('default APIRequestContext fixture', async ({ request }) => {
- await expect(request.get('/stall')).rejects.toThrow('apiRequestContext.get: Request timed out after 1111ms');
+ await expect(request.get('/stall')).rejects.toThrow('apiRequestContext.get: Timeout 1111ms exceeded');
});
test('newly created APIRequestContext without options', async ({ playwright }) => {
const apiRequestContext = await playwright.request.newContext();
- await expect(apiRequestContext.get('/stall')).rejects.toThrow('apiRequestContext.get: Request timed out after 1111ms');
+ await expect(apiRequestContext.get('/stall')).rejects.toThrow('apiRequestContext.get: Timeout 1111ms exceeded');
});
test('newly created APIRequestContext with options', async ({ playwright }) => {
const apiRequestContextWithOptions = await playwright.request.newContext({ httpCredentials: { username: 'user', password: 'pass' } });
- await expect(apiRequestContextWithOptions.get('/stall')).rejects.toThrow('apiRequestContext.get: Request timed out after 1111ms');
+ await expect(apiRequestContextWithOptions.get('/stall')).rejects.toThrow('apiRequestContext.get: Timeout 1111ms exceeded');
});
`,
}, { workers: 1 });