feat(HTTPResponse): expose timing information (#8025)

This commit is contained in:
omjadas 2022-02-15 21:16:49 +11:00 committed by GitHub
parent 5346e70ffc
commit 30b3d49b0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 0 deletions

View File

@ -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: <?[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]>

View File

@ -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
@ -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.
*/

View File

@ -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();