#![allow(clippy::all, missing_docs, unused_imports)]
use serde::{Deserialize, Serialize};
use super::*;
use crate::playwright::connection::{
Binary, Channel, ChannelType, ObjectRef, ProtocolError, ProtocolEvent, Ref,
};
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct DebugControllerInitializer {}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct DebugControllerInitializeParams {
#[serde(rename = "codegenId")]
pub codegen_id: String,
#[serde(rename = "sdkLanguage")]
pub sdk_language: SDKLanguage,
}
#[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,
}
#[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>,
}
#[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>,
}
#[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,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct DebugControllerSetModeRequestedEventParams {
#[serde(rename = "mode")]
pub mode: String,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct DebugControllerStateChangedEventParams {
#[serde(rename = "pageCount")]
pub page_count: i64,
}
#[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>>,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct DebugControllerPausedEventParams {
#[serde(rename = "paused")]
pub paused: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub enum DebugControllerEvent {
InspectRequested(DebugControllerInspectRequestedEventParams),
SetModeRequested(DebugControllerSetModeRequestedEventParams),
StateChanged(DebugControllerStateChangedEventParams),
SourceChanged(DebugControllerSourceChangedEventParams),
Paused(DebugControllerPausedEventParams),
Unknown {
method: String,
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 }),
}
}
}
#[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 {
pub async fn initialize(&self, params: DebugControllerInitializeParams) -> Result<(), ProtocolError> {
self.channel.send_no_result("initialize", ¶ms).await
}
pub async fn set_report_state_changed(&self, params: DebugControllerSetReportStateChangedParams) -> Result<(), ProtocolError> {
self.channel.send_no_result("setReportStateChanged", ¶ms).await
}
pub async fn set_recorder_mode(&self, params: DebugControllerSetRecorderModeParams) -> Result<(), ProtocolError> {
self.channel.send_no_result("setRecorderMode", ¶ms).await
}
pub async fn highlight(&self, params: DebugControllerHighlightParams) -> Result<(), ProtocolError> {
self.channel.send_no_result("highlight", ¶ms).await
}
pub async fn hide_highlight(&self) -> Result<(), ProtocolError> {
self.channel.send_no_result("hideHighlight", &serde_json::json!({})).await
}
pub async fn resume(&self) -> Result<(), ProtocolError> {
self.channel.send_no_result("resume", &serde_json::json!({})).await
}
pub async fn kill(&self) -> Result<(), ProtocolError> {
self.channel.send_no_result("kill", &serde_json::json!({})).await
}
}