Skip to main content

browser_commander/playwright/protocol/
dialog.rs

1// @generated by scripts/generate-playwright-protocol.mjs from
2// rust/protocol/playwright/*.yml. Do not edit by hand.
3
4#![allow(clippy::all, missing_docs, unused_imports)]
5
6use serde::{Deserialize, Serialize};
7
8use super::*;
9use crate::playwright::connection::{
10    Binary, Channel, ChannelType, ObjectRef, ProtocolError, ProtocolEvent, Ref,
11};
12
13/// Initializer the driver sends when it creates a `Dialog`.
14#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
15pub struct DialogInitializer {
16    #[serde(rename = "page", default, skip_serializing_if = "Option::is_none")]
17    pub page: Option<Ref<Page>>,
18    #[serde(rename = "type")]
19    pub r#type: String,
20    #[serde(rename = "message")]
21    pub message: String,
22    #[serde(rename = "defaultValue")]
23    pub default_value: String,
24}
25
26/// Parameters of `Dialog.accept` (Accept dialog).
27#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
28pub struct DialogAcceptParams {
29    #[serde(rename = "promptText", default, skip_serializing_if = "Option::is_none")]
30    pub prompt_text: Option<String>,
31}
32
33/// Events a `Dialog` channel can emit.
34#[derive(Debug, Clone, PartialEq)]
35pub enum DialogEvent {
36    /// An event this binding does not know (a newer driver).
37    Unknown {
38        /// Event name.
39        method: String,
40        /// Raw event parameters.
41        params: serde_json::Value,
42    },
43}
44
45impl ProtocolEvent for DialogEvent {
46    fn parse(method: &str, params: serde_json::Value) -> Result<Self, serde_json::Error> {
47        match method {
48            _ => Ok(Self::Unknown { method: method.to_string(), params }),
49        }
50    }
51}
52
53/// Channel for the `Dialog` interface (`playwright.yml`).
54#[derive(Debug, Clone)]
55pub struct Dialog {
56    channel: Channel,
57}
58
59impl ChannelType for Dialog {
60    const INTERFACE: &'static str = "Dialog";
61    type Initializer = DialogInitializer;
62    type Event = DialogEvent;
63
64    fn accepts(interface: &str) -> bool {
65        matches!(interface, "Dialog")
66    }
67
68    fn from_channel(channel: Channel) -> Self {
69        Self { channel }
70    }
71
72    fn channel(&self) -> &Channel {
73        &self.channel
74    }
75}
76
77impl Dialog {
78    /// `Dialog.accept` ("Accept dialog").
79    pub async fn accept(&self, params: DialogAcceptParams) -> Result<(), ProtocolError> {
80        self.channel.send_no_result("accept", &params).await
81    }
82
83    /// `Dialog.dismiss` ("Dismiss dialog").
84    pub async fn dismiss(&self) -> Result<(), ProtocolError> {
85        self.channel.send_no_result("dismiss", &serde_json::json!({})).await
86    }
87}