Whenever the page sends a request, such as for a network resource, the following events are emitted by playwright's page:
'request'emitted when the request is issued by the page.
'response'emitted when/if the response is 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: <?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.)
- returns: <?string> Request's post body, if any.
- returns: <?Object> Parsed request's body for
form-urlencodedand JSON as a fallback if any.
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.
- returns: <?Request> Request that was redirected by the server to this one, if any.
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:
- returns: <?Request> New request issued by the browser if the server responded with redirect.
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<?Response>> A matching Response object, or
nullif the response was not received due to error.
- returns: <string> URL of the request.