Skip to content

feat: upload_file auto-dispatch change event + wait_for_condition helper#389

Open
qiankunli wants to merge 1 commit into
browser-use:mainfrom
qiankunli:feat/upload-dispatch-change-and-wait-for-condition
Open

feat: upload_file auto-dispatch change event + wait_for_condition helper#389
qiankunli wants to merge 1 commit into
browser-use:mainfrom
qiankunli:feat/upload-dispatch-change-and-wait-for-condition

Conversation

@qiankunli
Copy link
Copy Markdown

@qiankunli qiankunli commented May 23, 2026

Problem

upload_file() uses CDP DOM.setFileInputFiles which sets files at the browser level, but many React component libraries (Arco Design DragUpload, Ant Design Upload, etc.) only react to DOM change events — not CDP-level file setting. This causes uploads to silently stay at 0%.

Additionally, there's no generic way to poll for arbitrary page states (spinner gone, streaming response complete, specific text appeared) without writing a manual for-loop each time.

Changes

upload_file(selector, path, dispatch_change=True)

Dispatches a synthetic change event after DOM.setFileInputFiles by default. This makes React upload components detect the selected files immediately.

  • Backward compatible: standard <input type="file"> elements are unaffected by the extra event
  • Set dispatch_change=False to opt out if needed

wait_for_condition(js_expr, timeout=15.0, poll=0.5)

Generic JS-expression poller for states that don't map to a single CSS selector:

wait_for_condition("!document.querySelector('.arco-spin-loading')")
wait_for_condition("document.querySelectorAll('.markdown-body h3').length >= 3")
wait_for_condition("document.querySelector('textarea')?.disabled === false")

Returns the truthy value on success, or False on timeout.

cdp() docstring

Clarifies that session_id is a top-level kwarg, not a CDP param — passing it inside params causes 'Message may have string sessionId property' errors.

Context

Discovered while automating Arco Design-based admin pages (file upload to knowledge base) and Notebook chat pages (waiting for SSE streaming to complete). The upload_file fix alone would have saved ~30 minutes of debugging per site.

…ove cdp docs

- upload_file: add dispatch_change=True (default) to fire synthetic change
  event after DOM.setFileInputFiles. React component libraries (Arco Design
  DragUpload, Ant Design Upload) need this event to process selected files;
  without it uploads stay at 0%. Backward compatible — standard file inputs
  are unaffected by the extra event.

- wait_for_condition(js_expr, timeout, poll): generic JS-expression poller
  for states that don't map to a single CSS selector (spinner gone, streaming
  response complete, specific text appeared, etc.).

- cdp(): docstring clarifies that session_id is a top-level kwarg, not a
  CDP param — passing it inside params causes 'Message may have string
  sessionId property' errors.
@qiankunli qiankunli changed the title feat: upload_file dispatch change event, add wait_for_condition, impr… feat: upload_file auto-dispatch change event + wait_for_condition helper May 23, 2026
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

Re-trigger cubic

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