viewpoint_cdp/protocol/page_dialog/
mod.rs

1//! Page dialog types.
2//!
3//! Types for JavaScript dialogs (alert, confirm, prompt, beforeunload).
4
5use serde::{Deserialize, Serialize};
6
7/// Type of JavaScript dialog.
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
9#[serde(rename_all = "lowercase")]
10pub enum DialogType {
11    /// Alert dialog.
12    Alert,
13    /// Confirm dialog.
14    Confirm,
15    /// Prompt dialog.
16    Prompt,
17    /// Beforeunload dialog.
18    Beforeunload,
19}
20
21impl std::fmt::Display for DialogType {
22    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23        match self {
24            Self::Alert => write!(f, "alert"),
25            Self::Confirm => write!(f, "confirm"),
26            Self::Prompt => write!(f, "prompt"),
27            Self::Beforeunload => write!(f, "beforeunload"),
28        }
29    }
30}
31
32/// Event: Page.javascriptDialogOpening
33///
34/// Fired when a JavaScript initiated dialog (alert, confirm, prompt, or onbeforeunload) is about to open.
35#[derive(Debug, Clone, Deserialize)]
36#[serde(rename_all = "camelCase")]
37pub struct JavascriptDialogOpeningEvent {
38    /// Frame url.
39    pub url: String,
40    /// Message that will be displayed by the dialog.
41    pub message: String,
42    /// Dialog type.
43    #[serde(rename = "type")]
44    pub dialog_type: DialogType,
45    /// True iff browser is capable showing or acting on the given dialog.
46    /// When browser has no dialog handler for given target, calling alert while
47    /// Page domain is engaged will stall the page execution. Execution can be
48    /// resumed via calling Page.handleJavaScriptDialog.
49    pub has_browser_handler: bool,
50    /// Default dialog prompt.
51    pub default_prompt: Option<String>,
52}
53
54/// Event: Page.javascriptDialogClosed
55///
56/// Fired when a JavaScript initiated dialog (alert, confirm, prompt, or onbeforeunload) has been closed.
57#[derive(Debug, Clone, Deserialize)]
58#[serde(rename_all = "camelCase")]
59pub struct JavascriptDialogClosedEvent {
60    /// Whether dialog was confirmed.
61    pub result: bool,
62    /// User input in case of prompt.
63    pub user_input: String,
64}
65
66/// Parameters for Page.handleJavaScriptDialog.
67#[derive(Debug, Clone, Serialize)]
68#[serde(rename_all = "camelCase")]
69pub struct HandleJavaScriptDialogParams {
70    /// Whether to accept or dismiss the dialog.
71    pub accept: bool,
72    /// The text to enter into the dialog prompt before accepting.
73    /// Used only if this is a prompt dialog.
74    #[serde(skip_serializing_if = "Option::is_none")]
75    pub prompt_text: Option<String>,
76}