To cancel a file chooser intercepted by Puppeteer, register page.waitForFileChooser() before triggering the chooser, then call await fileChooser.cancel(). This closes the chooser without selecting a file.
Cancel a file chooser
Use Promise.all() to start waiting before clicking the control that opens the chooser:
As an Amazon Associate I earn from qualifying purchases.
const [fileChooser] = await Promise.all([
page.waitForFileChooser(),
page.click('#upload-file-button'),
]);
await fileChooser.cancel();
Replace #upload-file-button with a selector for the page’s upload control. The returned object is a Puppeteer FileChooser; its cancel() method closes the chooser without selecting files. Puppeteer FileChooser reference · cancel() method
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Why the waiter must come first
waitForFileChooser() listens for a chooser opened after the waiter is registered; it does not attach to a chooser that is already active. Starting the wait and the click together with Promise.all() avoids a race in which the click opens the chooser before Puppeteer is listening. Page.waitForFileChooser() reference
#1 Best Overall
Canceling versus selecting a file
Call cancel() when the automation should close the chooser without uploading anything. If the test is meant to provide files instead, use fileChooser.accept(paths), where paths is an array of file paths. Every intercepted chooser should be accepted or canceled; leaving one unresolved can prevent later chooser requests from appearing. Puppeteer FileChooser reference
What this method does not handle
- DOM file picker APIs: Puppeteer documents that
waitForFileChooser()does not currently interceptwindow.showOpenFilePicker(). Page.waitForFileChooser() reference - Visible native picker UI: When Puppeteer handles the chooser with this method, the native picker does not appear to the user, including in headful mode. Page.waitForFileChooser() reference
Do not use JavaScript dialog dismissal
A browser file chooser and a JavaScript alert, confirm, or prompt are different Puppeteer objects. Dialog.dismiss() applies to JavaScript dialogs; use FileChooser.cancel() for the file chooser. Puppeteer Dialog reference
Troubleshooting
- The wait times out: Check that the selector points to the control that actually opens a file chooser, and register
waitForFileChooser()before clicking it. The waiter will not capture an already-open chooser. - A later chooser never appears: Make sure each earlier intercepted chooser was resolved by calling
accept()orcancel(). window.showOpenFilePicker()is involved: This API is not intercepted bywaitForFileChooser(); Puppeteer’s documented waiter is not a solution for that picker path.- An old example omits
await: Current Puppeteer documentscancel(): Promise<void>, so await it. The changelog records a historical change making cancellation synchronous in Puppeteer 9.0.0, released April 21, 2021; check the installed version when maintaining older automation. Current cancel() reference · Puppeteer changelog
Or skip the browser setup
If your goal is a clean screenshot rather than automating a file upload, ScreenshotNeo provides a one-request screenshot API. It accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each cleanup step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify page verdict and billing status. Its MCP server includes screenshot tools for AI agents.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
cURL example; replace YOUR_API_KEY with your key:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo API documentation. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. Sign up for free.
Quick Recap
Rank #3
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

