feat: support AbortSignal on server-side methods#41141
Open
Skn0tt wants to merge 2 commits into
Open
Conversation
Adds a client-only `signal` option that aborts an in-flight server operation via a new fire-and-forget `__cancel__` message, which aborts the call's ProgressController in the dispatcher. Wires it up on Locator.click and Locator.waitFor as a starting point. Fixes: microsoft#40578
Adds the signal option next to every existing timeout option on action, getter and navigation methods, threading it through the client so in-flight calls can be cancelled via the __cancel__ wire message. Refs: microsoft#40578
Contributor
Test results for "MCP"7230 passed, 1103 skipped Merge workflow run. |
Contributor
Test results for "tests 1"3 flaky39554 passed, 771 skipped Merge workflow run. |
Skn0tt
commented
Jun 5, 2026
| throw new Error('The object has been collected to prevent unbounded heap growth.'); | ||
|
|
||
| const signal = options.signal; | ||
| if (signal?.aborted) |
Member
Author
There was a problem hiding this comment.
Suggested change
| if (signal?.aborted) | |
| signal?.throwIfAborted(); |
dgozman
reviewed
Jun 5, 2026
| - `signal` <[AbortSignal]> | ||
|
|
||
| Allows to cancel the operation using an [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). If the signal is aborted, the operation will be aborted and throw an error. | ||
| Note that providing a signal does not disable the default timeout; pass `timeout: 0` to disable the timeout entirely. |
Collaborator
There was a problem hiding this comment.
Let's link to setDefaultTimeout here?
|
|
||
| async ariaSnapshot(options: TimeoutOptions & { mode?: 'ai' | 'default', depth?: number, boxes?: boolean, _track?: string } = {}): Promise<string> { | ||
| const result = await this.mainFrame()._channel.ariaSnapshot({ timeout: this._timeoutSettings.timeout(options), track: options._track, mode: options.mode, depth: options.depth, boxes: options.boxes }); | ||
| const result = await this.mainFrame()._channel.ariaSnapshot({ timeout: this._timeoutSettings.timeout(options), track: options._track, mode: options.mode, depth: options.depth, boxes: options.boxes, ...{ signal: options.signal } }); |
Collaborator
There was a problem hiding this comment.
How can we make sure that signal is passed for every method where it is defined? I think we are at least lacking signal option defined in many methods, and types like FetchOptions or ElectronOptions. Perhaps passing it explicitly as a second argument to generated channel methods is better? Or somehow ensuring in TypeScript that we pass non-optional AbortSignal | SomeSpecialSymbol to make sure it is always there.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
signal?: AbortSignaloption next to every existingtimeoutoption on action, getter and navigation methods.__cancel__wire message that aborts the dispatcher'sProgressController; a pre-aborted signal throwssignal.reasonsynchronously.AbortSignalsupport to client-side Waiter methods #41136 (Waiter-basedwaitFor*methods), which is excluded here as it already has signal support.Not included (follow-ups)
expectassertions (toBeVisible, etc.) — deferred to a separate PR.ElementHandle.inputValue— intentionally left out. UnlikeLocator/Page/Frame.inputValue(which route through theFrame.inputValueprotocol method that carriestimeout), theElementHandle.inputValueprotocol method (packages/protocol/spec/handles.yml) declares no parameters, so thetimeoutoption the public types have long advertised there is silently dropped by the wire validator. Addingsignalwould require a signature change and inherit that broken-timeout behavior. Fixing it is a separate change: addtimeout/signalto theinputValueentry inhandles.yml.Refs #40578