From 165a5e138d0e0f56db2b31bf6dfff9a402acf974 Mon Sep 17 00:00:00 2001 From: Ashutosh Singh Date: Mon, 13 Jul 2026 14:44:45 +0530 Subject: [PATCH] fix(input): prevent upload_file crash on chooser-opening elements MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #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: - → use uploadFile() directly (fast, safe) - Everything else → use waitForFileChooser() + click (safe proxy path) --- src/tools/input.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/tools/input.ts b/src/tools/input.ts index 53562eac6..0ee710a8f 100644 --- a/src/tools/input.ts +++ b/src/tools/input.ts @@ -475,12 +475,12 @@ export const uploadFile = definePageTool({ uid, )) as ElementHandle; try { - try { + const isFileInput = await handle.evaluate( + el => el instanceof HTMLInputElement && el.type === 'file', + ); + if (isFileInput) { await handle.uploadFile(filePath); - } catch { - // Some sites use a proxy element to trigger file upload instead of - // a type=file element. In this case, we want to default to - // Page.waitForFileChooser() and upload the file this way. + } else { try { const [fileChooser] = await Promise.all([ request.page.pptrPage.waitForFileChooser({timeout: 3000}), @@ -489,7 +489,8 @@ export const uploadFile = definePageTool({ await fileChooser.accept([filePath]); } catch { throw new Error( - `Failed to upload file. The element could not accept the file directly, and clicking it did not trigger a file chooser.`, + `Failed to upload file. Clicking the element did not trigger a file chooser. ` + + `If the element is an , pass its uid directly.`, ); } }