Whenever the page sends a request for a network resource the following sequence of events are emitted by Page:
'request'emitted when the request is issued by the page.
'response'emitted when/if the response status and headers are received for the request.
'requestfinished'emitted when the response body is downloaded and the request is complete.
If request fails at some point, then instead of
'requestfinished' event (and possibly instead of 'response' event), the
'requestfailed' event is emitted.
NOTE HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request will complete with
If request gets a 'redirect' response, the request is successfully finished with the 'requestfinished' event, and a new request is issued to a redirected url.
- returns: <null|Object> Object describing request failure, if any
errorText<string> Human-readable error message, e.g.
The method returns
null unless this request has failed, as reported by
Example of logging of all the failed requests:
- returns: <Object<string, string>> An object with HTTP headers associated with the request. All header names are lower-case.
- returns: <boolean>
Whether this request is driving frame's navigation.
- returns: <string> Request's method (GET, POST, etc.)
When the response is
application/x-www-form-urlencoded then a key/value object of the values will be returned. Otherwise it will be parsed as JSON.
When the server responds with a redirect, Playwright creates a new Request object. The two requests are connected by
redirectedTo() methods. When multiple server redirects has happened, it is possible to construct the whole redirect chain by repeatedly calling
For example, if the website
http://example.com redirects to
If the website
https://google.com has no redirects:
This method is the opposite of request.redirectedFrom():
- returns: <string>
Contains the request's resource type as it was perceived by the rendering engine.
ResourceType will be one of the following:
- returns: <Promise<null|Response>> A matching Response object, or
nullif the response was not received due to error.
- returns: <string> URL of the request.