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
* since: v1.8
* langs: js, python
- `handler` <[function]\([Route], [Request]\)>
- `handler` <[function]\([Route], [Request]\): [Promise<any>|any]>
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
* since: v1.8
* langs: js, python
- `handler` <[function]\([Route], [Request]\)>
- `handler` <[function]\([Route], [Request]\): [Promise<any>|any]>
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 = {
startTime: number;

View File

@ -3564,7 +3564,7 @@ export interface Page {
* @param handler handler function to route the request.
* @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.
*/
@ -8041,7 +8041,7 @@ export interface BrowserContext {
* @param handler handler function to route the request.
* @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.
*/

View File

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