Puppeteer: Cannot accept dialog which is already handled!
A dialog was already accepted or dismissed before another accept call.
A dialog was already accepted or dismissed before another accept call.
Error message
Cannot accept dialog which is already handled!
How this error happens
A JavaScript dialog is handled once. After accepting it, another accept or dismiss call tries to resolve the same completed dialog.
The snippets use an open Puppeteer page named page.
const dialogPromise = new Promise((resolve) => {
page.once("dialog", resolve);
});
const opening = page.evaluate(() => {
alert("Continue?");
});
const dialog = await dialogPromise;
await dialog.accept();
await opening;
await dialog.accept();
How to fix
Give each dialog one owner and one resolution. Register the listener before opening the dialog.
page.once("dialog", async (dialog) => {
await dialog.accept();
});
await page.evaluate(() => {
alert("Continue?");
});
Things to keep in mind
A shared listener and a test-specific listener can both receive the same dialog. Avoid two handlers that independently accept or dismiss it.