Skip to content

Commit

Permalink
feat(HTTPResponse): expose timing information (#8025)
Browse files Browse the repository at this point in the history
  • Loading branch information
omjadas committed Feb 15, 2022
1 parent 5346e70 commit 30b3d49
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
25 changes: 25 additions & 0 deletions docs/api.md
Expand Up @@ -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)
Expand Down Expand Up @@ -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: <?[Object]>
- `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]>
Expand Down
9 changes: 9 additions & 0 deletions src/common/HTTPResponse.ts
Expand Up @@ -57,6 +57,7 @@ export class HTTPResponse {
private _fromServiceWorker: boolean;
private _headers: Record<string, string> = {};
private _securityDetails: SecurityDetails | null;
private _timing: Protocol.Network.ResourceTiming | null;

/**
* @internal
Expand Down Expand Up @@ -93,6 +94,7 @@ export class HTTPResponse {
this._securityDetails = responsePayload.securityDetails
? new SecurityDetails(responsePayload.securityDetails)
: null;
this._timing = responsePayload.timing;
}

/**
Expand Down Expand Up @@ -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.
*/
Expand Down
11 changes: 11 additions & 0 deletions test/network.spec.ts
Expand Up @@ -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();
Expand Down

0 comments on commit 30b3d49

Please sign in to comment.