Skip to main content

What are Chrome dialogs?

A Chrome dialog is any pop-up or modal window that Google Chrome itself creates (not part of a web page) to communicate something to the user or request input. These include:
  • alert() dialogs that display a message with an “OK” button
  • confirm() dialogs that ask for confirmation with “OK” and “Cancel” buttons
  • prompt() dialogs that request text input from the user
  • window.print() dialogs that open the browser’s print interface
These native browser dialogs are different from custom web page modals and require special handling in automation.

Why you can’t interact with them directly

Chrome dialogs block JavaScript execution on the page until they’re dismissed. This means:
  • Automation tools can’t interact with the page while a dialog is open
  • Automation scripts will hang until the dialog is manually dismissed

Preventing Chrome dialogs

The best approach is to prevent these dialogs from appearing by overriding the native dialog functions before any page code runs. Use addInitScript(), which executes code before any page scripts.

Implementation

Playwright

Customizing dialog behavior

You can customize the return values based on your automation needs:

Handling PDF dialogs

PDF dialogs present unique challenges because PDFs can be generated and displayed in different ways. You’ll encounter two common scenarios:

Scenario 1: PDF opens in the current tab

When a PDF replaces the current page content, you need to capture it differently:
Playwright

Scenario 2: PDF opens in a new tab

When a PDF is generated client-side and opens in a new tab, you can capture the PDF blob before it’s displayed:
Playwright

How PDF capture works

Both scenarios use a combination of techniques:
  1. Override window.print() - Prevents the native print dialog from blocking automation
  2. Intercept URL.createObjectURL() - Captures client-side generated PDF blobs before they’re displayed
  3. Route network requests (Scenario 1) - Intercepts PDF files loaded from the network
The key difference:
  • Scenario 1: PDF might be fetched from the network or generated, and the print dialog appears in the current tab
  • Scenario 2: PDF is generated client-side and stored in a blob, opened in a new tab where the print dialog appears