Dialogs
Handle browser dialogs (alert, confirm, prompt, beforeunload) that block page interaction.
browser_handle_dialog
| Parameter | Type | Required | Description |
|---|---|---|---|
accept | boolean | yes | true to accept, false to dismiss |
promptText | string | no | The text of the prompt in case of a prompt dialog |
While a dialog is open, every other tool refuses to run and reports the modal state instead:
### Modal state
- ["alert" dialog with message "Alert"]: can be handled by browser_handle_dialog
Handle the dialog before continuing.
Alert dialog
→ browser_click { target: "e5" }
### Modal state
- ["alert" dialog with message "Item deleted"]: can be handled by browser_handle_dialog
→ browser_handle_dialog { accept: true }
Confirm dialog
→ browser_click { target: "e10" }
### Modal state
- ["confirm" dialog with message "Are you sure you want to delete this?"]: can be handled by browser_handle_dialog
→ browser_handle_dialog { accept: true } // click OK
→ browser_handle_dialog { accept: false } // click Cancel
Prompt dialog
→ browser_click { target: "e8" }
### Modal state
- ["prompt" dialog with message "Enter your name:"]: can be handled by browser_handle_dialog
→ browser_handle_dialog { accept: true, promptText: "My new name" }
Workflow
→ browser_click { target: "e12" }
### Modal state
- ["confirm" dialog with message "Discard unsaved changes?"]: can be handled by browser_handle_dialog
→ browser_handle_dialog { accept: true }
→ browser_snapshot
// Page now shows updated state after the dialog was accepted
note
File choosers are reported the same way, and are cleared with browser_file_upload rather than
browser_handle_dialog. See File Upload.