Puppeteer: Cannot accept FileChooser which is already handled!
A file chooser was already accepted or cancelled.
A file chooser was already accepted or cancelled.
Error message
Cannot accept FileChooser which is already handled!
How this error happens
A file chooser can be accepted or cancelled only once. The second operation below reuses a chooser that has already finished.
The snippets use an open Puppeteer page named page.
await page.setContent(
'<input id="upload" type="file">'
);
const [chooser] = await Promise.all([
page.waitForFileChooser(),
page.click("#upload"),
]);
await chooser.accept([]);
await chooser.accept([]);
How to fix
Wait for a new chooser before the click, then handle that chooser once.
const [chooser] = await Promise.all([
page.waitForFileChooser(),
page.click("#upload"),
]);
await chooser.accept([
"/absolute/path/report.csv",
]);
Things to keep in mind
The fix requires an existing file at the supplied path. If the file input is accessible, ElementHandle.uploadFile avoids owning a chooser event. Empty accept([]) in the failing example only demonstrates the handled state.