Skip to content

fix(input): prevent upload_file crash on chooser-opening elements#2354

Open
ashutoshsinghpr7 wants to merge 3 commits into
ChromeDevTools:mainfrom
ashutoshsinghpr7:fix/upload-file-chooser-crash
Open

fix(input): prevent upload_file crash on chooser-opening elements#2354
ashutoshsinghpr7 wants to merge 3 commits into
ChromeDevTools:mainfrom
ashutoshsinghpr7:fix/upload-file-chooser-crash

Conversation

@ashutoshsinghpr7

Copy link
Copy Markdown

Summary

Fixes #2310upload_file crashes the Chrome tab with RESULT_CODE_KILLED_BAD_MESSAGE when used on a chooser-opening proxy element (e.g. a button that calls input.click()).

Root Cause

upload_file called handle.uploadFile() on every element. This method is only valid for <input type="file"> elements. Calling it on a button or other element sends an invalid IPC message to the renderer, causing Chrome to kill the tab.

The crash happened before reaching the existing error-handling catch block, so the fallback waitForFileChooser() path was never reached.

Fix

Check the element type before choosing the upload path:

  • <input type="file"> → use uploadFile() directly (fast, safe, unchanged behavior)
  • Everything else → use waitForFileChooser() + click() (handles proxy elements correctly)

This matches the documented behavior:

uid: The uid of the file input element or an element that will open file chooser on the page from the page content snapshot

Testing

Self-contained repro from the issue:

  1. new_page with a page containing a hidden <input type="file"> + button that triggers input.click()
  2. take_snapshot → get button uid
  3. upload_file with button uid → no longer crashes tab, file upload succeeds via chooser

Existing file input direct-upload path is unchanged and continues to work.

Closes ChromeDevTools#2310

Previously upload_file called handle.uploadFile() on every element,
including chooser-opening proxy elements (e.g. a button that triggers
input.click()). Calling uploadFile() on a non-file-input element causes
Chrome to kill the renderer with RESULT_CODE_KILLED_BAD_MESSAGE.

The tool description documents this use case as supported:
  'The uid of the file input element or an element that will open
   file chooser on the page'

Fix: check the element type before choosing the upload path:
- <input type=file> → use uploadFile() directly (fast, safe)
- Everything else → use waitForFileChooser() + click (safe proxy path)
@google-cla

google-cla Bot commented Jul 13, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

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.

upload_file on a chooser-opening element crashes the tab with RESULT_CODE_KILLED_BAD_MESSAGE

1 participant