browser-commander 0.17.0

Universal browser automation library that supports multiple browser engines with a unified API
Documentation
// @generated by scripts/generate-playwright-protocol.mjs from
// rust/protocol/playwright/*.yml. Do not edit by hand.

#![allow(clippy::all, missing_docs, unused_imports)]

use serde::{Deserialize, Serialize};

use super::*;
use crate::playwright::connection::{
    Binary, Channel, ChannelType, ObjectRef, ProtocolError, ProtocolEvent, Ref,
};

/// Initializer the driver sends when it creates a `Root`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct RootInitializer {}

/// Parameters of `Root.initialize`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct RootInitializeParams {
    #[serde(rename = "sdkLanguage")]
    pub sdk_language: SDKLanguage,
}

/// Result of `Root.initialize`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct RootInitializeResult {
    #[serde(rename = "playwright")]
    pub playwright: Ref<Playwright>,
}

/// Events a `Root` channel can emit.
#[derive(Debug, Clone, PartialEq)]
pub enum RootEvent {
    /// An event this binding does not know (a newer driver).
    Unknown {
        /// Event name.
        method: String,
        /// Raw event parameters.
        params: serde_json::Value,
    },
}

impl ProtocolEvent for RootEvent {
    fn parse(method: &str, params: serde_json::Value) -> Result<Self, serde_json::Error> {
        match method {
            _ => Ok(Self::Unknown { method: method.to_string(), params }),
        }
    }
}

/// Channel for the `Root` interface (`playwright.yml`).
#[derive(Debug, Clone)]
pub struct Root {
    channel: Channel,
}

impl ChannelType for Root {
    const INTERFACE: &'static str = "Root";
    type Initializer = RootInitializer;
    type Event = RootEvent;

    fn accepts(interface: &str) -> bool {
        matches!(interface, "Root")
    }

    fn from_channel(channel: Channel) -> Self {
        Self { channel }
    }

    fn channel(&self) -> &Channel {
        &self.channel
    }
}

impl Root {
    /// `Root.initialize` (internal).
    pub async fn initialize(&self, params: RootInitializeParams) -> Result<RootInitializeResult, ProtocolError> {
        self.channel.send("initialize", &params).await
    }
}