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(fetch): correctly return empty response body (#9371)
Yury Semikhatskyfb001f608f4a
diff --git a/src/client/fetch.ts b/src/client/fetch.tsindex eb9b6c2be9..0a702191da 100644--- a/src/client/fetch.ts+++ b/src/client/fetch.ts@@ -218,7 +218,7 @@ export class FetchResponse implements api.ApiResponse {return this._request._wrapApiCall(async (channel: channels.FetchRequestChannel) => {try {const result = await channel.fetchResponseBody({ fetchUid: this._fetchUid() });- if (!result.binary)+ if (result.binary === undefined)throw new Error('Response has been disposed');return Buffer.from(result.binary!, 'base64');} catch (e) {diff --git a/tests/global-fetch.spec.ts b/tests/global-fetch.spec.tsindex 6df9c61e43..b10f1f5518 100644--- a/tests/global-fetch.spec.ts+++ b/tests/global-fetch.spec.ts@@ -158,3 +158,14 @@ it('should be able to construct with context options', async ({ playwright, servconst response = await request.get(server.EMPTY_PAGE);expect(response.ok()).toBeTruthy();});++it('should return empty body', async ({ playwright, server }) => {+ const request = await playwright.request.newContext();+ const response = await request.get(server.EMPTY_PAGE);+ const body = await response.body();+ expect(body.length).toBe(0);+ expect(await response.text()).toBe('');+ await request.dispose();+ const error = await response.body().catch(e => e);+ expect(error.message).toContain('Response has been disposed');+});