From dff0517d6accb5f428e6e457cb7114d36000e008 Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Tue, 9 Jun 2026 10:05:51 +0200 Subject: [PATCH] Revert "feat: add `AbortSignal` support to client-side Waiter methods" (#41197) --- docs/src/api/class-browsercontext.md | 4 - docs/src/api/class-frame.md | 3 - docs/src/api/class-page.md | 17 -- docs/src/api/class-websocket.md | 4 - docs/src/api/class-worker.md | 3 - docs/src/api/params.md | 8 - packages/playwright-client/types/types.d.ts | 158 ++++++------------ .../playwright-core/src/client/android.ts | 2 - .../src/client/browserContext.ts | 4 +- .../playwright-core/src/client/electron.ts | 6 +- packages/playwright-core/src/client/frame.ts | 15 +- .../playwright-core/src/client/network.ts | 4 +- packages/playwright-core/src/client/page.ts | 6 +- packages/playwright-core/src/client/types.ts | 2 +- packages/playwright-core/src/client/waiter.ts | 22 --- packages/playwright-core/src/client/worker.ts | 4 +- packages/playwright-core/types/types.d.ts | 158 ++++++------------ tests/page/page-filechooser.spec.ts | 7 - utils/generate_types/index.js | 2 +- 19 files changed, 109 insertions(+), 320 deletions(-) diff --git a/docs/src/api/class-browsercontext.md b/docs/src/api/class-browsercontext.md index 518b2f6059bcf..c5e504b484c49 100644 --- a/docs/src/api/class-browsercontext.md +++ b/docs/src/api/class-browsercontext.md @@ -1713,7 +1713,6 @@ Receives the [ConsoleMessage] object and resolves to truthy value when the waiti ### option: BrowserContext.waitForConsoleMessage.timeout = %%-wait-for-event-timeout-%% * since: v1.34 -### option: BrowserContext.waitForConsoleMessage.signal = %%-wait-for-event-signal-%% ### param: BrowserContext.waitForConsoleMessage.callback = %%-java-wait-for-event-callback-%% * since: v1.34 @@ -1783,7 +1782,6 @@ Either a predicate that receives an event or an options object. Optional. ### option: BrowserContext.waitForEvent.timeout = %%-wait-for-event-timeout-%% * since: v1.8 -### option: BrowserContext.waitForEvent.signal = %%-wait-for-event-signal-%% ## async method: BrowserContext.waitForPage * since: v1.9 @@ -1813,7 +1811,6 @@ Receives the [Page] object and resolves to truthy value when the waiting should ### option: BrowserContext.waitForPage.timeout = %%-wait-for-event-timeout-%% * since: v1.9 -### option: BrowserContext.waitForPage.signal = %%-wait-for-event-signal-%% ### param: BrowserContext.waitForPage.callback = %%-java-wait-for-event-callback-%% * since: v1.9 @@ -1840,4 +1837,3 @@ Will throw an error if the browser context is closed before the `event` is fired ### option: BrowserContext.waitForEvent2.timeout = %%-wait-for-event-timeout-%% * since: v1.8 -### option: BrowserContext.waitForEvent2.signal = %%-wait-for-event-signal-%% diff --git a/docs/src/api/class-frame.md b/docs/src/api/class-frame.md index 153a09ddaa66e..c73aa88e7baa4 100644 --- a/docs/src/api/class-frame.md +++ b/docs/src/api/class-frame.md @@ -2010,7 +2010,6 @@ await frame.WaitForLoadStateAsync(); // Defaults to LoadState.Load ### option: Frame.waitForLoadState.timeout = %%-navigation-timeout-js-%% * since: v1.8 -### option: Frame.waitForLoadState.signal = %%-wait-for-event-signal-%% ## async method: Frame.waitForNavigation * since: v1.8 @@ -2094,7 +2093,6 @@ a navigation. ### option: Frame.waitForNavigation.timeout = %%-navigation-timeout-js-%% * since: v1.8 -### option: Frame.waitForNavigation.signal = %%-wait-for-event-signal-%% ### param: Frame.waitForNavigation.callback = %%-java-wait-for-event-callback-%% * since: v1.9 @@ -2291,7 +2289,6 @@ await frame.WaitForURLAsync("**/target.html"); ### option: Frame.waitForURL.timeout = %%-navigation-timeout-js-%% * since: v1.11 -### option: Frame.waitForURL.signal = %%-wait-for-event-signal-%% ### option: Frame.waitForURL.waitUntil = %%-navigation-wait-until-%% * since: v1.11 diff --git a/docs/src/api/class-page.md b/docs/src/api/class-page.md index 098d83af7275f..606bab5d35fc3 100644 --- a/docs/src/api/class-page.md +++ b/docs/src/api/class-page.md @@ -4507,7 +4507,6 @@ Performs action and waits for the Page to close. ### option: Page.waitForClose.timeout = %%-wait-for-event-timeout-%% * since: v1.9 -### option: Page.waitForClose.signal = %%-wait-for-event-signal-%% ### param: Page.waitForClose.callback = %%-java-wait-for-event-callback-%% * since: v1.9 @@ -4539,7 +4538,6 @@ Receives the [ConsoleMessage] object and resolves to truthy value when the waiti ### option: Page.waitForConsoleMessage.timeout = %%-wait-for-event-timeout-%% * since: v1.9 -### option: Page.waitForConsoleMessage.signal = %%-wait-for-event-signal-%% ### param: Page.waitForConsoleMessage.callback = %%-java-wait-for-event-callback-%% * since: v1.9 @@ -4571,7 +4569,6 @@ Receives the [Download] object and resolves to truthy value when the waiting sho ### option: Page.waitForDownload.timeout = %%-wait-for-event-timeout-%% * since: v1.9 -### option: Page.waitForDownload.signal = %%-wait-for-event-signal-%% ### param: Page.waitForDownload.callback = %%-java-wait-for-event-callback-%% * since: v1.9 @@ -4628,7 +4625,6 @@ Either a predicate that receives an event or an options object. Optional. ### option: Page.waitForEvent.timeout = %%-wait-for-event-timeout-%% * since: v1.8 -### option: Page.waitForEvent.signal = %%-wait-for-event-signal-%% ## async method: Page.waitForFileChooser * since: v1.9 @@ -4657,7 +4653,6 @@ Receives the [FileChooser] object and resolves to truthy value when the waiting ### option: Page.waitForFileChooser.timeout = %%-wait-for-event-timeout-%% * since: v1.9 -### option: Page.waitForFileChooser.signal = %%-wait-for-event-signal-%% ### param: Page.waitForFileChooser.callback = %%-java-wait-for-event-callback-%% * since: v1.9 @@ -4895,7 +4890,6 @@ Console.WriteLine(await popup.TitleAsync()); // popup is ready to use. ### option: Page.waitForLoadState.timeout = %%-navigation-timeout-js-%% * since: v1.8 -### option: Page.waitForLoadState.signal = %%-wait-for-event-signal-%% ## async method: Page.waitForNavigation * since: v1.8 @@ -4982,7 +4976,6 @@ a navigation. ### option: Page.waitForNavigation.timeout = %%-navigation-timeout-js-%% * since: v1.8 -### option: Page.waitForNavigation.signal = %%-wait-for-event-signal-%% ### param: Page.waitForNavigation.callback = %%-java-wait-for-event-callback-%% * since: v1.9 @@ -5014,7 +5007,6 @@ Receives the [Page] object and resolves to truthy value when the waiting should ### option: Page.waitForPopup.timeout = %%-wait-for-event-timeout-%% * since: v1.9 -### option: Page.waitForPopup.signal = %%-wait-for-event-signal-%% ### param: Page.waitForPopup.callback = %%-java-wait-for-event-callback-%% * since: v1.9 @@ -5124,8 +5116,6 @@ Request URL string, regex or predicate receiving [Request] object. Maximum wait time in milliseconds, defaults to 30 seconds, pass `0` to disable the timeout. The default value can be changed by using the [`method: Page.setDefaultTimeout`] method. -### option: Page.waitForRequest.signal = %%-wait-for-event-signal-%% - ### param: Page.waitForRequest.callback = %%-java-wait-for-event-callback-%% * since: v1.9 @@ -5156,7 +5146,6 @@ Receives the [Request] object and resolves to truthy value when the waiting shou ### option: Page.waitForRequestFinished.timeout = %%-wait-for-event-timeout-%% * since: v1.12 -### option: Page.waitForRequestFinished.signal = %%-wait-for-event-signal-%% ### param: Page.waitForRequestFinished.callback = %%-java-wait-for-event-callback-%% * since: v1.12 @@ -5273,8 +5262,6 @@ it gets merged via the [`new URL()`](https://developer.mozilla.org/en-US/docs/We Maximum wait time in milliseconds, defaults to 30 seconds, pass `0` to disable the timeout. The default value can be changed by using the [`method: BrowserContext.setDefaultTimeout`] or [`method: Page.setDefaultTimeout`] methods. -### option: Page.waitForResponse.signal = %%-wait-for-event-signal-%% - ### param: Page.waitForResponse.callback = %%-java-wait-for-event-callback-%% * since: v1.9 @@ -5526,7 +5513,6 @@ await page.WaitForURLAsync("**/target.html"); ### option: Page.waitForURL.timeout = %%-navigation-timeout-js-%% * since: v1.11 -### option: Page.waitForURL.signal = %%-wait-for-event-signal-%% ### option: Page.waitForURL.waitUntil = %%-navigation-wait-until-%% * since: v1.11 @@ -5558,7 +5544,6 @@ Receives the [WebSocket] object and resolves to truthy value when the waiting sh ### option: Page.waitForWebSocket.timeout = %%-wait-for-event-timeout-%% * since: v1.9 -### option: Page.waitForWebSocket.signal = %%-wait-for-event-signal-%% ### param: Page.waitForWebSocket.callback = %%-java-wait-for-event-callback-%% * since: v1.9 @@ -5590,7 +5575,6 @@ Receives the [Worker] object and resolves to truthy value when the waiting shoul ### option: Page.waitForWorker.timeout = %%-wait-for-event-timeout-%% * since: v1.9 -### option: Page.waitForWorker.signal = %%-wait-for-event-signal-%% ### param: Page.waitForWorker.callback = %%-java-wait-for-event-callback-%% * since: v1.9 @@ -5628,4 +5612,3 @@ Will throw an error if the page is closed before the `event` is fired. ### option: Page.waitForEvent2.timeout = %%-wait-for-event-timeout-%% * since: v1.8 -### option: Page.waitForEvent2.signal = %%-wait-for-event-signal-%% diff --git a/docs/src/api/class-websocket.md b/docs/src/api/class-websocket.md index 354de8f874447..e33740eacaad6 100644 --- a/docs/src/api/class-websocket.md +++ b/docs/src/api/class-websocket.md @@ -97,7 +97,6 @@ Either a predicate that receives an event or an options object. Optional. ### option: WebSocket.waitForEvent.timeout = %%-wait-for-event-timeout-%% * since: v1.8 -### option: WebSocket.waitForEvent.signal = %%-wait-for-event-signal-%% ## async method: WebSocket.waitForFrameReceived * since: v1.10 @@ -116,7 +115,6 @@ Receives the [WebSocketFrame] object and resolves to truthy value when the waiti ### option: WebSocket.waitForFrameReceived.timeout = %%-wait-for-event-timeout-%% * since: v1.9 -### option: WebSocket.waitForFrameReceived.signal = %%-wait-for-event-signal-%% ### param: WebSocket.waitForFrameReceived.callback = %%-java-wait-for-event-callback-%% * since: v1.9 @@ -138,7 +136,6 @@ Receives the [WebSocketFrame] object and resolves to truthy value when the waiti ### option: WebSocket.waitForFrameSent.timeout = %%-wait-for-event-timeout-%% * since: v1.9 -### option: WebSocket.waitForFrameSent.signal = %%-wait-for-event-signal-%% ### param: WebSocket.waitForFrameSent.callback = %%-java-wait-for-event-callback-%% * since: v1.9 @@ -165,4 +162,3 @@ Will throw an error if the socket is closed before the `event` is fired. ### option: WebSocket.waitForEvent2.timeout = %%-wait-for-event-timeout-%% * since: v1.8 -### option: WebSocket.waitForEvent2.signal = %%-wait-for-event-signal-%% diff --git a/docs/src/api/class-worker.md b/docs/src/api/class-worker.md index 9c7160335ae50..5fc5992affc23 100644 --- a/docs/src/api/class-worker.md +++ b/docs/src/api/class-worker.md @@ -126,7 +126,6 @@ Performs action and waits for the Worker to close. ### option: Worker.waitForClose.timeout = %%-wait-for-event-timeout-%% * since: v1.9 -### option: Worker.waitForClose.signal = %%-wait-for-event-signal-%% ### param: Worker.waitForClose.callback = %%-java-wait-for-event-callback-%% * since: v1.9 @@ -146,7 +145,6 @@ Receives the [ConsoleMessage] object and resolves to true when the waiting shoul ### option: Worker.waitForConsoleMessage.timeout = %%-wait-for-event-timeout-%% * since: v1.57 -### option: Worker.waitForConsoleMessage.signal = %%-wait-for-event-signal-%% ### param: Worker.waitForConsoleMessage.callback = %%-java-wait-for-event-callback-%% * since: v1.57 @@ -205,4 +203,3 @@ Either a predicate that receives an event or an options object. Optional. ### option: Worker.waitForEvent.timeout = %%-wait-for-event-timeout-%% * since: v1.57 -### option: Worker.waitForEvent.signal = %%-wait-for-event-signal-%% diff --git a/docs/src/api/params.md b/docs/src/api/params.md index 0e885a7aa363b..118b38b2820ab 100644 --- a/docs/src/api/params.md +++ b/docs/src/api/params.md @@ -991,14 +991,6 @@ Receives the event data and resolves to truthy value when the waiting should res Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can be changed by using the [`method: BrowserContext.setDefaultTimeout`]. -## wait-for-event-signal -* langs: js -* since: v1.61 -- `signal` <[AbortSignal]> - -Allows to cancel the waiting using an [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). If the signal is aborted, the waiting will be aborted and the operation will throw an error. -Note that providing a signal does not disable the default timeout; pass `timeout: 0` to disable the timeout entirely. - ## android-timeout * langs: js - `timeout` <[float]> diff --git a/packages/playwright-client/types/types.d.ts b/packages/playwright-client/types/types.d.ts index 26912a6eadd49..f03a833351206 100644 --- a/packages/playwright-client/types/types.d.ts +++ b/packages/playwright-client/types/types.d.ts @@ -4787,7 +4787,7 @@ export interface Page { /** * Emitted when the page closes. */ - waitForEvent(event: 'close', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((page: Page) => boolean | Promise)): Promise; + waitForEvent(event: 'close', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise, timeout?: number } | ((page: Page) => boolean | Promise)): Promise; /** * Emitted when JavaScript within the page calls one of console API methods, e.g. `console.log` or `console.dir`. @@ -4808,7 +4808,7 @@ export interface Page { * ``` * */ - waitForEvent(event: 'console', optionsOrPredicate?: { predicate?: (consoleMessage: ConsoleMessage) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((consoleMessage: ConsoleMessage) => boolean | Promise)): Promise; + waitForEvent(event: 'console', optionsOrPredicate?: { predicate?: (consoleMessage: ConsoleMessage) => boolean | Promise, timeout?: number } | ((consoleMessage: ConsoleMessage) => boolean | Promise)): Promise; /** * Emitted when the page crashes. Browser pages might crash if they try to allocate too much memory. When the page @@ -4828,7 +4828,7 @@ export interface Page { * ``` * */ - waitForEvent(event: 'crash', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((page: Page) => boolean | Promise)): Promise; + waitForEvent(event: 'crash', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise, timeout?: number } | ((page: Page) => boolean | Promise)): Promise; /** * Emitted when a JavaScript dialog appears, such as `alert`, `prompt`, `confirm` or `beforeunload`. Listener **must** @@ -4848,19 +4848,19 @@ export interface Page { * listeners are present, all dialogs are automatically dismissed. * */ - waitForEvent(event: 'dialog', optionsOrPredicate?: { predicate?: (dialog: Dialog) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((dialog: Dialog) => boolean | Promise)): Promise; + waitForEvent(event: 'dialog', optionsOrPredicate?: { predicate?: (dialog: Dialog) => boolean | Promise, timeout?: number } | ((dialog: Dialog) => boolean | Promise)): Promise; /** * Emitted when the JavaScript * [`DOMContentLoaded`](https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded) event is dispatched. */ - waitForEvent(event: 'domcontentloaded', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((page: Page) => boolean | Promise)): Promise; + waitForEvent(event: 'domcontentloaded', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise, timeout?: number } | ((page: Page) => boolean | Promise)): Promise; /** * Emitted when attachment download started. User can access basic file operations on downloaded content via the * passed [Download](https://playwright.dev/docs/api/class-download) instance. */ - waitForEvent(event: 'download', optionsOrPredicate?: { predicate?: (download: Download) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((download: Download) => boolean | Promise)): Promise; + waitForEvent(event: 'download', optionsOrPredicate?: { predicate?: (download: Download) => boolean | Promise, timeout?: number } | ((download: Download) => boolean | Promise)): Promise; /** * Emitted when a file chooser is supposed to appear, such as after clicking the ``. Playwright can @@ -4875,27 +4875,27 @@ export interface Page { * ``` * */ - waitForEvent(event: 'filechooser', optionsOrPredicate?: { predicate?: (fileChooser: FileChooser) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((fileChooser: FileChooser) => boolean | Promise)): Promise; + waitForEvent(event: 'filechooser', optionsOrPredicate?: { predicate?: (fileChooser: FileChooser) => boolean | Promise, timeout?: number } | ((fileChooser: FileChooser) => boolean | Promise)): Promise; /** * Emitted when a frame is attached. */ - waitForEvent(event: 'frameattached', optionsOrPredicate?: { predicate?: (frame: Frame) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((frame: Frame) => boolean | Promise)): Promise; + waitForEvent(event: 'frameattached', optionsOrPredicate?: { predicate?: (frame: Frame) => boolean | Promise, timeout?: number } | ((frame: Frame) => boolean | Promise)): Promise; /** * Emitted when a frame is detached. */ - waitForEvent(event: 'framedetached', optionsOrPredicate?: { predicate?: (frame: Frame) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((frame: Frame) => boolean | Promise)): Promise; + waitForEvent(event: 'framedetached', optionsOrPredicate?: { predicate?: (frame: Frame) => boolean | Promise, timeout?: number } | ((frame: Frame) => boolean | Promise)): Promise; /** * Emitted when a frame is navigated to a new url. */ - waitForEvent(event: 'framenavigated', optionsOrPredicate?: { predicate?: (frame: Frame) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((frame: Frame) => boolean | Promise)): Promise; + waitForEvent(event: 'framenavigated', optionsOrPredicate?: { predicate?: (frame: Frame) => boolean | Promise, timeout?: number } | ((frame: Frame) => boolean | Promise)): Promise; /** * Emitted when the JavaScript [`load`](https://developer.mozilla.org/en-US/docs/Web/Events/load) event is dispatched. */ - waitForEvent(event: 'load', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((page: Page) => boolean | Promise)): Promise; + waitForEvent(event: 'load', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise, timeout?: number } | ((page: Page) => boolean | Promise)): Promise; /** * Emitted when an uncaught exception happens within the page. @@ -4911,7 +4911,7 @@ export interface Page { * ``` * */ - waitForEvent(event: 'pageerror', optionsOrPredicate?: { predicate?: (error: Error) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((error: Error) => boolean | Promise)): Promise; + waitForEvent(event: 'pageerror', optionsOrPredicate?: { predicate?: (error: Error) => boolean | Promise, timeout?: number } | ((error: Error) => boolean | Promise)): Promise; /** * Emitted when the page opens a new tab or window. This event is emitted in addition to the @@ -4940,14 +4940,14 @@ export interface Page { * wait until the page gets to a particular state (you should not need it in most cases). * */ - waitForEvent(event: 'popup', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((page: Page) => boolean | Promise)): Promise; + waitForEvent(event: 'popup', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise, timeout?: number } | ((page: Page) => boolean | Promise)): Promise; /** * Emitted when a page issues a request. The [request] object is read-only. In order to intercept and mutate requests, * see [page.route(url, handler[, options])](https://playwright.dev/docs/api/class-page#page-route) or * [browserContext.route(url, handler[, options])](https://playwright.dev/docs/api/class-browsercontext#browser-context-route). */ - waitForEvent(event: 'request', optionsOrPredicate?: { predicate?: (request: Request) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((request: Request) => boolean | Promise)): Promise; + waitForEvent(event: 'request', optionsOrPredicate?: { predicate?: (request: Request) => boolean | Promise, timeout?: number } | ((request: Request) => boolean | Promise)): Promise; /** * Emitted when a request fails, for example by timing out. @@ -4966,30 +4966,30 @@ export interface Page { * error net::ERR_FAILED. * */ - waitForEvent(event: 'requestfailed', optionsOrPredicate?: { predicate?: (request: Request) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((request: Request) => boolean | Promise)): Promise; + waitForEvent(event: 'requestfailed', optionsOrPredicate?: { predicate?: (request: Request) => boolean | Promise, timeout?: number } | ((request: Request) => boolean | Promise)): Promise; /** * Emitted when a request finishes successfully after downloading the response body. For a successful response, the * sequence of events is `request`, `response` and `requestfinished`. */ - waitForEvent(event: 'requestfinished', optionsOrPredicate?: { predicate?: (request: Request) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((request: Request) => boolean | Promise)): Promise; + waitForEvent(event: 'requestfinished', optionsOrPredicate?: { predicate?: (request: Request) => boolean | Promise, timeout?: number } | ((request: Request) => boolean | Promise)): Promise; /** * Emitted when [response] status and headers are received for a request. For a successful response, the sequence of * events is `request`, `response` and `requestfinished`. */ - waitForEvent(event: 'response', optionsOrPredicate?: { predicate?: (response: Response) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((response: Response) => boolean | Promise)): Promise; + waitForEvent(event: 'response', optionsOrPredicate?: { predicate?: (response: Response) => boolean | Promise, timeout?: number } | ((response: Response) => boolean | Promise)): Promise; /** * Emitted when [WebSocket](https://playwright.dev/docs/api/class-websocket) request is sent. */ - waitForEvent(event: 'websocket', optionsOrPredicate?: { predicate?: (webSocket: WebSocket) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((webSocket: WebSocket) => boolean | Promise)): Promise; + waitForEvent(event: 'websocket', optionsOrPredicate?: { predicate?: (webSocket: WebSocket) => boolean | Promise, timeout?: number } | ((webSocket: WebSocket) => boolean | Promise)): Promise; /** * Emitted when a dedicated [WebWorker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) is spawned * by the page. */ - waitForEvent(event: 'worker', optionsOrPredicate?: { predicate?: (worker: Worker) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((worker: Worker) => boolean | Promise)): Promise; + waitForEvent(event: 'worker', optionsOrPredicate?: { predicate?: (worker: Worker) => boolean | Promise, timeout?: number } | ((worker: Worker) => boolean | Promise)): Promise; /** @@ -5026,14 +5026,6 @@ export interface Page { * @param options */ waitForLoadState(state?: "load"|"domcontentloaded"|"networkidle", options?: { - /** - * Allows to cancel the waiting using an - * [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). If the signal is aborted, the - * waiting will be aborted and the operation will throw an error. Note that providing a signal does not disable the - * default timeout; pass `timeout: 0` to disable the timeout entirely. - */ - signal?: AbortSignal; - /** * Maximum operation time in milliseconds. Defaults to `0` - no timeout. The default value can be changed via * `navigationTimeout` option in the config, or by using the @@ -5071,14 +5063,6 @@ export interface Page { * @param options */ waitForNavigation(options?: { - /** - * Allows to cancel the waiting using an - * [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). If the signal is aborted, the - * waiting will be aborted and the operation will throw an error. Note that providing a signal does not disable the - * default timeout; pass `timeout: 0` to disable the timeout entirely. - */ - signal?: AbortSignal; - /** * Maximum operation time in milliseconds. Defaults to `0` - no timeout. The default value can be changed via * `navigationTimeout` option in the config, or by using the @@ -5132,14 +5116,6 @@ export interface Page { * @param options */ waitForRequest(urlOrPredicate: string|RegExp|((request: Request) => boolean|Promise), options?: { - /** - * Allows to cancel the waiting using an - * [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). If the signal is aborted, the - * waiting will be aborted and the operation will throw an error. Note that providing a signal does not disable the - * default timeout; pass `timeout: 0` to disable the timeout entirely. - */ - signal?: AbortSignal; - /** * Maximum wait time in milliseconds, defaults to 30 seconds, pass `0` to disable the timeout. The default value can * be changed by using the @@ -5176,14 +5152,6 @@ export interface Page { * @param options */ waitForResponse(urlOrPredicate: string|RegExp|((response: Response) => boolean|Promise), options?: { - /** - * Allows to cancel the waiting using an - * [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). If the signal is aborted, the - * waiting will be aborted and the operation will throw an error. Note that providing a signal does not disable the - * default timeout; pass `timeout: 0` to disable the timeout entirely. - */ - signal?: AbortSignal; - /** * Maximum wait time in milliseconds, defaults to 30 seconds, pass `0` to disable the timeout. The default value can * be changed by using the @@ -5230,14 +5198,6 @@ export interface Page { * @param options */ waitForURL(url: string|RegExp|URLPattern|((url: URL) => boolean), options?: { - /** - * Allows to cancel the waiting using an - * [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). If the signal is aborted, the - * waiting will be aborted and the operation will throw an error. Note that providing a signal does not disable the - * default timeout; pass `timeout: 0` to disable the timeout entirely. - */ - signal?: AbortSignal; - /** * Maximum operation time in milliseconds. Defaults to `0` - no timeout. The default value can be changed via * `navigationTimeout` option in the config, or by using the @@ -8063,14 +8023,6 @@ export interface Frame { * @param options */ waitForLoadState(state?: "load"|"domcontentloaded"|"networkidle", options?: { - /** - * Allows to cancel the waiting using an - * [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). If the signal is aborted, the - * waiting will be aborted and the operation will throw an error. Note that providing a signal does not disable the - * default timeout; pass `timeout: 0` to disable the timeout entirely. - */ - signal?: AbortSignal; - /** * Maximum operation time in milliseconds. Defaults to `0` - no timeout. The default value can be changed via * `navigationTimeout` option in the config, or by using the @@ -8107,14 +8059,6 @@ export interface Frame { * @param options */ waitForNavigation(options?: { - /** - * Allows to cancel the waiting using an - * [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). If the signal is aborted, the - * waiting will be aborted and the operation will throw an error. Note that providing a signal does not disable the - * default timeout; pass `timeout: 0` to disable the timeout entirely. - */ - signal?: AbortSignal; - /** * Maximum operation time in milliseconds. Defaults to `0` - no timeout. The default value can be changed via * `navigationTimeout` option in the config, or by using the @@ -8173,14 +8117,6 @@ export interface Frame { * @param options */ waitForURL(url: string|RegExp|URLPattern|((url: URL) => boolean), options?: { - /** - * Allows to cancel the waiting using an - * [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). If the signal is aborted, the - * waiting will be aborted and the operation will throw an error. Note that providing a signal does not disable the - * default timeout; pass `timeout: 0` to disable the timeout entirely. - */ - signal?: AbortSignal; - /** * Maximum operation time in milliseconds. Defaults to `0` - no timeout. The default value can be changed via * `navigationTimeout` option in the config, or by using the @@ -9787,7 +9723,7 @@ export interface BrowserContext { /** * This event is not emitted. */ - waitForEvent(event: 'backgroundpage', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((page: Page) => boolean | Promise)): Promise; + waitForEvent(event: 'backgroundpage', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise, timeout?: number } | ((page: Page) => boolean | Promise)): Promise; /** * Emitted when Browser context gets closed. This might happen because of one of the following: @@ -9795,7 +9731,7 @@ export interface BrowserContext { * - Browser application is closed or crashed. * - The [browser.close([options])](https://playwright.dev/docs/api/class-browser#browser-close) method was called. */ - waitForEvent(event: 'close', optionsOrPredicate?: { predicate?: (browserContext: BrowserContext) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((browserContext: BrowserContext) => boolean | Promise)): Promise; + waitForEvent(event: 'close', optionsOrPredicate?: { predicate?: (browserContext: BrowserContext) => boolean | Promise, timeout?: number } | ((browserContext: BrowserContext) => boolean | Promise)): Promise; /** * Emitted when JavaScript within the page calls one of console API methods, e.g. `console.log` or `console.dir`. @@ -9816,7 +9752,7 @@ export interface BrowserContext { * ``` * */ - waitForEvent(event: 'console', optionsOrPredicate?: { predicate?: (consoleMessage: ConsoleMessage) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((consoleMessage: ConsoleMessage) => boolean | Promise)): Promise; + waitForEvent(event: 'console', optionsOrPredicate?: { predicate?: (consoleMessage: ConsoleMessage) => boolean | Promise, timeout?: number } | ((consoleMessage: ConsoleMessage) => boolean | Promise)): Promise; /** * Emitted when a JavaScript dialog appears, such as `alert`, `prompt`, `confirm` or `beforeunload`. Listener **must** @@ -9838,7 +9774,7 @@ export interface BrowserContext { * listeners are present, all dialogs are automatically dismissed. * */ - waitForEvent(event: 'dialog', optionsOrPredicate?: { predicate?: (dialog: Dialog) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((dialog: Dialog) => boolean | Promise)): Promise; + waitForEvent(event: 'dialog', optionsOrPredicate?: { predicate?: (dialog: Dialog) => boolean | Promise, timeout?: number } | ((dialog: Dialog) => boolean | Promise)): Promise; /** * Emitted when attachment download started in any page belonging to this context. User can access basic file @@ -9846,28 +9782,28 @@ export interface BrowserContext { * instance. See also [page.on('download')](https://playwright.dev/docs/api/class-page#page-event-download) to receive * events about a specific page. */ - waitForEvent(event: 'download', optionsOrPredicate?: { predicate?: (download: Download) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((download: Download) => boolean | Promise)): Promise; + waitForEvent(event: 'download', optionsOrPredicate?: { predicate?: (download: Download) => boolean | Promise, timeout?: number } | ((download: Download) => boolean | Promise)): Promise; /** * Emitted when a frame is attached in any page belonging to this context. See also * [page.on('frameattached')](https://playwright.dev/docs/api/class-page#page-event-frame-attached) to receive events * about a specific page. */ - waitForEvent(event: 'frameattached', optionsOrPredicate?: { predicate?: (frame: Frame) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((frame: Frame) => boolean | Promise)): Promise; + waitForEvent(event: 'frameattached', optionsOrPredicate?: { predicate?: (frame: Frame) => boolean | Promise, timeout?: number } | ((frame: Frame) => boolean | Promise)): Promise; /** * Emitted when a frame is detached in any page belonging to this context. See also * [page.on('framedetached')](https://playwright.dev/docs/api/class-page#page-event-frame-detached) to receive events * about a specific page. */ - waitForEvent(event: 'framedetached', optionsOrPredicate?: { predicate?: (frame: Frame) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((frame: Frame) => boolean | Promise)): Promise; + waitForEvent(event: 'framedetached', optionsOrPredicate?: { predicate?: (frame: Frame) => boolean | Promise, timeout?: number } | ((frame: Frame) => boolean | Promise)): Promise; /** * Emitted when a frame is navigated to a new url in any page belonging to this context. See also * [page.on('framenavigated')](https://playwright.dev/docs/api/class-page#page-event-frame-navigated) to receive * events about navigations in a specific page. */ - waitForEvent(event: 'framenavigated', optionsOrPredicate?: { predicate?: (frame: Frame) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((frame: Frame) => boolean | Promise)): Promise; + waitForEvent(event: 'framenavigated', optionsOrPredicate?: { predicate?: (frame: Frame) => boolean | Promise, timeout?: number } | ((frame: Frame) => boolean | Promise)): Promise; /** * The event is emitted when a new Page is created in the BrowserContext. The page may still be loading. The event @@ -9896,14 +9832,14 @@ export interface BrowserContext { * wait until the page gets to a particular state (you should not need it in most cases). * */ - waitForEvent(event: 'page', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((page: Page) => boolean | Promise)): Promise; + waitForEvent(event: 'page', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise, timeout?: number } | ((page: Page) => boolean | Promise)): Promise; /** * Emitted when a page in this context is closed. See also * [page.on('close')](https://playwright.dev/docs/api/class-page#page-event-close) to receive events about a specific * page. */ - waitForEvent(event: 'pageclose', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((page: Page) => boolean | Promise)): Promise; + waitForEvent(event: 'pageclose', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise, timeout?: number } | ((page: Page) => boolean | Promise)): Promise; /** * Emitted when the JavaScript [`load`](https://developer.mozilla.org/en-US/docs/Web/Events/load) event is dispatched @@ -9911,7 +9847,7 @@ export interface BrowserContext { * [page.on('load')](https://playwright.dev/docs/api/class-page#page-event-load) to receive events about a specific * page. */ - waitForEvent(event: 'pageload', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((page: Page) => boolean | Promise)): Promise; + waitForEvent(event: 'pageload', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise, timeout?: number } | ((page: Page) => boolean | Promise)): Promise; /** * Emitted when a request is issued from any pages created through this context. The [request] object is read-only. To @@ -9922,7 +9858,7 @@ export interface BrowserContext { * [browserContext.route(url, handler[, options])](https://playwright.dev/docs/api/class-browsercontext#browser-context-route) * or [page.route(url, handler[, options])](https://playwright.dev/docs/api/class-page#page-route). */ - waitForEvent(event: 'request', optionsOrPredicate?: { predicate?: (request: Request) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((request: Request) => boolean | Promise)): Promise; + waitForEvent(event: 'request', optionsOrPredicate?: { predicate?: (request: Request) => boolean | Promise, timeout?: number } | ((request: Request) => boolean | Promise)): Promise; /** * Emitted when a request fails, for example by timing out. To only listen for failed requests from a particular page, @@ -9935,7 +9871,7 @@ export interface BrowserContext { * [browserContext.on('requestfailed')](https://playwright.dev/docs/api/class-browsercontext#browser-context-event-request-failed). * */ - waitForEvent(event: 'requestfailed', optionsOrPredicate?: { predicate?: (request: Request) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((request: Request) => boolean | Promise)): Promise; + waitForEvent(event: 'requestfailed', optionsOrPredicate?: { predicate?: (request: Request) => boolean | Promise, timeout?: number } | ((request: Request) => boolean | Promise)): Promise; /** * Emitted when a request finishes successfully after downloading the response body. For a successful response, the @@ -9943,27 +9879,27 @@ export interface BrowserContext { * particular page, use * [page.on('requestfinished')](https://playwright.dev/docs/api/class-page#page-event-request-finished). */ - waitForEvent(event: 'requestfinished', optionsOrPredicate?: { predicate?: (request: Request) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((request: Request) => boolean | Promise)): Promise; + waitForEvent(event: 'requestfinished', optionsOrPredicate?: { predicate?: (request: Request) => boolean | Promise, timeout?: number } | ((request: Request) => boolean | Promise)): Promise; /** * Emitted when [response] status and headers are received for a request. For a successful response, the sequence of * events is `request`, `response` and `requestfinished`. To listen for response events from a particular page, use * [page.on('response')](https://playwright.dev/docs/api/class-page#page-event-response). */ - waitForEvent(event: 'response', optionsOrPredicate?: { predicate?: (response: Response) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((response: Response) => boolean | Promise)): Promise; + waitForEvent(event: 'response', optionsOrPredicate?: { predicate?: (response: Response) => boolean | Promise, timeout?: number } | ((response: Response) => boolean | Promise)): Promise; /** * **NOTE** Service workers are only supported on Chromium-based browsers. * * Emitted when new service worker is created in the context. */ - waitForEvent(event: 'serviceworker', optionsOrPredicate?: { predicate?: (worker: Worker) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((worker: Worker) => boolean | Promise)): Promise; + waitForEvent(event: 'serviceworker', optionsOrPredicate?: { predicate?: (worker: Worker) => boolean | Promise, timeout?: number } | ((worker: Worker) => boolean | Promise)): Promise; /** * Emitted when exception is unhandled in any of the pages in this context. To listen for errors from a particular * page, use [page.on('pageerror')](https://playwright.dev/docs/api/class-page#page-event-page-error) instead. */ - waitForEvent(event: 'weberror', optionsOrPredicate?: { predicate?: (webError: WebError) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((webError: WebError) => boolean | Promise)): Promise; + waitForEvent(event: 'weberror', optionsOrPredicate?: { predicate?: (webError: WebError) => boolean | Promise, timeout?: number } | ((webError: WebError) => boolean | Promise)): Promise; /** @@ -10930,12 +10866,12 @@ export interface Worker { * Emitted when this dedicated [WebWorker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) is * terminated. */ - waitForEvent(event: 'close', optionsOrPredicate?: { predicate?: (worker: Worker) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((worker: Worker) => boolean | Promise)): Promise; + waitForEvent(event: 'close', optionsOrPredicate?: { predicate?: (worker: Worker) => boolean | Promise, timeout?: number } | ((worker: Worker) => boolean | Promise)): Promise; /** * Emitted when JavaScript within the worker calls one of console API methods, e.g. `console.log` or `console.dir`. */ - waitForEvent(event: 'console', optionsOrPredicate?: { predicate?: (consoleMessage: ConsoleMessage) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((consoleMessage: ConsoleMessage) => boolean | Promise)): Promise; + waitForEvent(event: 'console', optionsOrPredicate?: { predicate?: (consoleMessage: ConsoleMessage) => boolean | Promise, timeout?: number } | ((consoleMessage: ConsoleMessage) => boolean | Promise)): Promise; } @@ -17178,7 +17114,7 @@ export interface ElectronApplication { /** * This event is issued when the application process has been terminated. */ - waitForEvent(event: 'close', optionsOrPredicate?: { predicate?: () => boolean | Promise, timeout?: number, signal?: AbortSignal } | (() => boolean | Promise)): Promise; + waitForEvent(event: 'close', optionsOrPredicate?: { predicate?: () => boolean | Promise, timeout?: number } | (() => boolean | Promise)): Promise; /** * Emitted when JavaScript within the Electron main process calls one of console API methods, e.g. `console.log` or @@ -17200,13 +17136,13 @@ export interface ElectronApplication { * ``` * */ - waitForEvent(event: 'console', optionsOrPredicate?: { predicate?: (consoleMessage: ConsoleMessage) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((consoleMessage: ConsoleMessage) => boolean | Promise)): Promise; + waitForEvent(event: 'console', optionsOrPredicate?: { predicate?: (consoleMessage: ConsoleMessage) => boolean | Promise, timeout?: number } | ((consoleMessage: ConsoleMessage) => boolean | Promise)): Promise; /** * This event is issued for every window that is created **and loaded** in Electron. It contains a * [Page](https://playwright.dev/docs/api/class-page) that can be used for Playwright automation. */ - waitForEvent(event: 'window', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((page: Page) => boolean | Promise)): Promise; + waitForEvent(event: 'window', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise, timeout?: number } | ((page: Page) => boolean | Promise)): Promise; /** @@ -21708,7 +21644,7 @@ export interface WebSocket { /** * Fired when the websocket closes. */ - waitForEvent(event: 'close', optionsOrPredicate?: { predicate?: (webSocket: WebSocket) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((webSocket: WebSocket) => boolean | Promise)): Promise; + waitForEvent(event: 'close', optionsOrPredicate?: { predicate?: (webSocket: WebSocket) => boolean | Promise, timeout?: number } | ((webSocket: WebSocket) => boolean | Promise)): Promise; /** * Fired when the websocket receives a frame. @@ -21718,7 +21654,7 @@ export interface WebSocket { * frame payload */ payload: string|Buffer; - }) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((data: { + }) => boolean | Promise, timeout?: number } | ((data: { /** * frame payload */ @@ -21738,7 +21674,7 @@ export interface WebSocket { * frame payload */ payload: string|Buffer; - }) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((data: { + }) => boolean | Promise, timeout?: number } | ((data: { /** * frame payload */ @@ -21753,7 +21689,7 @@ export interface WebSocket { /** * Fired when the websocket has an error. */ - waitForEvent(event: 'socketerror', optionsOrPredicate?: { predicate?: (string: string) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((string: string) => boolean | Promise)): Promise; + waitForEvent(event: 'socketerror', optionsOrPredicate?: { predicate?: (string: string) => boolean | Promise, timeout?: number } | ((string: string) => boolean | Promise)): Promise; } @@ -23100,12 +23036,12 @@ export interface AndroidDevice { /** * Emitted when the device connection gets closed. */ - waitForEvent(event: 'close', optionsOrPredicate?: { predicate?: (androidDevice: AndroidDevice) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((androidDevice: AndroidDevice) => boolean | Promise)): Promise; + waitForEvent(event: 'close', optionsOrPredicate?: { predicate?: (androidDevice: AndroidDevice) => boolean | Promise, timeout?: number } | ((androidDevice: AndroidDevice) => boolean | Promise)): Promise; /** * Emitted when a new WebView instance is detected. */ - waitForEvent(event: 'webview', optionsOrPredicate?: { predicate?: (androidWebView: AndroidWebView) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((androidWebView: AndroidWebView) => boolean | Promise)): Promise; + waitForEvent(event: 'webview', optionsOrPredicate?: { predicate?: (androidWebView: AndroidWebView) => boolean | Promise, timeout?: number } | ((androidWebView: AndroidWebView) => boolean | Promise)): Promise; /** diff --git a/packages/playwright-core/src/client/android.ts b/packages/playwright-core/src/client/android.ts index 3f6ad60f04c02..9a63c601ef988 100644 --- a/packages/playwright-core/src/client/android.ts +++ b/packages/playwright-core/src/client/android.ts @@ -273,10 +273,8 @@ export class AndroidDevice extends ChannelOwner i return await this._wrapApiCall(async () => { const timeout = this._timeoutSettings.timeout(typeof optionsOrPredicate === 'function' ? {} : optionsOrPredicate); const predicate = typeof optionsOrPredicate === 'function' ? optionsOrPredicate : optionsOrPredicate.predicate; - const signal = typeof optionsOrPredicate === 'function' ? undefined : (optionsOrPredicate as types.TimeoutOptions).signal; const waiter = Waiter.createForEvent(this, event); waiter.rejectOnTimeout(timeout, `Timeout ${timeout}ms exceeded while waiting for event "${event}"`); - waiter.rejectOnSignal(signal); if (event !== Events.AndroidDevice.Close) waiter.rejectOnEvent(this, Events.AndroidDevice.Close, () => new TargetClosedError()); const result = await waiter.waitForEvent(this, event, predicate as any); diff --git a/packages/playwright-core/src/client/browserContext.ts b/packages/playwright-core/src/client/browserContext.ts index ff4b4241de878..31accbf0cb8cf 100644 --- a/packages/playwright-core/src/client/browserContext.ts +++ b/packages/playwright-core/src/client/browserContext.ts @@ -43,7 +43,7 @@ import { Worker } from './worker'; import { TimeoutSettings } from './timeoutSettings'; import { mkdirIfNeeded } from './fileUtils'; -import type { BrowserContextOptions, Headers, SetStorageState, StorageState, TimeoutOptions, WaitForEventOptions } from './types'; +import type { BrowserContextOptions, Headers, SetStorageState, StorageState, WaitForEventOptions } from './types'; import type * as structs from '../../types/structs'; import type * as api from '../../types/types'; import type { URLMatch } from '@isomorphic/urlMatch'; @@ -447,10 +447,8 @@ export class BrowserContext extends ChannelOwner return await this._wrapApiCall(async () => { const timeout = this._timeoutSettings.timeout(typeof optionsOrPredicate === 'function' ? {} : optionsOrPredicate); const predicate = typeof optionsOrPredicate === 'function' ? optionsOrPredicate : optionsOrPredicate.predicate; - const signal = typeof optionsOrPredicate === 'function' ? undefined : (optionsOrPredicate as TimeoutOptions).signal; const waiter = Waiter.createForEvent(this, event); waiter.rejectOnTimeout(timeout, `Timeout ${timeout}ms exceeded while waiting for event "${event}"`); - waiter.rejectOnSignal(signal); if (event !== Events.BrowserContext.Close) waiter.rejectOnEvent(this, Events.BrowserContext.Close, () => new TargetClosedError(this._effectiveCloseReason())); const result = await waiter.waitForEvent(this, event, predicate as any); diff --git a/packages/playwright-core/src/client/electron.ts b/packages/playwright-core/src/client/electron.ts index f83be0294672f..2399aa61ff1ce 100644 --- a/packages/playwright-core/src/client/electron.ts +++ b/packages/playwright-core/src/client/electron.ts @@ -25,7 +25,7 @@ import { Waiter } from './waiter'; import { TimeoutSettings } from './timeoutSettings'; import type { Page } from './page'; -import type { BrowserContextOptions, Headers, TimeoutOptions, WaitForEventOptions } from './types'; +import type { BrowserContextOptions, Headers, WaitForEventOptions } from './types'; import type * as structs from '../../types/structs'; import type * as api from '../../types/types'; import type * as channels from '@protocol/channels'; @@ -114,7 +114,7 @@ export class ElectronApplication extends ChannelOwner { + async firstWindow(options?: { timeout?: number }): Promise { if (this._windows.size) return this._windows.values().next().value!; return await this.waitForEvent('window', options); @@ -142,10 +142,8 @@ export class ElectronApplication extends ChannelOwner { const timeout = this._timeoutSettings.timeout(typeof optionsOrPredicate === 'function' ? {} : optionsOrPredicate); const predicate = typeof optionsOrPredicate === 'function' ? optionsOrPredicate : optionsOrPredicate.predicate; - const signal = typeof optionsOrPredicate === 'function' ? undefined : (optionsOrPredicate as TimeoutOptions).signal; const waiter = Waiter.createForEvent(this, event); waiter.rejectOnTimeout(timeout, `Timeout ${timeout}ms exceeded while waiting for event "${event}"`); - waiter.rejectOnSignal(signal); if (event !== Events.ElectronApplication.Close) waiter.rejectOnEvent(this, Events.ElectronApplication.Close, () => new TargetClosedError()); const result = await waiter.waitForEvent(this, event, predicate as any); diff --git a/packages/playwright-core/src/client/frame.ts b/packages/playwright-core/src/client/frame.ts index bb28e673771f4..bb116238ea5cf 100644 --- a/packages/playwright-core/src/client/frame.ts +++ b/packages/playwright-core/src/client/frame.ts @@ -44,7 +44,6 @@ export type WaitForNavigationOptions = { timeout?: number, waitUntil?: LifecycleEvent, url?: URLMatch, - signal?: AbortSignal, }; export class Frame extends ChannelOwner implements api.Frame { @@ -119,7 +118,7 @@ export class Frame extends ChannelOwner implements api.Fr return network.Response.fromNullable((await this._channel.goto({ url, ...options, waitUntil, timeout: this._navigationTimeout(options) })).response); } - private _setupNavigationWaiter(options: TimeoutOptions): Waiter { + private _setupNavigationWaiter(options: { timeout?: number }): Waiter { const waiter = new Waiter(this._page!, ''); if (this._page!.isClosed()) waiter.rejectImmediately(this._page!._closeErrorWithReason()); @@ -128,7 +127,6 @@ export class Frame extends ChannelOwner implements api.Fr waiter.rejectOnEvent(this._page!, Events.Page.FrameDetached, new Error('Navigating frame was detached!'), frame => frame === this); const timeout = this._page!._timeoutSettings.navigationTimeout(options); waiter.rejectOnTimeout(timeout, `Timeout ${timeout}ms exceeded.`); - waiter.rejectOnSignal(options.signal); return waiter; } @@ -167,10 +165,10 @@ export class Frame extends ChannelOwner implements api.Fr }, { title: 'Wait for navigation' }); } - async waitForLoadState(state: LifecycleEvent = 'load', options?: TimeoutOptions): Promise { + async waitForLoadState(state: LifecycleEvent = 'load', options: { timeout?: number } = {}): Promise { state = verifyLoadState('state', state); return await this._page!._wrapApiCall(async () => { - const waiter = this._setupNavigationWaiter(options ?? {}); + const waiter = this._setupNavigationWaiter(options); if (this._loadStates.has(state)) { waiter.log(` not waiting, "${state}" event already fired`); } else { @@ -183,12 +181,11 @@ export class Frame extends ChannelOwner implements api.Fr }, { title: `Wait for load state "${state}"` }); } - async waitForURL(url: URLMatch, options?: { waitUntil?: LifecycleEvent } & TimeoutOptions): Promise { - const waitOptions = options ?? {}; + async waitForURL(url: URLMatch, options: { waitUntil?: LifecycleEvent, timeout?: number } = {}): Promise { if (urlMatches(this._page?.context()._options.baseURL, this.url(), url)) - return await this.waitForLoadState(waitOptions.waitUntil, waitOptions); + return await this.waitForLoadState(options.waitUntil, options); - await this.waitForNavigation({ url, ...waitOptions }); + await this.waitForNavigation({ url, ...options }); } async frameElement(): Promise { diff --git a/packages/playwright-core/src/client/network.ts b/packages/playwright-core/src/client/network.ts index 49ab620c190a7..08ce06bf09528 100644 --- a/packages/playwright-core/src/client/network.ts +++ b/packages/playwright-core/src/client/network.ts @@ -32,7 +32,7 @@ import { ChannelOwner } from './channelOwner'; import type { BrowserContext } from './browserContext'; import type { Page } from './page'; -import type { Headers, RemoteAddr, SecurityDetails, TimeoutOptions, WaitForEventOptions } from './types'; +import type { Headers, RemoteAddr, SecurityDetails, WaitForEventOptions } from './types'; import type { Serializable } from '../../types/structs'; import type * as api from '../../types/types'; import type { HeadersArray } from '@isomorphic/types'; @@ -802,10 +802,8 @@ export class WebSocket extends ChannelOwner implement return await this._wrapApiCall(async () => { const timeout = this._page._timeoutSettings.timeout(typeof optionsOrPredicate === 'function' ? {} : optionsOrPredicate); const predicate = typeof optionsOrPredicate === 'function' ? optionsOrPredicate : optionsOrPredicate.predicate; - const signal = typeof optionsOrPredicate === 'function' ? undefined : (optionsOrPredicate as TimeoutOptions).signal; const waiter = Waiter.createForEvent(this, event); waiter.rejectOnTimeout(timeout, `Timeout ${timeout}ms exceeded while waiting for event "${event}"`); - waiter.rejectOnSignal(signal); if (event !== Events.WebSocket.Error) waiter.rejectOnEvent(this, Events.WebSocket.Error, new Error('Socket error')); if (event !== Events.WebSocket.Close) diff --git a/packages/playwright-core/src/client/page.ts b/packages/playwright-core/src/client/page.ts index b45b623083a7f..6da37f9f5b1b7 100644 --- a/packages/playwright-core/src/client/page.ts +++ b/packages/playwright-core/src/client/page.ts @@ -449,7 +449,7 @@ export class Page extends ChannelOwner implements api.Page }; const trimmedUrl = trimUrl(urlOrPredicate); const logLine = trimmedUrl ? `waiting for request ${trimmedUrl}` : undefined; - return await this._waitForEvent(Events.Page.Request, { predicate, timeout: options.timeout, signal: options.signal }, logLine); + return await this._waitForEvent(Events.Page.Request, { predicate, timeout: options.timeout }, logLine); } async waitForResponse(urlOrPredicate: string | RegExp | ((r: Response) => boolean | Promise), options: TimeoutOptions = {}): Promise { @@ -460,7 +460,7 @@ export class Page extends ChannelOwner implements api.Page }; const trimmedUrl = trimUrl(urlOrPredicate); const logLine = trimmedUrl ? `waiting for response ${trimmedUrl}` : undefined; - return await this._waitForEvent(Events.Page.Response, { predicate, timeout: options.timeout, signal: options.signal }, logLine); + return await this._waitForEvent(Events.Page.Response, { predicate, timeout: options.timeout }, logLine); } async waitForEvent(event: string, optionsOrPredicate: WaitForEventOptions = {}): Promise { @@ -475,12 +475,10 @@ export class Page extends ChannelOwner implements api.Page return await this._wrapApiCall(async () => { const timeout = this._timeoutSettings.timeout(typeof optionsOrPredicate === 'function' ? {} : optionsOrPredicate); const predicate = typeof optionsOrPredicate === 'function' ? optionsOrPredicate : optionsOrPredicate.predicate; - const signal = typeof optionsOrPredicate === 'function' ? undefined : (optionsOrPredicate as TimeoutOptions).signal; const waiter = Waiter.createForEvent(this, event); if (logLine) waiter.log(logLine); waiter.rejectOnTimeout(timeout, `Timeout ${timeout}ms exceeded while waiting for event "${event}"`); - waiter.rejectOnSignal(signal); if (event !== Events.Page.Crash) waiter.rejectOnEvent(this, Events.Page.Crash, new Error('Page crashed')); if (event !== Events.Page.Close) diff --git a/packages/playwright-core/src/client/types.ts b/packages/playwright-core/src/client/types.ts index cf7bedd7af974..cb90ec932f987 100644 --- a/packages/playwright-core/src/client/types.ts +++ b/packages/playwright-core/src/client/types.ts @@ -25,7 +25,7 @@ export interface Logger { log(name: string, severity: LoggerSeverity, message: string | Error, args: any[], hints: { color?: string }): void; } -export type TimeoutOptions = { timeout?: number, signal?: AbortSignal }; +export type TimeoutOptions = { timeout?: number }; export type StrictOptions = { strict?: boolean }; export type Headers = { [key: string]: string }; diff --git a/packages/playwright-core/src/client/waiter.ts b/packages/playwright-core/src/client/waiter.ts index e53aeae27d7a5..e2b63c890081c 100644 --- a/packages/playwright-core/src/client/waiter.ts +++ b/packages/playwright-core/src/client/waiter.ts @@ -85,20 +85,6 @@ export class Waiter { this._rejectOn(promise.then(() => { throw new TimeoutError(message); }), dispose); } - rejectOnSignal(signal: AbortSignal | undefined) { - if (!signal) - return; - if (signal.aborted) { - this.rejectImmediately(signalToError(signal)); - return; - } - let rejectPromise: (e: any) => void; - const promise = new Promise((_, reject) => { rejectPromise = reject; }); - const listener = () => rejectPromise!(signalToError(signal)); - signal.addEventListener('abort', listener, { once: true }); - this._rejectOn(promise, () => signal.removeEventListener('abort', listener)); - } - rejectImmediately(error: Error) { this._immediateError = error; } @@ -160,14 +146,6 @@ function waitForEvent(emitter: EventEmitter, event: string, savedZone: return { promise, dispose }; } -function signalToError(signal: AbortSignal): Error { - const reason = signal.reason; - if (reason instanceof Error) - return reason; - const message = typeof reason?.message === 'string' ? reason.message : reason; - return new Error(String(message ?? 'The operation was aborted')); -} - function waitForTimeout(timeout: number): { promise: Promise, dispose: () => void } { let timeoutId: any; const promise = new Promise(resolve => timeoutId = setTimeout(resolve, timeout)); diff --git a/packages/playwright-core/src/client/worker.ts b/packages/playwright-core/src/client/worker.ts index 1d11e65b21197..ee98e35779e2e 100644 --- a/packages/playwright-core/src/client/worker.ts +++ b/packages/playwright-core/src/client/worker.ts @@ -28,7 +28,7 @@ import type { Page } from './page'; import type * as structs from '../../types/structs'; import type * as api from '../../types/types'; import type * as channels from '@protocol/channels'; -import type { TimeoutOptions, WaitForEventOptions } from './types'; +import type { WaitForEventOptions } from './types'; export class Worker extends ChannelOwner implements api.Worker { @@ -91,10 +91,8 @@ export class Worker extends ChannelOwner implements api. const timeoutSettings = this._page?._timeoutSettings ?? this._context?._timeoutSettings ?? new TimeoutSettings(this._platform); const timeout = timeoutSettings.timeout(typeof optionsOrPredicate === 'function' ? {} : optionsOrPredicate); const predicate = typeof optionsOrPredicate === 'function' ? optionsOrPredicate : optionsOrPredicate.predicate; - const signal = typeof optionsOrPredicate === 'function' ? undefined : (optionsOrPredicate as TimeoutOptions).signal; const waiter = Waiter.createForEvent(this, event); waiter.rejectOnTimeout(timeout, `Timeout ${timeout}ms exceeded while waiting for event "${event}"`); - waiter.rejectOnSignal(signal); if (event !== Events.Worker.Close) waiter.rejectOnEvent(this, Events.Worker.Close, () => this._closeErrorWithReason()); const result = await waiter.waitForEvent(this, event, predicate as any); diff --git a/packages/playwright-core/types/types.d.ts b/packages/playwright-core/types/types.d.ts index 26912a6eadd49..f03a833351206 100644 --- a/packages/playwright-core/types/types.d.ts +++ b/packages/playwright-core/types/types.d.ts @@ -4787,7 +4787,7 @@ export interface Page { /** * Emitted when the page closes. */ - waitForEvent(event: 'close', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((page: Page) => boolean | Promise)): Promise; + waitForEvent(event: 'close', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise, timeout?: number } | ((page: Page) => boolean | Promise)): Promise; /** * Emitted when JavaScript within the page calls one of console API methods, e.g. `console.log` or `console.dir`. @@ -4808,7 +4808,7 @@ export interface Page { * ``` * */ - waitForEvent(event: 'console', optionsOrPredicate?: { predicate?: (consoleMessage: ConsoleMessage) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((consoleMessage: ConsoleMessage) => boolean | Promise)): Promise; + waitForEvent(event: 'console', optionsOrPredicate?: { predicate?: (consoleMessage: ConsoleMessage) => boolean | Promise, timeout?: number } | ((consoleMessage: ConsoleMessage) => boolean | Promise)): Promise; /** * Emitted when the page crashes. Browser pages might crash if they try to allocate too much memory. When the page @@ -4828,7 +4828,7 @@ export interface Page { * ``` * */ - waitForEvent(event: 'crash', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((page: Page) => boolean | Promise)): Promise; + waitForEvent(event: 'crash', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise, timeout?: number } | ((page: Page) => boolean | Promise)): Promise; /** * Emitted when a JavaScript dialog appears, such as `alert`, `prompt`, `confirm` or `beforeunload`. Listener **must** @@ -4848,19 +4848,19 @@ export interface Page { * listeners are present, all dialogs are automatically dismissed. * */ - waitForEvent(event: 'dialog', optionsOrPredicate?: { predicate?: (dialog: Dialog) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((dialog: Dialog) => boolean | Promise)): Promise; + waitForEvent(event: 'dialog', optionsOrPredicate?: { predicate?: (dialog: Dialog) => boolean | Promise, timeout?: number } | ((dialog: Dialog) => boolean | Promise)): Promise; /** * Emitted when the JavaScript * [`DOMContentLoaded`](https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded) event is dispatched. */ - waitForEvent(event: 'domcontentloaded', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((page: Page) => boolean | Promise)): Promise; + waitForEvent(event: 'domcontentloaded', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise, timeout?: number } | ((page: Page) => boolean | Promise)): Promise; /** * Emitted when attachment download started. User can access basic file operations on downloaded content via the * passed [Download](https://playwright.dev/docs/api/class-download) instance. */ - waitForEvent(event: 'download', optionsOrPredicate?: { predicate?: (download: Download) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((download: Download) => boolean | Promise)): Promise; + waitForEvent(event: 'download', optionsOrPredicate?: { predicate?: (download: Download) => boolean | Promise, timeout?: number } | ((download: Download) => boolean | Promise)): Promise; /** * Emitted when a file chooser is supposed to appear, such as after clicking the ``. Playwright can @@ -4875,27 +4875,27 @@ export interface Page { * ``` * */ - waitForEvent(event: 'filechooser', optionsOrPredicate?: { predicate?: (fileChooser: FileChooser) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((fileChooser: FileChooser) => boolean | Promise)): Promise; + waitForEvent(event: 'filechooser', optionsOrPredicate?: { predicate?: (fileChooser: FileChooser) => boolean | Promise, timeout?: number } | ((fileChooser: FileChooser) => boolean | Promise)): Promise; /** * Emitted when a frame is attached. */ - waitForEvent(event: 'frameattached', optionsOrPredicate?: { predicate?: (frame: Frame) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((frame: Frame) => boolean | Promise)): Promise; + waitForEvent(event: 'frameattached', optionsOrPredicate?: { predicate?: (frame: Frame) => boolean | Promise, timeout?: number } | ((frame: Frame) => boolean | Promise)): Promise; /** * Emitted when a frame is detached. */ - waitForEvent(event: 'framedetached', optionsOrPredicate?: { predicate?: (frame: Frame) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((frame: Frame) => boolean | Promise)): Promise; + waitForEvent(event: 'framedetached', optionsOrPredicate?: { predicate?: (frame: Frame) => boolean | Promise, timeout?: number } | ((frame: Frame) => boolean | Promise)): Promise; /** * Emitted when a frame is navigated to a new url. */ - waitForEvent(event: 'framenavigated', optionsOrPredicate?: { predicate?: (frame: Frame) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((frame: Frame) => boolean | Promise)): Promise; + waitForEvent(event: 'framenavigated', optionsOrPredicate?: { predicate?: (frame: Frame) => boolean | Promise, timeout?: number } | ((frame: Frame) => boolean | Promise)): Promise; /** * Emitted when the JavaScript [`load`](https://developer.mozilla.org/en-US/docs/Web/Events/load) event is dispatched. */ - waitForEvent(event: 'load', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((page: Page) => boolean | Promise)): Promise; + waitForEvent(event: 'load', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise, timeout?: number } | ((page: Page) => boolean | Promise)): Promise; /** * Emitted when an uncaught exception happens within the page. @@ -4911,7 +4911,7 @@ export interface Page { * ``` * */ - waitForEvent(event: 'pageerror', optionsOrPredicate?: { predicate?: (error: Error) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((error: Error) => boolean | Promise)): Promise; + waitForEvent(event: 'pageerror', optionsOrPredicate?: { predicate?: (error: Error) => boolean | Promise, timeout?: number } | ((error: Error) => boolean | Promise)): Promise; /** * Emitted when the page opens a new tab or window. This event is emitted in addition to the @@ -4940,14 +4940,14 @@ export interface Page { * wait until the page gets to a particular state (you should not need it in most cases). * */ - waitForEvent(event: 'popup', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((page: Page) => boolean | Promise)): Promise; + waitForEvent(event: 'popup', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise, timeout?: number } | ((page: Page) => boolean | Promise)): Promise; /** * Emitted when a page issues a request. The [request] object is read-only. In order to intercept and mutate requests, * see [page.route(url, handler[, options])](https://playwright.dev/docs/api/class-page#page-route) or * [browserContext.route(url, handler[, options])](https://playwright.dev/docs/api/class-browsercontext#browser-context-route). */ - waitForEvent(event: 'request', optionsOrPredicate?: { predicate?: (request: Request) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((request: Request) => boolean | Promise)): Promise; + waitForEvent(event: 'request', optionsOrPredicate?: { predicate?: (request: Request) => boolean | Promise, timeout?: number } | ((request: Request) => boolean | Promise)): Promise; /** * Emitted when a request fails, for example by timing out. @@ -4966,30 +4966,30 @@ export interface Page { * error net::ERR_FAILED. * */ - waitForEvent(event: 'requestfailed', optionsOrPredicate?: { predicate?: (request: Request) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((request: Request) => boolean | Promise)): Promise; + waitForEvent(event: 'requestfailed', optionsOrPredicate?: { predicate?: (request: Request) => boolean | Promise, timeout?: number } | ((request: Request) => boolean | Promise)): Promise; /** * Emitted when a request finishes successfully after downloading the response body. For a successful response, the * sequence of events is `request`, `response` and `requestfinished`. */ - waitForEvent(event: 'requestfinished', optionsOrPredicate?: { predicate?: (request: Request) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((request: Request) => boolean | Promise)): Promise; + waitForEvent(event: 'requestfinished', optionsOrPredicate?: { predicate?: (request: Request) => boolean | Promise, timeout?: number } | ((request: Request) => boolean | Promise)): Promise; /** * Emitted when [response] status and headers are received for a request. For a successful response, the sequence of * events is `request`, `response` and `requestfinished`. */ - waitForEvent(event: 'response', optionsOrPredicate?: { predicate?: (response: Response) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((response: Response) => boolean | Promise)): Promise; + waitForEvent(event: 'response', optionsOrPredicate?: { predicate?: (response: Response) => boolean | Promise, timeout?: number } | ((response: Response) => boolean | Promise)): Promise; /** * Emitted when [WebSocket](https://playwright.dev/docs/api/class-websocket) request is sent. */ - waitForEvent(event: 'websocket', optionsOrPredicate?: { predicate?: (webSocket: WebSocket) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((webSocket: WebSocket) => boolean | Promise)): Promise; + waitForEvent(event: 'websocket', optionsOrPredicate?: { predicate?: (webSocket: WebSocket) => boolean | Promise, timeout?: number } | ((webSocket: WebSocket) => boolean | Promise)): Promise; /** * Emitted when a dedicated [WebWorker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) is spawned * by the page. */ - waitForEvent(event: 'worker', optionsOrPredicate?: { predicate?: (worker: Worker) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((worker: Worker) => boolean | Promise)): Promise; + waitForEvent(event: 'worker', optionsOrPredicate?: { predicate?: (worker: Worker) => boolean | Promise, timeout?: number } | ((worker: Worker) => boolean | Promise)): Promise; /** @@ -5026,14 +5026,6 @@ export interface Page { * @param options */ waitForLoadState(state?: "load"|"domcontentloaded"|"networkidle", options?: { - /** - * Allows to cancel the waiting using an - * [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). If the signal is aborted, the - * waiting will be aborted and the operation will throw an error. Note that providing a signal does not disable the - * default timeout; pass `timeout: 0` to disable the timeout entirely. - */ - signal?: AbortSignal; - /** * Maximum operation time in milliseconds. Defaults to `0` - no timeout. The default value can be changed via * `navigationTimeout` option in the config, or by using the @@ -5071,14 +5063,6 @@ export interface Page { * @param options */ waitForNavigation(options?: { - /** - * Allows to cancel the waiting using an - * [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). If the signal is aborted, the - * waiting will be aborted and the operation will throw an error. Note that providing a signal does not disable the - * default timeout; pass `timeout: 0` to disable the timeout entirely. - */ - signal?: AbortSignal; - /** * Maximum operation time in milliseconds. Defaults to `0` - no timeout. The default value can be changed via * `navigationTimeout` option in the config, or by using the @@ -5132,14 +5116,6 @@ export interface Page { * @param options */ waitForRequest(urlOrPredicate: string|RegExp|((request: Request) => boolean|Promise), options?: { - /** - * Allows to cancel the waiting using an - * [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). If the signal is aborted, the - * waiting will be aborted and the operation will throw an error. Note that providing a signal does not disable the - * default timeout; pass `timeout: 0` to disable the timeout entirely. - */ - signal?: AbortSignal; - /** * Maximum wait time in milliseconds, defaults to 30 seconds, pass `0` to disable the timeout. The default value can * be changed by using the @@ -5176,14 +5152,6 @@ export interface Page { * @param options */ waitForResponse(urlOrPredicate: string|RegExp|((response: Response) => boolean|Promise), options?: { - /** - * Allows to cancel the waiting using an - * [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). If the signal is aborted, the - * waiting will be aborted and the operation will throw an error. Note that providing a signal does not disable the - * default timeout; pass `timeout: 0` to disable the timeout entirely. - */ - signal?: AbortSignal; - /** * Maximum wait time in milliseconds, defaults to 30 seconds, pass `0` to disable the timeout. The default value can * be changed by using the @@ -5230,14 +5198,6 @@ export interface Page { * @param options */ waitForURL(url: string|RegExp|URLPattern|((url: URL) => boolean), options?: { - /** - * Allows to cancel the waiting using an - * [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). If the signal is aborted, the - * waiting will be aborted and the operation will throw an error. Note that providing a signal does not disable the - * default timeout; pass `timeout: 0` to disable the timeout entirely. - */ - signal?: AbortSignal; - /** * Maximum operation time in milliseconds. Defaults to `0` - no timeout. The default value can be changed via * `navigationTimeout` option in the config, or by using the @@ -8063,14 +8023,6 @@ export interface Frame { * @param options */ waitForLoadState(state?: "load"|"domcontentloaded"|"networkidle", options?: { - /** - * Allows to cancel the waiting using an - * [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). If the signal is aborted, the - * waiting will be aborted and the operation will throw an error. Note that providing a signal does not disable the - * default timeout; pass `timeout: 0` to disable the timeout entirely. - */ - signal?: AbortSignal; - /** * Maximum operation time in milliseconds. Defaults to `0` - no timeout. The default value can be changed via * `navigationTimeout` option in the config, or by using the @@ -8107,14 +8059,6 @@ export interface Frame { * @param options */ waitForNavigation(options?: { - /** - * Allows to cancel the waiting using an - * [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). If the signal is aborted, the - * waiting will be aborted and the operation will throw an error. Note that providing a signal does not disable the - * default timeout; pass `timeout: 0` to disable the timeout entirely. - */ - signal?: AbortSignal; - /** * Maximum operation time in milliseconds. Defaults to `0` - no timeout. The default value can be changed via * `navigationTimeout` option in the config, or by using the @@ -8173,14 +8117,6 @@ export interface Frame { * @param options */ waitForURL(url: string|RegExp|URLPattern|((url: URL) => boolean), options?: { - /** - * Allows to cancel the waiting using an - * [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). If the signal is aborted, the - * waiting will be aborted and the operation will throw an error. Note that providing a signal does not disable the - * default timeout; pass `timeout: 0` to disable the timeout entirely. - */ - signal?: AbortSignal; - /** * Maximum operation time in milliseconds. Defaults to `0` - no timeout. The default value can be changed via * `navigationTimeout` option in the config, or by using the @@ -9787,7 +9723,7 @@ export interface BrowserContext { /** * This event is not emitted. */ - waitForEvent(event: 'backgroundpage', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((page: Page) => boolean | Promise)): Promise; + waitForEvent(event: 'backgroundpage', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise, timeout?: number } | ((page: Page) => boolean | Promise)): Promise; /** * Emitted when Browser context gets closed. This might happen because of one of the following: @@ -9795,7 +9731,7 @@ export interface BrowserContext { * - Browser application is closed or crashed. * - The [browser.close([options])](https://playwright.dev/docs/api/class-browser#browser-close) method was called. */ - waitForEvent(event: 'close', optionsOrPredicate?: { predicate?: (browserContext: BrowserContext) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((browserContext: BrowserContext) => boolean | Promise)): Promise; + waitForEvent(event: 'close', optionsOrPredicate?: { predicate?: (browserContext: BrowserContext) => boolean | Promise, timeout?: number } | ((browserContext: BrowserContext) => boolean | Promise)): Promise; /** * Emitted when JavaScript within the page calls one of console API methods, e.g. `console.log` or `console.dir`. @@ -9816,7 +9752,7 @@ export interface BrowserContext { * ``` * */ - waitForEvent(event: 'console', optionsOrPredicate?: { predicate?: (consoleMessage: ConsoleMessage) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((consoleMessage: ConsoleMessage) => boolean | Promise)): Promise; + waitForEvent(event: 'console', optionsOrPredicate?: { predicate?: (consoleMessage: ConsoleMessage) => boolean | Promise, timeout?: number } | ((consoleMessage: ConsoleMessage) => boolean | Promise)): Promise; /** * Emitted when a JavaScript dialog appears, such as `alert`, `prompt`, `confirm` or `beforeunload`. Listener **must** @@ -9838,7 +9774,7 @@ export interface BrowserContext { * listeners are present, all dialogs are automatically dismissed. * */ - waitForEvent(event: 'dialog', optionsOrPredicate?: { predicate?: (dialog: Dialog) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((dialog: Dialog) => boolean | Promise)): Promise; + waitForEvent(event: 'dialog', optionsOrPredicate?: { predicate?: (dialog: Dialog) => boolean | Promise, timeout?: number } | ((dialog: Dialog) => boolean | Promise)): Promise; /** * Emitted when attachment download started in any page belonging to this context. User can access basic file @@ -9846,28 +9782,28 @@ export interface BrowserContext { * instance. See also [page.on('download')](https://playwright.dev/docs/api/class-page#page-event-download) to receive * events about a specific page. */ - waitForEvent(event: 'download', optionsOrPredicate?: { predicate?: (download: Download) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((download: Download) => boolean | Promise)): Promise; + waitForEvent(event: 'download', optionsOrPredicate?: { predicate?: (download: Download) => boolean | Promise, timeout?: number } | ((download: Download) => boolean | Promise)): Promise; /** * Emitted when a frame is attached in any page belonging to this context. See also * [page.on('frameattached')](https://playwright.dev/docs/api/class-page#page-event-frame-attached) to receive events * about a specific page. */ - waitForEvent(event: 'frameattached', optionsOrPredicate?: { predicate?: (frame: Frame) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((frame: Frame) => boolean | Promise)): Promise; + waitForEvent(event: 'frameattached', optionsOrPredicate?: { predicate?: (frame: Frame) => boolean | Promise, timeout?: number } | ((frame: Frame) => boolean | Promise)): Promise; /** * Emitted when a frame is detached in any page belonging to this context. See also * [page.on('framedetached')](https://playwright.dev/docs/api/class-page#page-event-frame-detached) to receive events * about a specific page. */ - waitForEvent(event: 'framedetached', optionsOrPredicate?: { predicate?: (frame: Frame) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((frame: Frame) => boolean | Promise)): Promise; + waitForEvent(event: 'framedetached', optionsOrPredicate?: { predicate?: (frame: Frame) => boolean | Promise, timeout?: number } | ((frame: Frame) => boolean | Promise)): Promise; /** * Emitted when a frame is navigated to a new url in any page belonging to this context. See also * [page.on('framenavigated')](https://playwright.dev/docs/api/class-page#page-event-frame-navigated) to receive * events about navigations in a specific page. */ - waitForEvent(event: 'framenavigated', optionsOrPredicate?: { predicate?: (frame: Frame) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((frame: Frame) => boolean | Promise)): Promise; + waitForEvent(event: 'framenavigated', optionsOrPredicate?: { predicate?: (frame: Frame) => boolean | Promise, timeout?: number } | ((frame: Frame) => boolean | Promise)): Promise; /** * The event is emitted when a new Page is created in the BrowserContext. The page may still be loading. The event @@ -9896,14 +9832,14 @@ export interface BrowserContext { * wait until the page gets to a particular state (you should not need it in most cases). * */ - waitForEvent(event: 'page', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((page: Page) => boolean | Promise)): Promise; + waitForEvent(event: 'page', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise, timeout?: number } | ((page: Page) => boolean | Promise)): Promise; /** * Emitted when a page in this context is closed. See also * [page.on('close')](https://playwright.dev/docs/api/class-page#page-event-close) to receive events about a specific * page. */ - waitForEvent(event: 'pageclose', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((page: Page) => boolean | Promise)): Promise; + waitForEvent(event: 'pageclose', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise, timeout?: number } | ((page: Page) => boolean | Promise)): Promise; /** * Emitted when the JavaScript [`load`](https://developer.mozilla.org/en-US/docs/Web/Events/load) event is dispatched @@ -9911,7 +9847,7 @@ export interface BrowserContext { * [page.on('load')](https://playwright.dev/docs/api/class-page#page-event-load) to receive events about a specific * page. */ - waitForEvent(event: 'pageload', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((page: Page) => boolean | Promise)): Promise; + waitForEvent(event: 'pageload', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise, timeout?: number } | ((page: Page) => boolean | Promise)): Promise; /** * Emitted when a request is issued from any pages created through this context. The [request] object is read-only. To @@ -9922,7 +9858,7 @@ export interface BrowserContext { * [browserContext.route(url, handler[, options])](https://playwright.dev/docs/api/class-browsercontext#browser-context-route) * or [page.route(url, handler[, options])](https://playwright.dev/docs/api/class-page#page-route). */ - waitForEvent(event: 'request', optionsOrPredicate?: { predicate?: (request: Request) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((request: Request) => boolean | Promise)): Promise; + waitForEvent(event: 'request', optionsOrPredicate?: { predicate?: (request: Request) => boolean | Promise, timeout?: number } | ((request: Request) => boolean | Promise)): Promise; /** * Emitted when a request fails, for example by timing out. To only listen for failed requests from a particular page, @@ -9935,7 +9871,7 @@ export interface BrowserContext { * [browserContext.on('requestfailed')](https://playwright.dev/docs/api/class-browsercontext#browser-context-event-request-failed). * */ - waitForEvent(event: 'requestfailed', optionsOrPredicate?: { predicate?: (request: Request) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((request: Request) => boolean | Promise)): Promise; + waitForEvent(event: 'requestfailed', optionsOrPredicate?: { predicate?: (request: Request) => boolean | Promise, timeout?: number } | ((request: Request) => boolean | Promise)): Promise; /** * Emitted when a request finishes successfully after downloading the response body. For a successful response, the @@ -9943,27 +9879,27 @@ export interface BrowserContext { * particular page, use * [page.on('requestfinished')](https://playwright.dev/docs/api/class-page#page-event-request-finished). */ - waitForEvent(event: 'requestfinished', optionsOrPredicate?: { predicate?: (request: Request) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((request: Request) => boolean | Promise)): Promise; + waitForEvent(event: 'requestfinished', optionsOrPredicate?: { predicate?: (request: Request) => boolean | Promise, timeout?: number } | ((request: Request) => boolean | Promise)): Promise; /** * Emitted when [response] status and headers are received for a request. For a successful response, the sequence of * events is `request`, `response` and `requestfinished`. To listen for response events from a particular page, use * [page.on('response')](https://playwright.dev/docs/api/class-page#page-event-response). */ - waitForEvent(event: 'response', optionsOrPredicate?: { predicate?: (response: Response) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((response: Response) => boolean | Promise)): Promise; + waitForEvent(event: 'response', optionsOrPredicate?: { predicate?: (response: Response) => boolean | Promise, timeout?: number } | ((response: Response) => boolean | Promise)): Promise; /** * **NOTE** Service workers are only supported on Chromium-based browsers. * * Emitted when new service worker is created in the context. */ - waitForEvent(event: 'serviceworker', optionsOrPredicate?: { predicate?: (worker: Worker) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((worker: Worker) => boolean | Promise)): Promise; + waitForEvent(event: 'serviceworker', optionsOrPredicate?: { predicate?: (worker: Worker) => boolean | Promise, timeout?: number } | ((worker: Worker) => boolean | Promise)): Promise; /** * Emitted when exception is unhandled in any of the pages in this context. To listen for errors from a particular * page, use [page.on('pageerror')](https://playwright.dev/docs/api/class-page#page-event-page-error) instead. */ - waitForEvent(event: 'weberror', optionsOrPredicate?: { predicate?: (webError: WebError) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((webError: WebError) => boolean | Promise)): Promise; + waitForEvent(event: 'weberror', optionsOrPredicate?: { predicate?: (webError: WebError) => boolean | Promise, timeout?: number } | ((webError: WebError) => boolean | Promise)): Promise; /** @@ -10930,12 +10866,12 @@ export interface Worker { * Emitted when this dedicated [WebWorker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) is * terminated. */ - waitForEvent(event: 'close', optionsOrPredicate?: { predicate?: (worker: Worker) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((worker: Worker) => boolean | Promise)): Promise; + waitForEvent(event: 'close', optionsOrPredicate?: { predicate?: (worker: Worker) => boolean | Promise, timeout?: number } | ((worker: Worker) => boolean | Promise)): Promise; /** * Emitted when JavaScript within the worker calls one of console API methods, e.g. `console.log` or `console.dir`. */ - waitForEvent(event: 'console', optionsOrPredicate?: { predicate?: (consoleMessage: ConsoleMessage) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((consoleMessage: ConsoleMessage) => boolean | Promise)): Promise; + waitForEvent(event: 'console', optionsOrPredicate?: { predicate?: (consoleMessage: ConsoleMessage) => boolean | Promise, timeout?: number } | ((consoleMessage: ConsoleMessage) => boolean | Promise)): Promise; } @@ -17178,7 +17114,7 @@ export interface ElectronApplication { /** * This event is issued when the application process has been terminated. */ - waitForEvent(event: 'close', optionsOrPredicate?: { predicate?: () => boolean | Promise, timeout?: number, signal?: AbortSignal } | (() => boolean | Promise)): Promise; + waitForEvent(event: 'close', optionsOrPredicate?: { predicate?: () => boolean | Promise, timeout?: number } | (() => boolean | Promise)): Promise; /** * Emitted when JavaScript within the Electron main process calls one of console API methods, e.g. `console.log` or @@ -17200,13 +17136,13 @@ export interface ElectronApplication { * ``` * */ - waitForEvent(event: 'console', optionsOrPredicate?: { predicate?: (consoleMessage: ConsoleMessage) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((consoleMessage: ConsoleMessage) => boolean | Promise)): Promise; + waitForEvent(event: 'console', optionsOrPredicate?: { predicate?: (consoleMessage: ConsoleMessage) => boolean | Promise, timeout?: number } | ((consoleMessage: ConsoleMessage) => boolean | Promise)): Promise; /** * This event is issued for every window that is created **and loaded** in Electron. It contains a * [Page](https://playwright.dev/docs/api/class-page) that can be used for Playwright automation. */ - waitForEvent(event: 'window', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((page: Page) => boolean | Promise)): Promise; + waitForEvent(event: 'window', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise, timeout?: number } | ((page: Page) => boolean | Promise)): Promise; /** @@ -21708,7 +21644,7 @@ export interface WebSocket { /** * Fired when the websocket closes. */ - waitForEvent(event: 'close', optionsOrPredicate?: { predicate?: (webSocket: WebSocket) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((webSocket: WebSocket) => boolean | Promise)): Promise; + waitForEvent(event: 'close', optionsOrPredicate?: { predicate?: (webSocket: WebSocket) => boolean | Promise, timeout?: number } | ((webSocket: WebSocket) => boolean | Promise)): Promise; /** * Fired when the websocket receives a frame. @@ -21718,7 +21654,7 @@ export interface WebSocket { * frame payload */ payload: string|Buffer; - }) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((data: { + }) => boolean | Promise, timeout?: number } | ((data: { /** * frame payload */ @@ -21738,7 +21674,7 @@ export interface WebSocket { * frame payload */ payload: string|Buffer; - }) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((data: { + }) => boolean | Promise, timeout?: number } | ((data: { /** * frame payload */ @@ -21753,7 +21689,7 @@ export interface WebSocket { /** * Fired when the websocket has an error. */ - waitForEvent(event: 'socketerror', optionsOrPredicate?: { predicate?: (string: string) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((string: string) => boolean | Promise)): Promise; + waitForEvent(event: 'socketerror', optionsOrPredicate?: { predicate?: (string: string) => boolean | Promise, timeout?: number } | ((string: string) => boolean | Promise)): Promise; } @@ -23100,12 +23036,12 @@ export interface AndroidDevice { /** * Emitted when the device connection gets closed. */ - waitForEvent(event: 'close', optionsOrPredicate?: { predicate?: (androidDevice: AndroidDevice) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((androidDevice: AndroidDevice) => boolean | Promise)): Promise; + waitForEvent(event: 'close', optionsOrPredicate?: { predicate?: (androidDevice: AndroidDevice) => boolean | Promise, timeout?: number } | ((androidDevice: AndroidDevice) => boolean | Promise)): Promise; /** * Emitted when a new WebView instance is detected. */ - waitForEvent(event: 'webview', optionsOrPredicate?: { predicate?: (androidWebView: AndroidWebView) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((androidWebView: AndroidWebView) => boolean | Promise)): Promise; + waitForEvent(event: 'webview', optionsOrPredicate?: { predicate?: (androidWebView: AndroidWebView) => boolean | Promise, timeout?: number } | ((androidWebView: AndroidWebView) => boolean | Promise)): Promise; /** diff --git a/tests/page/page-filechooser.spec.ts b/tests/page/page-filechooser.spec.ts index 9fef3a6925da7..6c4262e41d74e 100644 --- a/tests/page/page-filechooser.spec.ts +++ b/tests/page/page-filechooser.spec.ts @@ -218,13 +218,6 @@ test('should work with no timeout', async ({ page, server }) => { expect(chooser).toBeTruthy(); }); -test('should abort with signal', async ({ page }) => { - const controller = new AbortController(); - const promise = page.waitForEvent('filechooser', { signal: controller.signal }); - controller.abort('Aborted by user'); - await expect(promise).rejects.toThrow('Aborted by user'); -}); - test('should return the same file chooser when there are many watchdogs simultaneously', async ({ page, server }) => { await page.setContent(``); const [fileChooser1, fileChooser2] = await Promise.all([ diff --git a/utils/generate_types/index.js b/utils/generate_types/index.js index c0cf8c46b9460..dc811837eb808 100644 --- a/utils/generate_types/index.js +++ b/utils/generate_types/index.js @@ -288,7 +288,7 @@ class TypesGenerator { for (const { eventName, params, comment, type } of eventDescriptions) { if (comment) parts.push(this.writeComment(comment, indent)); - parts.push(` ${member.alias}(event: '${eventName}', optionsOrPredicate?: { predicate?: (${params}) => boolean | Promise, timeout?: number, signal?: AbortSignal } | ((${params}) => boolean | Promise)): Promise<${type}>;\n`); + parts.push(` ${member.alias}(event: '${eventName}', optionsOrPredicate?: { predicate?: (${params}) => boolean | Promise, timeout?: number } | ((${params}) => boolean | Promise)): Promise<${type}>;\n`); } return parts.join('\n');