The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Listen for the page’s dialog event, then read dialog.defaultValue(). For a prompt, it returns the text initially shown in the prompt; for other dialog types, it returns an empty string.
Read a prompt’s default value
Puppeteer emits a dialog event on the page when a JavaScript dialog opens. The event handler receives a Dialog object, whose defaultValue() method reads the prompt’s initial text.
As an Amazon Associate I earn from qualifying purchases.
The following handler logs that value and accepts the dialog:
Free tools Windows power users keep installed
One-click scans. No signup required.
page.on('dialog', async dialog => {
const initialText = dialog.defaultValue();
console.log(initialText);
await dialog.accept();
});
dialog.defaultValue() returns an empty string if the dialog is not a prompt. Puppeteer documents the supported dialog types as alert, beforeunload, confirm, and prompt. See the Puppeteer Dialog API reference.
#1 Best Overall
Accept the prompt with different text
To submit a replacement instead of accepting the original prompt value, pass a string to accept():
page.on('dialog', async dialog => {
const initialText = dialog.defaultValue();
console.log('Initial prompt value:', initialText);
await dialog.accept('replacement text');
});
The optional argument supplies the prompt’s response; it has no effect on other dialog types. The browser’s prompt(message, default) function uses its second argument as the initial response text. See the HTML Living Standard.
Handle dialog types deliberately
If your handler may receive dialogs other than prompts, check the type before relying on the value. The API returns an empty string for a non-prompt dialog, so the value alone cannot establish that the dialog is a prompt.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →page.on('dialog', async dialog => {
if (dialog.type() === 'prompt') {
console.log('Initial prompt value:', dialog.defaultValue());
await dialog.accept();
return;
}
// Choose the appropriate action for alert, confirm, or beforeunload.
await dialog.dismiss();
});
Choose the non-prompt action to suit your test: accepting a confirmation and dismissing it represent different user responses. This example dismisses non-prompt dialogs only to show an explicit branch; it is not a universal handling policy.
Rank #3
Or skip the browser setup
If your goal is to capture a website rather than inspect a JavaScript prompt, ScreenshotNeo provides a screenshot API. One GET request can return a PNG, JPEG, WebP, or PDF. For example, this cURL call saves a WebP screenshot:
Quick Recap
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 removes cookie banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, failed loads, timeouts, and cache hits are not billed. Its MCP server lets AI agents take screenshots. The Free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 shots. Sign up for ScreenshotNeo and start with 1,000 free screenshots a month, no card required.
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.

