#![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 JSHandleInitializer {
#[serde(rename = "preview")]
pub preview: String,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct JSHandleEvaluateExpressionParams {
#[serde(rename = "expression")]
pub expression: String,
#[serde(rename = "isFunction", default, skip_serializing_if = "Option::is_none")]
pub is_function: Option<bool>,
#[serde(rename = "arg")]
pub arg: SerializedArgument,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct JSHandleEvaluateExpressionResult {
#[serde(rename = "value")]
pub value: SerializedValue,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct JSHandleEvaluateExpressionHandleParams {
#[serde(rename = "expression")]
pub expression: String,
#[serde(rename = "isFunction", default, skip_serializing_if = "Option::is_none")]
pub is_function: Option<bool>,
#[serde(rename = "arg")]
pub arg: SerializedArgument,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct JSHandleEvaluateExpressionHandleResult {
#[serde(rename = "handle")]
pub handle: Ref<JSHandle>,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct JSHandleGetPropertyListResultProperties {
#[serde(rename = "name")]
pub name: String,
#[serde(rename = "value")]
pub value: Ref<JSHandle>,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct JSHandleGetPropertyListResult {
#[serde(rename = "properties")]
pub properties: Vec<JSHandleGetPropertyListResultProperties>,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct JSHandleGetPropertyParams {
#[serde(rename = "name")]
pub name: String,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct JSHandleGetPropertyResult {
#[serde(rename = "handle")]
pub handle: Ref<JSHandle>,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct JSHandleJsonValueResult {
#[serde(rename = "value")]
pub value: SerializedValue,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct JSHandlePreviewUpdatedEventParams {
#[serde(rename = "preview")]
pub preview: String,
}
#[derive(Debug, Clone, PartialEq)]
pub enum JSHandleEvent {
PreviewUpdated(JSHandlePreviewUpdatedEventParams),
Unknown {
method: String,
params: serde_json::Value,
},
}
impl ProtocolEvent for JSHandleEvent {
fn parse(method: &str, params: serde_json::Value) -> Result<Self, serde_json::Error> {
match method {
"previewUpdated" => Ok(Self::PreviewUpdated(serde_json::from_value(params)?)),
_ => Ok(Self::Unknown { method: method.to_string(), params }),
}
}
}
#[derive(Debug, Clone)]
pub struct JSHandle {
channel: Channel,
}
impl ChannelType for JSHandle {
const INTERFACE: &'static str = "JSHandle";
type Initializer = JSHandleInitializer;
type Event = JSHandleEvent;
fn accepts(interface: &str) -> bool {
matches!(interface, "JSHandle" | "ElementHandle")
}
fn from_channel(channel: Channel) -> Self {
Self { channel }
}
fn channel(&self) -> &Channel {
&self.channel
}
}
impl JSHandle {
pub async fn dispose(&self) -> Result<(), ProtocolError> {
self.channel.send_no_result("dispose", &serde_json::json!({})).await
}
pub async fn evaluate_expression(&self, params: JSHandleEvaluateExpressionParams) -> Result<JSHandleEvaluateExpressionResult, ProtocolError> {
self.channel.send("evaluateExpression", ¶ms).await
}
pub async fn evaluate_expression_handle(&self, params: JSHandleEvaluateExpressionHandleParams) -> Result<JSHandleEvaluateExpressionHandleResult, ProtocolError> {
self.channel.send("evaluateExpressionHandle", ¶ms).await
}
pub async fn get_property_list(&self) -> Result<JSHandleGetPropertyListResult, ProtocolError> {
self.channel.send("getPropertyList", &serde_json::json!({})).await
}
pub async fn get_property(&self, params: JSHandleGetPropertyParams) -> Result<JSHandleGetPropertyResult, ProtocolError> {
self.channel.send("getProperty", ¶ms).await
}
pub async fn json_value(&self) -> Result<JSHandleJsonValueResult, ProtocolError> {
self.channel.send("jsonValue", &serde_json::json!({})).await
}
}