Skip to content
Merged
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
16 changes: 7 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,12 @@ 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;
// Keep the size as -1 "not available" when we did not actually read the body.
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 +544,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
3 changes: 2 additions & 1 deletion tests/library/har.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,8 @@ it('should include redirects from API request', async ({ contextFactory, server
const [redirect, json] = log.entries;
expect(redirect.request.url).toBe(server.PREFIX + '/redirect-me');
expect(json.request.url).toBe(server.PREFIX + '/simple.json');

expect(redirect.response.bodySize).toBe(-1);
expect(redirect.response.content.size).toBe(-1);
expect(redirect.timings).toBeDefined();
expect(json.timings).toBeDefined();
});
Expand Down
Loading