Thanks to visit codestin.com
Credit goes to github.com

Skip to content

#4143 Issue fix and test cases as well#4145

Open
hemant838 wants to merge 1 commit intobrowser-use:mainfrom
hemant838:input/fix
Open

#4143 Issue fix and test cases as well#4145
hemant838 wants to merge 1 commit intobrowser-use:mainfrom
hemant838:input/fix

Conversation

@hemant838
Copy link

@hemant838 hemant838 commented Feb 21, 2026

The Bug

The input action focuses elements using DOM.focus() — a CDP API that programmatically moves focus without firing mouse events. This is fine for normal text inputs, but many real-world
autocomplete/combobox widgets (Select2, MUI Autocomplete, Ant Design, etc.) bind their dropdown-open logic to mousedown/click events, not the focus event.

So when the agent does input(index=5, text="New York") on an autocomplete field:

  • DOM.focus() succeeds silently → text gets typed → but the dropdown never opens
  • The agent never sees suggestions to click on

When you manually do click then type, it works because click dispatches real mouse events (mousePressed → mouseReleased) which the widget's JS listens for.

What I changed

  1. browser_use/browser/watchdogs/default_action_watchdog.py

Modified _focus_element_simple() (the method that focuses an element before typing) to detect autocomplete fields and use click-to-focus instead of DOM.focus() for them:

  • Added _is_autocomplete_field() — detects combobox fields from ARIA attributes (role="combobox", aria-autocomplete, aria-haspopup + aria-controls/aria-owns)
  • Extracted _click_to_focus() — dispatches mousePressed/mouseReleased events at the element's coordinates
  • Changed the focus strategy order: for autocomplete fields, try click-to-focus first (so mouse events fire and the dropdown opens), then fall back to DOM.focus() only if coordinates aren't available
  1. tests/ci/interactions/test_autocomplete_interaction.py
    Added a test with an HTML page where the combobox dropdown only opens on mousedown/click exactly the scenario that was broken. The test verifies that tools.input() triggers the dropdown to open.

What I didn't change

  • Normal (non-autocomplete) inputs still use DOM.focus() first — no behavior change for regular fields
  • The existing autocomplete detection in tools/service.py (the post-typing delay and hint message) is untouched — it still works as before
  • The _is_autocomplete_field logic intentionally excludes native fields (which use the list attribute), since those are handled by the browser natively and don't need mouse events to work

Summary by cubic

Fix input on autocomplete/combobox fields by preferring click-to-focus so mouse events fire and dropdowns open. This makes tools.input reliably show suggestions in common widgets.

  • Bug Fixes
    • Detect combobox/autocomplete inputs via ARIA attributes (role="combobox", aria-autocomplete, aria-haspopup with controls/owns).
    • Use click-to-focus for these fields; fall back to DOM.focus() if coordinates aren’t available.
    • No change for regular inputs.
    • Added an integration test that only opens on mousedown/click to verify the fix.

Written for commit 2210203. Summary will update on new commits.

@CLAassistant
Copy link

CLAassistant commented Feb 21, 2026

CLA assistant check
All committers have signed the CLA.

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

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.

2 participants