Skip to content

fix(helpers): make press_key handle keyboard shortcuts#332

Open
immanuwell wants to merge 1 commit into
browser-use:mainfrom
immanuwell:fix/press-key-shortcuts-small
Open

fix(helpers): make press_key handle keyboard shortcuts#332
immanuwell wants to merge 1 commit into
browser-use:mainfrom
immanuwell:fix/press-key-shortcuts-small

Conversation

@immanuwell
Copy link
Copy Markdown

@immanuwell immanuwell commented May 10, 2026

What

Tiny fix for press_key() shortcuts. Ctrl/Cmd/Alt combos should not send printable text, and letter/digit keys need Chrome-style metadata like KeyA / 65.

No big rewrite, just the busted bit.

Repro

from unittest.mock import patch
from browser_harness import helpers

calls = []
with patch("browser_harness.helpers.cdp", side_effect=lambda m, **kw: calls.append(kw) or {}):
    helpers.press_key("a", modifiers=2)
print(calls)

Before: keyDown text="a", then a char event, with code="a" and vk 97. In real Chrome, textarea abc + Ctrl+A + type_text("x") does not select cleanly. kinda cooked.

After: only keyDown/keyUp, code="KeyA", vk 65; the same Chrome smoke ends with x.

Checks

  • uv run --with pytest pytest -q
  • real headless Chrome CDP smoke for Ctrl+A in a textarea

Related: #297, same edge; this is the smaller patch.


Summary by cubic

Fix press_key to handle keyboard shortcuts correctly. Modifiers no longer emit printable text, and letters/digits now include Chrome-style code and VK metadata.

  • Bug Fixes
    • Suppress text/char events when Alt/Ctrl/Meta modifiers are present.
    • Map letters to KeyX and digits to DigitN with correct windowsVirtualKeyCode.
    • Added unit tests for Ctrl+letter, letter, and digit cases.

Written for commit 33cf31c. Summary will update on new commits.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant