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 `Route`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct RouteInitializer {
    #[serde(rename = "request")]
    pub request: Ref<Request>,
}

/// Parameters of `Route.redirectNavigationRequest`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct RouteRedirectNavigationRequestParams {
    #[serde(rename = "url")]
    pub url: String,
}

/// Parameters of `Route.abort` (Abort request).
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct RouteAbortParams {
    #[serde(rename = "errorCode", default, skip_serializing_if = "Option::is_none")]
    pub error_code: Option<String>,
}

/// Parameters of `Route.continue` (Continue request).
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct RouteContinueParams {
    #[serde(rename = "url", default, skip_serializing_if = "Option::is_none")]
    pub url: Option<String>,
    #[serde(rename = "method", default, skip_serializing_if = "Option::is_none")]
    pub method: Option<String>,
    #[serde(rename = "headers", default, skip_serializing_if = "Option::is_none")]
    pub headers: Option<Vec<NameValue>>,
    #[serde(rename = "postData", default, skip_serializing_if = "Option::is_none")]
    pub post_data: Option<Binary>,
    #[serde(rename = "isFallback")]
    pub is_fallback: bool,
}

/// Parameters of `Route.fulfill` (Fulfill request).
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct RouteFulfillParams {
    #[serde(rename = "status", default, skip_serializing_if = "Option::is_none")]
    pub status: Option<i64>,
    #[serde(rename = "headers", default, skip_serializing_if = "Option::is_none")]
    pub headers: Option<Vec<NameValue>>,
    #[serde(rename = "body", default, skip_serializing_if = "Option::is_none")]
    pub body: Option<String>,
    #[serde(rename = "isBase64", default, skip_serializing_if = "Option::is_none")]
    pub is_base64: Option<bool>,
    #[serde(rename = "fetchResponseUid", default, skip_serializing_if = "Option::is_none")]
    pub fetch_response_uid: Option<String>,
}

/// Events a `Route` channel can emit.
#[derive(Debug, Clone, PartialEq)]
pub enum RouteEvent {
    /// 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 RouteEvent {
    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 `Route` interface (`network.yml`).
#[derive(Debug, Clone)]
pub struct Route {
    channel: Channel,
}

impl ChannelType for Route {
    const INTERFACE: &'static str = "Route";
    type Initializer = RouteInitializer;
    type Event = RouteEvent;

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

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

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

impl Route {
    /// `Route.redirectNavigationRequest` (internal).
    pub async fn redirect_navigation_request(&self, params: RouteRedirectNavigationRequestParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("redirectNavigationRequest", &params).await
    }

    /// `Route.abort` ("Abort request").
    pub async fn abort(&self, params: RouteAbortParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("abort", &params).await
    }

    /// `Route.continue` ("Continue request").
    pub async fn r#continue(&self, params: RouteContinueParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("continue", &params).await
    }

    /// `Route.fulfill` ("Fulfill request").
    pub async fn fulfill(&self, params: RouteFulfillParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("fulfill", &params).await
    }
}