feat: upload_file auto-dispatch change event + wait_for_condition helper#389
Open
qiankunli wants to merge 1 commit into
Open
Conversation
…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.
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.
Problem
upload_file()uses CDPDOM.setFileInputFileswhich sets files at the browser level, but many React component libraries (Arco Design DragUpload, Ant Design Upload, etc.) only react to DOMchangeevents — 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
changeevent afterDOM.setFileInputFilesby default. This makes React upload components detect the selected files immediately.<input type="file">elements are unaffected by the extra eventdispatch_change=Falseto opt out if neededwait_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:
Returns the truthy value on success, or
Falseon timeout.cdp()docstringClarifies that
session_idis a top-level kwarg, not a CDP param — passing it insideparamscauses'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_filefix alone would have saved ~30 minutes of debugging per site.