browser-commander 0.18.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 `DebugController`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct DebugControllerInitializer {}

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

/// Parameters of `DebugController.setReportStateChanged`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct DebugControllerSetReportStateChangedParams {
    #[serde(rename = "enabled")]
    pub enabled: bool,
}

#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum DebugControllerSetRecorderModeParamsMode {
    #[default]
    #[serde(rename = "inspecting")]
    Inspecting,
    #[serde(rename = "recording")]
    Recording,
    #[serde(rename = "none")]
    None,
}

/// Parameters of `DebugController.setRecorderMode`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct DebugControllerSetRecorderModeParams {
    #[serde(rename = "mode")]
    pub mode: DebugControllerSetRecorderModeParamsMode,
    #[serde(rename = "testIdAttributeName", default, skip_serializing_if = "Option::is_none")]
    pub test_id_attribute_name: Option<String>,
    #[serde(rename = "generateAutoExpect", default, skip_serializing_if = "Option::is_none")]
    pub generate_auto_expect: Option<bool>,
}

/// Parameters of `DebugController.highlight`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct DebugControllerHighlightParams {
    #[serde(rename = "selector", default, skip_serializing_if = "Option::is_none")]
    pub selector: Option<String>,
    #[serde(rename = "ariaTemplate", default, skip_serializing_if = "Option::is_none")]
    pub aria_template: Option<String>,
}

/// Payload of the `DebugController.inspectRequested` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct DebugControllerInspectRequestedEventParams {
    #[serde(rename = "selector")]
    pub selector: String,
    #[serde(rename = "locator")]
    pub locator: String,
    #[serde(rename = "ariaSnapshot")]
    pub aria_snapshot: String,
}

/// Payload of the `DebugController.setModeRequested` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct DebugControllerSetModeRequestedEventParams {
    #[serde(rename = "mode")]
    pub mode: String,
}

/// Payload of the `DebugController.stateChanged` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct DebugControllerStateChangedEventParams {
    #[serde(rename = "pageCount")]
    pub page_count: i64,
}

/// Payload of the `DebugController.sourceChanged` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct DebugControllerSourceChangedEventParams {
    #[serde(rename = "text")]
    pub text: String,
    #[serde(rename = "header", default, skip_serializing_if = "Option::is_none")]
    pub header: Option<String>,
    #[serde(rename = "footer", default, skip_serializing_if = "Option::is_none")]
    pub footer: Option<String>,
    #[serde(rename = "actions", default, skip_serializing_if = "Option::is_none")]
    pub actions: Option<Vec<String>>,
}

/// Payload of the `DebugController.paused` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct DebugControllerPausedEventParams {
    #[serde(rename = "paused")]
    pub paused: bool,
}

/// Events a `DebugController` channel can emit.
#[derive(Debug, Clone, PartialEq)]
pub enum DebugControllerEvent {
    /// `DebugController.inspectRequested`
    InspectRequested(DebugControllerInspectRequestedEventParams),
    /// `DebugController.setModeRequested`
    SetModeRequested(DebugControllerSetModeRequestedEventParams),
    /// `DebugController.stateChanged`
    StateChanged(DebugControllerStateChangedEventParams),
    /// `DebugController.sourceChanged`
    SourceChanged(DebugControllerSourceChangedEventParams),
    /// `DebugController.paused`
    Paused(DebugControllerPausedEventParams),
    /// 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 DebugControllerEvent {
    fn parse(method: &str, params: serde_json::Value) -> Result<Self, serde_json::Error> {
        match method {
            "inspectRequested" => Ok(Self::InspectRequested(serde_json::from_value(params)?)),
            "setModeRequested" => Ok(Self::SetModeRequested(serde_json::from_value(params)?)),
            "stateChanged" => Ok(Self::StateChanged(serde_json::from_value(params)?)),
            "sourceChanged" => Ok(Self::SourceChanged(serde_json::from_value(params)?)),
            "paused" => Ok(Self::Paused(serde_json::from_value(params)?)),
            _ => Ok(Self::Unknown { method: method.to_string(), params }),
        }
    }
}

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

impl ChannelType for DebugController {
    const INTERFACE: &'static str = "DebugController";
    type Initializer = DebugControllerInitializer;
    type Event = DebugControllerEvent;

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

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

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

impl DebugController {
    /// `DebugController.initialize` (internal).
    pub async fn initialize(&self, params: DebugControllerInitializeParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("initialize", &params).await
    }

    /// `DebugController.setReportStateChanged` (internal).
    pub async fn set_report_state_changed(&self, params: DebugControllerSetReportStateChangedParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("setReportStateChanged", &params).await
    }

    /// `DebugController.setRecorderMode` (internal).
    pub async fn set_recorder_mode(&self, params: DebugControllerSetRecorderModeParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("setRecorderMode", &params).await
    }

    /// `DebugController.highlight` (internal).
    pub async fn highlight(&self, params: DebugControllerHighlightParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("highlight", &params).await
    }

    /// `DebugController.hideHighlight` (internal).
    pub async fn hide_highlight(&self) -> Result<(), ProtocolError> {
        self.channel.send_no_result("hideHighlight", &serde_json::json!({})).await
    }

    /// `DebugController.resume` (internal).
    pub async fn resume(&self) -> Result<(), ProtocolError> {
        self.channel.send_no_result("resume", &serde_json::json!({})).await
    }

    /// `DebugController.kill` (internal).
    pub async fn kill(&self) -> Result<(), ProtocolError> {
        self.channel.send_no_result("kill", &serde_json::json!({})).await
    }
}