mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(har): recalculate receive time after response ended (#19646)
Fixes https://github.com/microsoft/playwright/issues/19327
This commit is contained in:
parent
fe989d95eb
commit
8b80e22a03
@ -332,6 +332,11 @@ export class HarTracer {
|
|||||||
});
|
});
|
||||||
this._addBarrier(page || request.serviceWorker(), promise);
|
this._addBarrier(page || request.serviceWorker(), promise);
|
||||||
|
|
||||||
|
// Respose end timing is only available after the response event was received.
|
||||||
|
const timing = response.timing();
|
||||||
|
harEntry.timings.receive = response.request()._responseEndTiming !== -1 ? helper.millisToRoundishMillis(response.request()._responseEndTiming - timing.responseStart) : -1;
|
||||||
|
this._computeHarEntryTotalTime(harEntry);
|
||||||
|
|
||||||
if (!this._options.omitSizes) {
|
if (!this._options.omitSizes) {
|
||||||
this._addBarrier(page || request.serviceWorker(), response.sizes().then(sizes => {
|
this._addBarrier(page || request.serviceWorker(), response.sizes().then(sizes => {
|
||||||
harEntry.response.bodySize = sizes.responseBodySize;
|
harEntry.response.bodySize = sizes.responseBodySize;
|
||||||
@ -417,7 +422,7 @@ export class HarTracer {
|
|||||||
const connect = timing.connectEnd !== -1 ? helper.millisToRoundishMillis(timing.connectEnd - timing.connectStart) : -1;
|
const connect = timing.connectEnd !== -1 ? helper.millisToRoundishMillis(timing.connectEnd - timing.connectStart) : -1;
|
||||||
const ssl = timing.connectEnd !== -1 ? helper.millisToRoundishMillis(timing.connectEnd - timing.secureConnectionStart) : -1;
|
const ssl = timing.connectEnd !== -1 ? helper.millisToRoundishMillis(timing.connectEnd - timing.secureConnectionStart) : -1;
|
||||||
const wait = timing.responseStart !== -1 ? helper.millisToRoundishMillis(timing.responseStart - timing.requestStart) : -1;
|
const wait = timing.responseStart !== -1 ? helper.millisToRoundishMillis(timing.responseStart - timing.requestStart) : -1;
|
||||||
const receive = response.request()._responseEndTiming !== -1 ? helper.millisToRoundishMillis(response.request()._responseEndTiming - timing.responseStart) : -1;
|
const receive = -1;
|
||||||
|
|
||||||
harEntry.timings = {
|
harEntry.timings = {
|
||||||
dns,
|
dns,
|
||||||
@ -427,7 +432,7 @@ export class HarTracer {
|
|||||||
wait,
|
wait,
|
||||||
receive,
|
receive,
|
||||||
};
|
};
|
||||||
harEntry.time = [dns, connect, ssl, wait, receive].reduce((pre, cur) => cur > 0 ? cur + pre : pre, 0);
|
this._computeHarEntryTotalTime(harEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this._options.omitServerIP) {
|
if (!this._options.omitServerIP) {
|
||||||
@ -460,6 +465,16 @@ export class HarTracer {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _computeHarEntryTotalTime(harEntry: har.Entry) {
|
||||||
|
harEntry.time = [
|
||||||
|
harEntry.timings.dns,
|
||||||
|
harEntry.timings.connect,
|
||||||
|
harEntry.timings.ssl,
|
||||||
|
harEntry.timings.wait,
|
||||||
|
harEntry.timings.receive
|
||||||
|
].reduce((pre, cur) => (cur || -1) > 0 ? cur! + pre! : pre, 0)!;
|
||||||
|
}
|
||||||
|
|
||||||
async flush() {
|
async flush() {
|
||||||
await Promise.all(this._barrierPromises);
|
await Promise.all(this._barrierPromises);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -421,6 +421,13 @@ it('should calculate time', async ({ contextFactory, server }, testInfo) => {
|
|||||||
expect(log.entries[0].time).toBeGreaterThan(0);
|
expect(log.entries[0].time).toBeGreaterThan(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should return receive time', async ({ contextFactory, server }, testInfo) => {
|
||||||
|
const { page, getLog } = await pageWithHar(contextFactory, testInfo);
|
||||||
|
await page.goto(server.PREFIX + '/har.html');
|
||||||
|
const log = await getLog();
|
||||||
|
expect(log.entries[0].timings.receive).toBeGreaterThan(0);
|
||||||
|
});
|
||||||
|
|
||||||
it('should report the correct _transferSize with PNG files', async ({ contextFactory, server, asset }, testInfo) => {
|
it('should report the correct _transferSize with PNG files', async ({ contextFactory, server, asset }, testInfo) => {
|
||||||
const { page, getLog } = await pageWithHar(contextFactory, testInfo);
|
const { page, getLog } = await pageWithHar(contextFactory, testInfo);
|
||||||
await page.goto(server.EMPTY_PAGE);
|
await page.goto(server.EMPTY_PAGE);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user