fix(har tracing): record `response.bodySize` for API requests (#32656)

A small drive-by that came out of working on
https://github.com/microsoft/playwright/issues/32653.
This commit is contained in:
Simon Knott 2024-09-18 08:21:10 +02:00 committed by GitHub
parent 8a97050822
commit 4460c98710
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 0 deletions

View File

@ -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);

View File

@ -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, serv
expect(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) => {