Skip to main content
The Route class represents a route handler that can intercept, modify, or mock network requests. Routes are created using page.route() or context.route().

Methods

request

Returns the request associated with this route.
Returns: Request

abort

Aborts the request.
string
Optional error code. Defaults to ‘failed’.Possible values: aborted, accessdenied, addressunreachable, blockedbyclient, blockedbyresponse, connectionaborted, connectionclosed, connectionfailed, connectionrefused, connectionreset, internetdisconnected, namenotresolved, timedout, failed

fulfill

Fulfills the request with a custom response.
number
Response status code. Defaults to 200.
Object
Response headers. Header values must be strings.
string
Response content type. If not set, will be inferred from body.
string | Buffer
Response body.
any
JSON response body. Mutually exclusive with body.
string
File path to read response body from.
APIResponse
APIResponse to fulfill with. Status and headers will be copied from the response.

continue

Continues the request with optional modifications.
string
Override request URL.
string
Override request method (GET, POST, etc.).
Object
Override request headers.
string | Buffer | object
Override request post data.

fallback

Falls back to the next route handler or default behavior.
string
Override request URL.
string
Override request method.
Object
Override request headers.
string | Buffer | object
Override request post data.

fetch

Fetches the original request and returns the response.
string
Override request URL.
string
Override request method.
Object
Override request headers.
string | Buffer | object
Override request post data.
number
Maximum number of redirects to follow. Defaults to 20.
number
Maximum number of retries. Defaults to 0.
number
Request timeout in milliseconds.
Returns: Promise<APIResponse>

Example Usage

Mock API Response

Block Images

Modify Request Headers

Modify Response

Conditional Routing