You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/api.md
+106-95
Original file line number
Diff line number
Diff line change
@@ -20,6 +20,7 @@
20
20
-[class: Request](#class-request)
21
21
-[class: Response](#class-response)
22
22
-[class: Selectors](#class-selectors)
23
+
-[class: Route](#class-route)
23
24
-[class: TimeoutError](#class-timeouterror)
24
25
-[class: Accessibility](#class-accessibility)
25
26
-[class: Worker](#class-worker)
@@ -456,17 +457,17 @@ Creates a new page in the browser context.
456
457
457
458
#### browserContext.route(url, handler)
458
459
-`url` <[string]|[RegExp]|[function]\([string]\):[boolean]> A glob pattern, regex pattern or predicate receiving [URL] to match while routing.
459
-
-`handler` <[function]\([Request]\)> handler function to route the request.
460
-
- returns: <[Promise]>.
460
+
-`handler` <[function]\([Route], [Request]\)> handler function to route the request.
461
+
- returns: <[Promise]>
461
462
462
-
Routing activates the request interception and enables `request.abort`, `request.continue` and `request.fulfill` methods on the request. This provides the capability to modify network requests that are made by any page in the browser context.
463
+
Routing provides the capability to modify network requests that are made by any page in the browser context.
464
+
Once route is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
463
465
464
-
Once request interception is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
465
-
An example of a naïve request interceptor that aborts all image requests:
466
+
An example of a naïve handler that aborts all image requests:
Page routes (set up with [page.route(url, handler)](#pagerouteurl-handler)) take precedence over browser context routes when request matches both handlers.
Page routes take precedence over browser context routes (set up with [browserContext.route(url, handler)](#browsercontextrouteurl-handler)) when request matches both handlers.
-`options` <[Object]> Options object which might have the following properties:
@@ -3131,11 +3132,8 @@ If request fails at some point, then instead of `'requestfinished'` event (and p
3131
3132
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.
@@ -3146,50 +3144,6 @@ If request gets a 'redirect' response, the request is successfully finished with
3146
3144
-[request.url()](#requesturl)
3147
3145
<!-- GEN:stop -->
3148
3146
3149
-
#### request.abort([errorCode])
3150
-
-`errorCode` <[string]> Optional error code. Defaults to `failed`, could be
3151
-
one of the following:
3152
-
-`aborted` - An operation was aborted (due to user action)
3153
-
-`accessdenied` - Permission to access a resource, other than the network, was denied
3154
-
-`addressunreachable` - The IP address is unreachable. This usually means
3155
-
that there is no route to the specified host or network.
3156
-
-`blockedbyclient` - The client chose to block the request.
3157
-
-`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).
3158
-
-`connectionaborted` - A connection timed out as a result of not receiving an ACK for data sent.
3159
-
-`connectionclosed` - A connection was closed (corresponding to a TCP FIN).
3160
-
-`connectionfailed` - A connection attempt failed.
3161
-
-`connectionrefused` - A connection attempt was refused.
3162
-
-`connectionreset` - A connection was reset (corresponding to a TCP RST).
3163
-
-`internetdisconnected` - The Internet connection has been lost.
3164
-
-`namenotresolved` - The host name could not be resolved.
3165
-
-`timedout` - An operation timed out.
3166
-
-`failed` - A generic failure occurred.
3167
-
- returns: <[Promise]>
3168
-
3169
-
Aborts request. To use this, request interception should be enabled with `page.route`.
3170
-
Exception is immediately thrown if the request interception is not enabled.
3171
-
3172
-
#### request.continue([overrides])
3173
-
-`overrides` <[Object]> Optional request overrides, which can be one of the following:
3174
-
-`method` <[string]> If set changes the request method (e.g. GET or POST)
3175
-
-`postData` <[string]> If set changes the post data of request
3176
-
-`headers` <[Object]> If set changes the request HTTP headers. Header values will be converted to a string.
3177
-
- returns: <[Promise]>
3178
-
3179
-
Continues request with optional request overrides. To use this, request interception should be enabled with `page.route`.
3180
-
Exception is immediately thrown if the request interception is not enabled.
-`path` <[string]> Optional file path to respond with. The content type will be inferred from file extension. If `path` is a relative path, then it is resolved relative to [current working directory](https://nodejs.org/api/process.html#process_process_cwd).
3218
-
- returns: <[Promise]>
3219
-
3220
-
Fulfills request with given response. To use this, request interception should
3221
-
be enabled with `page.route`. Exception is thrown if
3222
-
request interception is not enabled.
3223
-
3224
-
An example of fulfilling all requests with 404 responses:
- returns: <[Object]> An object with HTTP headers associated with the request. All header names are lower-case.
3244
3167
@@ -3410,6 +3333,93 @@ const { selectors, firefox } = require('playwright'); // Or 'chromium' or 'webk
3410
3333
})();
3411
3334
```
3412
3335
3336
+
3337
+
### class: Route
3338
+
3339
+
Whenever a network route is set up with [page.route(url, handler)](#pagerouteurl-handler) or [browserContext.route(url, handler)](#browsercontextrouteurl-handler), the `Route` object allows to handle the route.
-`errorCode` <[string]> Optional error code. Defaults to `failed`, could be
3350
+
one of the following:
3351
+
-`aborted` - An operation was aborted (due to user action)
3352
+
-`accessdenied` - Permission to access a resource, other than the network, was denied
3353
+
-`addressunreachable` - The IP address is unreachable. This usually means
3354
+
that there is no route to the specified host or network.
3355
+
-`blockedbyclient` - The client chose to block the request.
3356
+
-`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).
3357
+
-`connectionaborted` - A connection timed out as a result of not receiving an ACK for data sent.
3358
+
-`connectionclosed` - A connection was closed (corresponding to a TCP FIN).
3359
+
-`connectionfailed` - A connection attempt failed.
3360
+
-`connectionrefused` - A connection attempt was refused.
3361
+
-`connectionreset` - A connection was reset (corresponding to a TCP RST).
3362
+
-`internetdisconnected` - The Internet connection has been lost.
3363
+
-`namenotresolved` - The host name could not be resolved.
3364
+
-`timedout` - An operation timed out.
3365
+
-`failed` - A generic failure occurred.
3366
+
- returns: <[Promise]>
3367
+
3368
+
Aborts the route's request.
3369
+
3370
+
#### route.continue([overrides])
3371
+
-`overrides` <[Object]> Optional request overrides, which can be one of the following:
3372
+
-`method` <[string]> If set changes the request method (e.g. GET or POST)
3373
+
-`postData` <[string]> If set changes the post data of request
3374
+
-`headers` <[Object]> If set changes the request HTTP headers. Header values will be converted to a string.
3375
+
- returns: <[Promise]>
3376
+
3377
+
Continues route's request with optional overrides.
-`path` <[string]> Optional file path to respond with. The content type will be inferred from file extension. If `path` is a relative path, then it is resolved relative to [current working directory](https://nodejs.org/api/process.html#process_process_cwd).
3397
+
- returns: <[Promise]>
3398
+
3399
+
Fulfills route's request with given response.
3400
+
3401
+
An example of fulfilling all requests with 404 responses:
0 commit comments