From 30b3d49b0de46d812b7485e708174a07c73dbdd0 Mon Sep 17 00:00:00 2001 From: omjadas Date: Tue, 15 Feb 2022 21:16:49 +1100 Subject: [PATCH] feat(HTTPResponse): expose timing information (#8025) --- docs/api.md | 25 +++++++++++++++++++++++++ src/common/HTTPResponse.ts | 9 +++++++++ test/network.spec.ts | 11 +++++++++++ 3 files changed, 45 insertions(+) diff --git a/docs/api.md b/docs/api.md index 8770ffd4..d337fdeb 100644 --- a/docs/api.md +++ b/docs/api.md @@ -375,6 +375,7 @@ * [httpResponse.status()](#httpresponsestatus) * [httpResponse.statusText()](#httpresponsestatustext) * [httpResponse.text()](#httpresponsetext) + * [httpResponse.timing()](#httpresponsetiming) * [httpResponse.url()](#httpresponseurl) - [class: SecurityDetails](#class-securitydetails) * [securityDetails.issuer()](#securitydetailsissuer) @@ -5231,6 +5232,30 @@ Contains the status text of the response (e.g. usually an "OK" for a success). - returns: <[Promise]<[string]>> Promise which resolves to a text representation of response body. +#### httpResponse.timing() + +- returns: + - `requestTime` <[number]> baseline in seconds + - `proxyStart` <[number]> started resolving proxy (milliseconds since requestTime) + - `proxyEnd` <[number]> finished resolving proxy (milliseconds since requestTime) + - `dnsStart` <[number]> started DNS address resolve (milliseconds since requestTime) + - `dnsEnd` <[number]> finished DNS address resolve (milliseconds since requestTime) + - `connectStart` <[number]> started connecting to the remote host (milliseconds since requestTime) + - `connectEnd` <[number]> connected to the remote host (milliseconds since requestTime) + - `sslStart` <[number]> started SSL handshake (milliseconds since requestTime) + - `sslEnd` <[number]> finished SSL handshake (milliseconds since requestTime) + - `workerStart` <[number]> started running ServiceWorker (milliseconds since requestTime) + - `workerReady` <[number]> finished Starting ServiceWorker (milliseconds since requestTime) + - `workerFetchStart` <[number]> started fetch event (milliseconds since requestTime) + - `workerRespondWithSettled` <[number]> settled fetch event respondWith promise (milliseconds since requestTime) + - `sendStart` <[number]> started sending request (milliseconds since requestTime) + - `sendEnd` <[number]> finished sending request (milliseconds since requestTime) + - `pushStart` <[number]> time the server started pushing request (milliseconds since requestTime) + - `pushEnd` <[number]> time the server finished pushing request (milliseconds since requestTime) + - `receiveHeadersEnd` <[number]> finished receiving response headers (milliseconds since requestTime) + +Timing information related to the response. + #### httpResponse.url() - returns: <[string]> diff --git a/src/common/HTTPResponse.ts b/src/common/HTTPResponse.ts index f1e22581..b528ac08 100644 --- a/src/common/HTTPResponse.ts +++ b/src/common/HTTPResponse.ts @@ -57,6 +57,7 @@ export class HTTPResponse { private _fromServiceWorker: boolean; private _headers: Record = {}; private _securityDetails: SecurityDetails | null; + private _timing: Protocol.Network.ResourceTiming | null; /** * @internal @@ -93,6 +94,7 @@ export class HTTPResponse { this._securityDetails = responsePayload.securityDetails ? new SecurityDetails(responsePayload.securityDetails) : null; + this._timing = responsePayload.timing; } /** @@ -172,6 +174,13 @@ export class HTTPResponse { return this._securityDetails; } + /** + * @returns Timing information related to the response. + */ + timing(): Protocol.Network.ResourceTiming | null { + return this._timing; + } + /** * @returns Promise which resolves to a buffer with response body. */ diff --git a/test/network.spec.ts b/test/network.spec.ts index 4e098b19..d86102f0 100644 --- a/test/network.spec.ts +++ b/test/network.spec.ts @@ -430,6 +430,17 @@ describe('network', function () { }); }); + describeFailsFirefox('Response.timing', function () { + it('returns timing information', async () => { + const { page, server } = getTestState(); + const responses = []; + page.on('response', (response) => responses.push(response)); + await page.goto(server.EMPTY_PAGE); + expect(responses.length).toBe(1); + expect(responses[0].timing().receiveHeadersEnd).toBeGreaterThan(0); + }); + }); + describeFailsFirefox('Network Events', function () { it('Page.Events.Request', async () => { const { page, server } = getTestState();