Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions packages/playwright-core/src/server/har/harTracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,13 @@ export class HarTracer {
const contentType = event.headers['content-type'];
if (contentType)
content.mimeType = contentType;
this._storeResponseContent(event.body, content, 'other');
if (!this._options.omitSizes)
harEntry.response.bodySize = event.body?.length ?? 0;
// Redirect and auth-retry hops are destroyed before their body is read, so the
// sizes stay at the -1 "not available" sentinel instead of claiming zero bytes.
if (event.body) {
this._storeResponseContent(event.body, content, 'other');
if (!this._options.omitSizes)
harEntry.response.bodySize = event.body.length;
}

if (this._started)
this._delegate.onEntryFinished(harEntry);
Expand Down Expand Up @@ -541,12 +545,7 @@ export class HarTracer {
this._delegate.onEntryStarted(harEntry);
}

private _storeResponseContent(buffer: Buffer | undefined, content: har.Content, resourceType: string) {
if (!buffer) {
content.size = 0;
return;
}

private _storeResponseContent(buffer: Buffer, content: har.Content, resourceType: string) {
if (!this._options.omitSizes)
content.size = buffer.length;

Expand Down
4 changes: 4 additions & 0 deletions tests/library/har.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,10 @@ it('should include redirects from API request', async ({ contextFactory, server

expect(redirect.timings).toBeDefined();
expect(json.timings).toBeDefined();

// The redirect body is never read, so its sizes stay unknown rather than claiming zero.
expect(redirect.response.bodySize).toBe(-1);
expect(redirect.response.content.size).toBe(-1);
});

it('should not hang on resources served from cache', async ({ contextFactory, server, browserName, isBidi }, testInfo) => {
Expand Down
Loading