X Tutup
Skip to content

Prioritize click-to-focus for input_text action to trigger JS dropdowns#4284

Open
Adityakk9031 wants to merge 3 commits intobrowser-use:mainfrom
Adityakk9031:#4143
Open

Prioritize click-to-focus for input_text action to trigger JS dropdowns#4284
Adityakk9031 wants to merge 3 commits intobrowser-use:mainfrom
Adityakk9031:#4143

Conversation

@Adityakk9031
Copy link

@Adityakk9031 Adityakk9031 commented Mar 6, 2026

Fixes #4143

What is the issue?
When the agent uses the
input_text
action, it fails to open autocomplete dropdown menus on some modern websites (such as immigration applications), whereas a manual
click
followed by
type
works properly.

This happens because the underlying
_focus_element_simple
method prioritized CDP DOM.focus() over actual mouse clicks. Since DOM.focus() almost always succeeds, the input element never receives the mousedown, mouseup, or
click
events that many JS frameworks rely on to open their autocomplete lists.

What is the fix?
Reversed the focus priority in
_focus_element_simple
(both in
browser_use/browser/watchdogs/default_action_watchdog.py
and
browser_use/actor/element.py
).

If coordinates are available, the agent will now prioritize simulating a complete human click (sending mouseMoved, then mousePressed, then mouseReleased) before attempting CDP-based focus. This guarantees that event listeners bound to mouse actions are correctly triggered, allowing dropdowns to open just as they do during standard human interaction.

CDP DOM.focus() and JS .focus() remain intact as reliable fallbacks in case the click interaction fails or coordinates are missing.


Summary by cubic

Prioritizes click-to-focus for input_text so JS-driven autocomplete dropdowns open reliably. Fixes #4143 by simulating real mouse events before falling back to DOM focus, with JS focus as a last resort where applicable.

  • Bug Fixes
    • Reordered _focus_element_simple to click first when coordinates exist, sending mouseMoved → mousePressed → mouseReleased with 50ms delays to trigger event listeners.
    • Fallback order: CDP DOM.focus; JS this.focus as last resort in actor/element.py (watchdog falls back to CDP only).
    • Updated in browser_use/actor/element.py and browser_use/browser/watchdogs/default_action_watchdog.py.

Written for commit 749930a. Summary will update on new commits.

Copy link
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

@Adityakk9031
Copy link
Author

@ShawnPana have a look

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.

browser-use input action is not equal to click+type

1 participant

X Tutup