Prioritize click-to-focus for input_text action to trigger JS dropdowns#4284
Open
Adityakk9031 wants to merge 3 commits intobrowser-use:mainfrom
Open
Prioritize click-to-focus for input_text action to trigger JS dropdowns#4284Adityakk9031 wants to merge 3 commits intobrowser-use:mainfrom
Adityakk9031 wants to merge 3 commits intobrowser-use:mainfrom
Conversation
Author
|
@ShawnPana have a look |
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.
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.
Written for commit 749930a. Summary will update on new commits.