Recommended Free Tools
Listen for the page’s dialog event, then call dialog.message() on the Dialog object passed to the handler. It returns the text shown in the browser dialog as a string.
Read the message in the dialog handler
Install the event listener before the page action that opens the dialog. Read its message, then accept or dismiss the dialog so it does not leave the page interaction waiting.
As an Amazon Associate I earn from qualifying purchases.
page.on('dialog', async dialog => {
console.log(dialog.message());
await dialog.dismiss();
});
message() provides the displayed message; it does not read text from the page DOM. Puppeteer delivers the dialog through the Page’s dialog event. See the Dialog.message() API and the Dialog class example.
Complete runnable example
This example creates a browser and page, registers the listener, then triggers an alert. It logs the alert text and dismisses the dialog.
#1 Best Overall
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
try {
const page = await browser.newPage();
page.on('dialog', async dialog => {
console.log(dialog.message());
await dialog.dismiss();
});
await page.evaluate(() => alert('The dialog message'));
} finally {
await browser.close();
}
})();
Run it in a Node.js project with Puppeteer installed. The event handler must be set up before page.evaluate() triggers the alert, or the code may wait on a dialog that has no handler.
Message text versus a prompt’s default value
Use dialog.message() for the text displayed in the dialog. For a prompt’s pre-filled input, use dialog.defaultValue() instead. That method returns an empty string when the dialog is not a prompt. Puppeteer documents the dialog types as alert, beforeunload, confirm, and prompt; the message method applies to the Dialog API rather than only alerts.
Rank #2
- HTML CSS Design and Build Web Sites
- Comes with secure packaging
- It can be a gift option
Choose whether to accept or dismiss
After inspecting the message, call await dialog.accept() to accept the dialog, or await dialog.dismiss() to cancel it. Choose based on the behavior your test or automation needs. The official example dismisses after reading.
Troubleshooting
- The script appears stuck: A JavaScript dialog may be blocking page progress. Register the handler before triggering the page action and ensure it accepts or dismisses the dialog.
- The message is undefined or unavailable: Read it from the Dialog object supplied to the
dialogevent handler, not from the page object or DOM. - You need the prompt’s pre-filled text: Call
dialog.defaultValue();message()returns the displayed dialog message, not the prompt input default.
Or skip the browser setup
If your goal is a screenshot rather than interacting with a JavaScript dialog, ScreenshotNeo offers a one-request screenshot API. For example, this cURL request captures a page:
Quick Recap
Best Value
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
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. Cookie banners, popups and chat widgets are removed before capture; bot checks, blank pages and failed loads are not billed. An MCP server lets AI agents take screenshots. The free plan includes 1,000 screenshots per month with no card, and paid plans start at $5 for 3,000.
Sign up free for ScreenshotNeo.
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.




