Skip to content

fix: prevent duplicate character insertion in press_key() for contenteditable#346

Open
TheMapleBin wants to merge 1 commit into
browser-use:mainfrom
TheMapleBin:fix/press-key-duplicate-insertion
Open

fix: prevent duplicate character insertion in press_key() for contenteditable#346
TheMapleBin wants to merge 1 commit into
browser-use:mainfrom
TheMapleBin:fix/press-key-duplicate-insertion

Conversation

@TheMapleBin
Copy link
Copy Markdown

@TheMapleBin TheMapleBin commented May 12, 2026

Summary

  • press_key() currently sends text on both keyDown and char CDP events.
  • Chrome's editing handler may insert text during both phases in contenteditable elements.
  • Result: every typed character can appear twice, for example 你好你你好好.

Fix

Remove text from the keyDown event. The char event, which immediately follows, remains the insertion-bearing event.

This preserves the keyDown / keyUp pair for listeners that watch raw keyboard events while ensuring printable text is inserted only once.

Test

Example case:

<div id="ce" contenteditable="true"></div>

fill_input("#ce", "你好测试")
assert js("return document.getElementById('ce').textContent") == "你好测试"

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Fix duplicate character insertion when typing into contenteditable elements.

- **Bug Fixes**
  - Only `char` events carry text in `press_key()`; `keyDown` no longer sends `text` via `Input.dispatchKeyEvent`.
  - Prevents double characters in Chromium contenteditable and keeps `keyDown`/`keyUp` for listeners.

<sup>Written for commit c6f16f2548e2dd3ef442d38ce1aa410180cf01cc. Summary will update on new commits.</sup>

<!-- End of auto-generated description by cubic. -->

…editable

press_key() was sending printable text through both keyDown(text=...) and char(text=...).

For contenteditable elements, Chromium may insert text during both phases, causing each character to appear twice.

This removes text from the keyDown event and keeps the char event as the only insertion-bearing event.
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 1 file

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