Version: 1.8.0
Route
Whenever a network route is set up with page.route(url, handler) or browserContext.route(url, handler), the Route
object allows to handle the route.
#
route.abort([errorCode])errorCode
<string> Optional error code. Defaults tofailed
, could be one of the following:'aborted'
- An operation was aborted (due to user action)'accessdenied'
- Permission to access a resource, other than the network, was denied'addressunreachable'
- The IP address is unreachable. This usually means that there is no route to the specified host or network.'blockedbyclient'
- The client chose to block the request.'blockedbyresponse'
- The request failed because the response was delivered along with requirements which are not met ('X-Frame-Options' and 'Content-Security-Policy' ancestor checks, for instance).'connectionaborted'
- A connection timed out as a result of not receiving an ACK for data sent.'connectionclosed'
- A connection was closed (corresponding to a TCP FIN).'connectionfailed'
- A connection attempt failed.'connectionrefused'
- A connection attempt was refused.'connectionreset'
- A connection was reset (corresponding to a TCP RST).'internetdisconnected'
- The Internet connection has been lost.'namenotresolved'
- The host name could not be resolved.'timedout'
- An operation timed out.'failed'
- A generic failure occurred.
Aborts the route's request.
#
route.continue([options])options
<Object>headers
<Object<string, string>> If set changes the request HTTP headers. Header values will be converted to a string.method
<string> If set changes the request method (e.g. GET or POST)postData
<string|Buffer> If set changes the post data of requesturl
<string> If set changes the request URL. New URL must have same protocol as original one.
Continues route's request with optional overrides.
#
route.fulfill([options])options
<Object>body
<string|Buffer> Response body.contentType
<string> If set, equals to settingContent-Type
response header.headers
<Object<string, string>> Response headers. Header values will be converted to a string.path
<string> File path to respond with. The content type will be inferred from file extension. Ifpath
is a relative path, then it is resolved relative to the current working directory.status
<number> Response status code, defaults to200
.
Fulfills route's request with given response.
An example of fulfilling all requests with 404 responses:
An example of serving static file:
#
route.request()- returns: <Request>
A request to be routed.