chore: return Promise<any> in {page,context}.route (#20005)

Fixes https://github.com/microsoft/playwright/issues/19855
Closes https://github.com/microsoft/playwright/pull/19856
This commit is contained in:
Max Schmitt 2023-01-10 18:07:17 +01:00 committed by GitHub
parent e2a2196e6a
commit 0fe327c21b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 7 additions and 5 deletions

View file

@ -1060,7 +1060,7 @@ it gets merged via the [`new URL()`](https://developer.mozilla.org/en-US/docs/We
### param: BrowserContext.route.handler ### param: BrowserContext.route.handler
* since: v1.8 * since: v1.8
* langs: js, python * langs: js, python
- `handler` <[function]\([Route], [Request]\)> - `handler` <[function]\([Route], [Request]\): [Promise<any>|any]>
handler function to route the request. handler function to route the request.

View file

@ -3138,7 +3138,7 @@ it gets merged via the [`new URL()`](https://developer.mozilla.org/en-US/docs/We
### param: Page.route.handler ### param: Page.route.handler
* since: v1.8 * since: v1.8
* langs: js, python * langs: js, python
- `handler` <[function]\([Route], [Request]\)> - `handler` <[function]\([Route], [Request]\): [Promise<any>|any]>
handler function to route the request. handler function to route the request.

View file

@ -422,7 +422,7 @@ export class Route extends ChannelOwner<channels.RouteChannel> implements api.Ro
} }
} }
export type RouteHandlerCallback = (route: Route, request: Request) => void; export type RouteHandlerCallback = (route: Route, request: Request) => Promise<any> | void;
export type ResourceTiming = { export type ResourceTiming = {
startTime: number; startTime: number;

View file

@ -3564,7 +3564,7 @@ export interface Page {
* @param handler handler function to route the request. * @param handler handler function to route the request.
* @param options * @param options
*/ */
route(url: string|RegExp|((url: URL) => boolean), handler: ((route: Route, request: Request) => void), options?: { route(url: string|RegExp|((url: URL) => boolean), handler: ((route: Route, request: Request) => Promise<any>|any), options?: {
/** /**
* How often a route should be used. By default it will be used every time. * How often a route should be used. By default it will be used every time.
*/ */
@ -8041,7 +8041,7 @@ export interface BrowserContext {
* @param handler handler function to route the request. * @param handler handler function to route the request.
* @param options * @param options
*/ */
route(url: string|RegExp|((url: URL) => boolean), handler: ((route: Route, request: Request) => void), options?: { route(url: string|RegExp|((url: URL) => boolean), handler: ((route: Route, request: Request) => Promise<any>|any), options?: {
/** /**
* How often a route should be used. By default it will be used every time. * How often a route should be used. By default it will be used every time.
*/ */

View file

@ -139,6 +139,8 @@ playwright.chromium.launch().then(async browser => {
else route.continue(); else route.continue();
}); });
await page.route('**/*', route => route.continue());
await page.route(str => { await page.route(str => {
return true; return true;
}, (route, request) => { }, (route, request) => {