DocsDialog Handlingbrowser_set_dialog_action

browser_set_dialog_action

Browser Set Dialog Action

Configure automatic handling for JavaScript dialogs (alert, confirm, prompt, beforeunload). Set once and all future dialogs of that type are handled automatically. Useful for preventing dialog interruptions during automated browsing. Each dialog type can have a different action.

Usage Example

12345678910111213
import asyncio
from owl_browser import OwlBrowser, RemoteConfig
# Async usage
async with OwlBrowser(config) as browser:
context = await browser.create_context()
context_id = context["context_id"]
await browser.set_dialog_action(
context_id=context_id,
dialog_type="alert",
action="accept"
)

Parameters

Required

context_idstringrequired

The unique identifier of the browser context (e.g., 'ctx_000001')

dialog_typeenum
alertconfirmpromptbeforeunload
required

Type of JavaScript dialog to configure: 'alert' (message display), 'confirm' (yes/no), 'prompt' (text input), 'beforeunload' (page leave warning)

actionenum
acceptdismissaccept_with_textwait
required

How to automatically handle this dialog type: 'accept' clicks OK/Yes, 'dismiss' clicks Cancel/No, 'accept_with_text' accepts and provides text input (for prompts), 'wait' holds the dialog for manual handling via browser_handle_dialog

Optional

prompt_textstring

Default text to enter when accepting prompt dialogs. Only used when dialog_type='prompt' and action='accept_with_text'. Leave empty for blank input

Response

Returns a JSON object with the operation result.

{
  "success": true,
  "result": <value>
}