Repository navigation
[fix]: report key/code on keydown for printable keyPress keys - #3110
Open
antonvishal wants to merge 5 commits into
Open
antonvishal wants to merge 5 commits into
antonvishal wants to merge 5 commits into
Conversation
keyPress sent printable keys as text-only keyDown events, so keydown listeners saw an empty key and code. Send the physical key with US-layout VKs; ASCII-derived VKs would make punctuation run editing commands such as Delete and the arrow keys. Co-authored-by: Cursor <cursoragent@cursor.com>
🦋 Changeset detectedLatest commit: 6ffe393 The changes in this PR will be included in the next version bump. This PR includes changesets to release 24 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
|
This PR is from an external contributor and must be approved by a stagehand team member with write access before CI can run. |
antonvishal
marked this pull request as ready for review
October 5, 2026 18:59
# Conflicts: # packages/sdk-go/internal/extensionassets/stagehand-extension.zip
# Conflicts: # packages/sdk-go/internal/extensionassets/stagehand-extension.zip
# Conflicts: # packages/sdk-go/internal/extensionassets/stagehand-extension.zip
# Conflicts: # packages/sdk-go/internal/extensionassets/stagehand-extension.zip
This branch has not been deployed
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.
why
I was navigating across https://teleoperator.mindblown.ai/?mb=game (a browser game driven with WASD-style keys) and found that Stagehand's key presses didn't move anything. This PR fixes that.
The real bug:
page.keyPress("w")(andlocator.press, which uses it) sent printable keys as a text-onlykeyDown, with nokey,code, or virtual key code. Text still landed in inputs, butkeydownlisteners saw an empty key. Measured in Chrome onmain:keycodekeyCode""""0"w""KeyW"87Games, shortcut handlers, and anything else reading
event.key/event.codeonkeydownignored the press.what changed
key,code, andwindowsVirtualKeyCodeonkeyDown, alongside the text, the same way Playwright does..isPeriod/190,(isDigit9/57). The old helper derived them from ASCII, which is wrong and harmful once sent onkeyDown: Chromium runs editing commands from the key code, so.(46) acted as Delete and( % & ' $ #acted as the arrow keys, Home, and End. I hit this regression while writing the first version of the fix, and the integration test below guards against it.é) send nocodeor key code, so they can't trigger editing commands.event.keymatches the character typed ("W"forkeyPress("W")). Shortcuts still report the unshifted letter (Control+Agives"a"), as a physical keyboard does.test plan
packages/extension/tests/page-keyboard.test.ts(new): exact CDP events for letters, digits, space, punctuation, non-US characters, and shortcuts.keyboard.test.tsintegration:keydownreportskey/code, and. ( % $ # 'insert at the caret instead of moving it or deleting. Fails onmain, passes here.facade-frames.test.ts:locator.press("w", {delay})and"w+a"reportKeyW/KeyAwith the delay honored, in same-origin and out-of-process iframes.+, etc.) still pass.Summary by cubic
Fixes
page.keyPressandlocator.presssokeydownlisteners see the pressed key and code instead of an empty string, leaving keyboard-driven games and shortcut handlers unresponsive.Bug Fixes
key,code, andwindowsVirtualKeyCodeonkeyDown, matching Playwright behavior..trigger Delete and( % & ' $ #trigger arrow/Home/End editing commands in Chromium.é) send no code or VK so they can't trigger editing commands.Written for commit 6ffe393. Summary will update on new commits.