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(har tracing): record `response.bodySize` for API requests (#32656)
Simon Knott4460c987103f
diff --git a/packages/playwright-core/src/server/har/harTracer.ts b/packages/playwright-core/src/server/har/harTracer.tsindex 197b640086..448e511242 100644--- a/packages/playwright-core/src/server/har/harTracer.ts+++ b/packages/playwright-core/src/server/har/harTracer.ts@@ -239,6 +239,8 @@ export class HarTracer {if (contentType)content.mimeType = contentType;this._storeResponseContent(event.body, content, 'other');+ if (!this._options.omitSizes)+ harEntry.response.bodySize = event.body?.length ?? 0;if (this._started)this._delegate.onEntryFinished(harEntry);diff --git a/tests/library/har.spec.ts b/tests/library/har.spec.tsindex f46854d049..021d79ff4c 100644--- a/tests/library/har.spec.ts+++ b/tests/library/har.spec.ts@@ -823,6 +823,7 @@ it('should include API request', async ({ contextFactory, server }, testInfo) =>expect(entry.response.headers.find(h => h.name.toLowerCase() === 'content-type')?.value).toContain('application/json');expect(entry.response.content.size).toBe(15);expect(entry.response.content.text).toBe(responseBody.toString());+ expect(entry.response.bodySize).toBe(15);expect(entry.time).toBeGreaterThan(0);expect(entry.timings).toEqual(expect.objectContaining({@@ -849,6 +850,7 @@ it('should respect minimal mode for API Requests', async ({ contextFactory, servexpect(entry.timings).toEqual({ receive: -1, send: -1, wait: -1 });expect(entry.request.cookies).toEqual([]);expect(entry.request.bodySize).toBe(-1);+ expect(entry.response.bodySize).toBe(-1);});it('should include redirects from API request', async ({ contextFactory, server }, testInfo) => {