feat(keyboard): add pressSequence() for batched key presses#40734
Closed
SebTardif wants to merge 2 commits into
Closed
feat(keyboard): add pressSequence() for batched key presses#40734SebTardif wants to merge 2 commits into
SebTardif wants to merge 2 commits into
Conversation
Member
|
It is best to start with filing an issue, please see contributors' guide |
Contributor
Author
|
Filed #40740 as requested. |
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
keyboard.pressSequence(keys, options)to press an array of named keys in a single protocol round-tripkeyboard.type()for charactersMotivation
keyboard.type("hello")batches character-level key presses into a single protocol message, with all character events processed server-side. There is no equivalent for named keys (Space,ArrowDown,Enter, etc.).When automating keyboard-driven interactions like drag-and-drop via accessibility patterns (Space to grab, Arrow keys to move, Space to drop) or multi-step form navigation, each
keyboard.press()call requires a separate protocol round-trip:This is particularly relevant for:
Keyboard-based drag-and-drop: Mouse-based
dragTo()does not work with popular DnD libraries like react-beautiful-dnd and dnd-kit (#13855, #35749). The common workaround is keyboard-based reordering (Space/Arrow/Space), which requires multiple sequentialkeyboard.press()calls.AI browser agents: Tools like browser-use, Playwright MCP, and other automation agents rely heavily on keyboard sequences for form navigation. Each
keyboard.press()call incurs protocol serialization + WebSocket frame + async scheduling overhead, which compounds in tight loops. See browser-use#4683 for a related request about faster input clearing.Remote automation: When Playwright connects to a remote browser via
connect()orconnect_over_cdp(), network latency amplifies per-call overhead from ~5-10ms locally to 50-200ms per call. A 5-key drag sequence goes from ~250ms to ~1s of pure overhead.Unlike
evaluateAllalternatives, this cannot be replicated withpage.evaluate(): CDP keyboard events go through the browser's native input pipeline (Input.dispatchKeyEvent), triggering IME, contenteditable, autocomplete, and framework-specific event handlers that syntheticdispatchEvent()calls do not.API
Implementation
Follows the standard 6-step API addition process: docs, client, protocol, dispatcher, server, tests. The server-side
pressSequence()method iterates the key array and delegates each press to the existingpress()method, applying the delay between consecutive presses. 7 tests covering: basic sequencing, delay timing, empty/single arrays, modifier combos, event ordering, and invalid key error handling.