Free tools Windows power users keep installed
One-click scans. No signup required.
Listen for the page’s dialog event before triggering an alert, confirm, prompt, or beforeunload dialog. In the handler, call and await dialog.accept() to proceed or dialog.dismiss() to cancel. For a prompt, pass the text to enter to accept(promptText).
Handle a dialog with a Page event listener
Register the listener on the Puppeteer Page that will open the dialog, and do so before the action that triggers it. This example supplies text to prompts and dismisses other dialog types; change those choices to match the behavior your test is meant to verify.
page.on('dialog', async dialog => {
console.log(dialog.type(), dialog.message());
if (dialog.type() === 'prompt') {
await dialog.accept('example response');
return;
}
await dialog.dismiss();
});
The dialog event provides a Dialog instance. The example logs the dialog type and displayed message, then responds. Both response methods return promises, so await them.
Choose whether to accept or dismiss
| Method | Effect | When to use it |
|---|---|---|
dialog.accept() |
Accepts the dialog and lets the page continue. | Use when the test should confirm or proceed. |
dialog.accept(promptText) |
Accepts a prompt and supplies the given text. The argument has no effect on non-prompt dialogs. | Use when the test should submit a prompt response. |
dialog.dismiss() |
Dismisses the dialog. | Use when the test should cancel, such as rejecting a confirmation. |
There is no universal default response: accepting and dismissing produce different page outcomes. Select the one that exercises the scenario under test.
#1 Best Overall
Inspect the dialog before responding
The Dialog API exposes information that can help a handler make a deliberate choice:
dialog.type()returns the type, such asalert,confirm,prompt, orbeforeunload.dialog.message()returns the displayed message.dialog.defaultValue()returns the prompt’s default value, or an empty string for a non-prompt dialog.
For example, use type() to branch by dialog kind, or use defaultValue() if the test should submit the prompt’s displayed default rather than a fixed string. These inspection methods do not replace the need to accept or dismiss the dialog.
Set up Puppeteer and the browser
Install and import Puppeteer using the module style and package manager used by your project. The Puppeteer project distinguishes puppeteer, which downloads a compatible Chrome during installation, from puppeteer-core, which does not download Chrome. If your package manager blocks install scripts, you may need to install the browser explicitly. This setup is separate from handling dialogs.
Troubleshoot dialog handling
- The page action appears stuck: make sure the listener is attached to the correct
Pageand is registered before the action that opens the dialog. Then ensure the handler awaits eitheraccept()ordismiss(). - The prompt contains the wrong text: pass the intended string to
accept(promptText). If the test should use the displayed default, inspectdefaultValue()first. - The test follows the wrong branch: inspect
type()rather than assuming every JavaScript dialog is a prompt or confirmation. The Page event can cover alerts, prompts, confirms, and before-unload dialogs. - The page proceeds when it should cancel, or vice versa: revise the test’s response policy. Accept proceeds; dismiss cancels. Do not apply one response to every dialog unless that is actually the intended test behavior.
Or skip the browser setup
For a screenshot rather than an interactive Puppeteer test, ScreenshotNeo provides a one-request website screenshot API. Its capture flow accepts cookie and consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and the response identifies the page verdict and billing status in headers. Its MCP server provides screenshot tools for AI agents.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteExample cURL request (replace the URL with the page to capture):
Rank #3
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 for request options. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots. Sign up for free.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Frequently Asked Questions
Does the prompt text argument affect alerts or confirmations?
No. The string passed to accept(promptText) supplies input for a prompt; it has no effect on non-prompt dialogs.
Quick Recap
What does defaultValue() return for a non-prompt dialog?
It returns an empty string.
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.




