To accept a JavaScript alert, confirm, prompt, or beforeunload dialog with Puppeteer, listen for the page’s dialog event and call await dialog.accept(). Register the listener before the click or navigation that triggers the dialog. For a prompt, pass the text to enter to accept().
Accept a dialog with Puppeteer
Attach a handler to the page before triggering the action that opens the dialog:
page.on('dialog', async dialog => {
await dialog.accept();
});
The page emits a dialog event with a Dialog object. Its accept() method returns a promise that resolves when the dialog has been accepted. This event-and-handler approach is for JavaScript dialogs; it is not the same as finding and clicking a button in the page DOM. See the Puppeteer Dialog API.
Enter text in a JavaScript prompt
Pass the text as the optional argument to accept() when the dialog is a prompt:
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →#1 Best Overall
page.on('dialog', async dialog => {
await dialog.accept('text to enter');
});
The optional promptText argument only affects prompt dialogs. It has no effect on alerts, confirms, or beforeunload dialogs. For prompts, dialog.defaultValue() can return the prompt’s default value; it is empty for non-prompt dialogs. Refer to the accept() method reference and defaultValue() reference.
Dismiss instead of accepting
To cancel a dialog, call await dialog.dismiss() in the handler:
Rank #2
- HTML CSS Design and Build Web Sites
- Comes with secure packaging
- It can be a gift option
page.on('dialog', async dialog => {
await dialog.dismiss();
});
dismiss() returns a promise that resolves when the dialog has been dismissed. Choose between accepting and dismissing according to the interaction your test is meant to perform. The method is documented in the Puppeteer dismiss() reference.
Inspect the dialog before deciding
Puppeteer sends several dialog types through the same event: alert, prompt, confirm, and beforeunload. If the page can open more than one kind, inspect the dialog before resolving it rather than automatically accepting every dialog.
Rank #3
dialog.type()identifies the dialog type.dialog.message()returns its message.dialog.defaultValue()provides a default value for prompts and an empty value for other dialog types.dialog.handledindicates whether the dialog has been handled.
These properties and dialog categories are described in the Dialog class reference and the PageEvent reference. The references surfaced for this topic span Puppeteer versions 25.4.0, 25.9.0, 25.11.0, and 25.12.0; the PageEvent page uses the next documentation path. If your installed package behaves differently, consult the API reference matching that package version.
Or skip the browser setup
If you need a website screenshot rather than a browser dialog interaction, ScreenshotNeo offers a screenshot API and MCP server. A single GET request returns an image or PDF; for example, this cURL request saves a WebP screenshot of Stripe:
Rank #4
- Brand: Wiley
- Set of 2 Volumes
- A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
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. ScreenshotNeo accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each of those steps can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers report the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots.
Sign up for 1,000 free screenshots a month, with no card required.
Quick Recap
Best Value
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.




