Skip to main content

browser_commander/playwright/protocol/
root.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 `Root`.
14#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
15pub struct RootInitializer {}
16
17/// Parameters of `Root.initialize`.
18#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
19pub struct RootInitializeParams {
20    #[serde(rename = "sdkLanguage")]
21    pub sdk_language: SDKLanguage,
22}
23
24/// Result of `Root.initialize`.
25#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
26pub struct RootInitializeResult {
27    #[serde(rename = "playwright")]
28    pub playwright: Ref<Playwright>,
29}
30
31/// Events a `Root` channel can emit.
32#[derive(Debug, Clone, PartialEq)]
33pub enum RootEvent {
34    /// An event this binding does not know (a newer driver).
35    Unknown {
36        /// Event name.
37        method: String,
38        /// Raw event parameters.
39        params: serde_json::Value,
40    },
41}
42
43impl ProtocolEvent for RootEvent {
44    fn parse(method: &str, params: serde_json::Value) -> Result<Self, serde_json::Error> {
45        match method {
46            _ => Ok(Self::Unknown { method: method.to_string(), params }),
47        }
48    }
49}
50
51/// Channel for the `Root` interface (`playwright.yml`).
52#[derive(Debug, Clone)]
53pub struct Root {
54    channel: Channel,
55}
56
57impl ChannelType for Root {
58    const INTERFACE: &'static str = "Root";
59    type Initializer = RootInitializer;
60    type Event = RootEvent;
61
62    fn accepts(interface: &str) -> bool {
63        matches!(interface, "Root")
64    }
65
66    fn from_channel(channel: Channel) -> Self {
67        Self { channel }
68    }
69
70    fn channel(&self) -> &Channel {
71        &self.channel
72    }
73}
74
75impl Root {
76    /// `Root.initialize` (internal).
77    pub async fn initialize(&self, params: RootInitializeParams) -> Result<RootInitializeResult, ProtocolError> {
78        self.channel.send("initialize", &params).await
79    }
80}