Skip to main content

browser_commander/playwright/protocol/
js_handle.rs

1// @generated by scripts/generate-playwright-protocol.mjs from
2// rust/protocol/playwright/*.yml. Do not edit by hand.
3
4#![allow(clippy::all, missing_docs, unused_imports)]
5
6use serde::{Deserialize, Serialize};
7
8use super::*;
9use crate::playwright::connection::{
10    Binary, Channel, ChannelType, ObjectRef, ProtocolError, ProtocolEvent, Ref,
11};
12
13/// Initializer the driver sends when it creates a `JSHandle`.
14#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
15pub struct JSHandleInitializer {
16    #[serde(rename = "preview")]
17    pub preview: String,
18}
19
20/// Parameters of `JSHandle.evaluateExpression` (Evaluate).
21#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
22pub struct JSHandleEvaluateExpressionParams {
23    #[serde(rename = "expression")]
24    pub expression: String,
25    #[serde(rename = "isFunction", default, skip_serializing_if = "Option::is_none")]
26    pub is_function: Option<bool>,
27    #[serde(rename = "arg")]
28    pub arg: SerializedArgument,
29}
30
31/// Result of `JSHandle.evaluateExpression` (Evaluate).
32#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
33pub struct JSHandleEvaluateExpressionResult {
34    #[serde(rename = "value")]
35    pub value: SerializedValue,
36}
37
38/// Parameters of `JSHandle.evaluateExpressionHandle` (Evaluate).
39#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
40pub struct JSHandleEvaluateExpressionHandleParams {
41    #[serde(rename = "expression")]
42    pub expression: String,
43    #[serde(rename = "isFunction", default, skip_serializing_if = "Option::is_none")]
44    pub is_function: Option<bool>,
45    #[serde(rename = "arg")]
46    pub arg: SerializedArgument,
47}
48
49/// Result of `JSHandle.evaluateExpressionHandle` (Evaluate).
50#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
51pub struct JSHandleEvaluateExpressionHandleResult {
52    #[serde(rename = "handle")]
53    pub handle: Ref<JSHandle>,
54}
55
56#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
57pub struct JSHandleGetPropertyListResultProperties {
58    #[serde(rename = "name")]
59    pub name: String,
60    #[serde(rename = "value")]
61    pub value: Ref<JSHandle>,
62}
63
64/// Result of `JSHandle.getPropertyList` (Get property list).
65#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
66pub struct JSHandleGetPropertyListResult {
67    #[serde(rename = "properties")]
68    pub properties: Vec<JSHandleGetPropertyListResultProperties>,
69}
70
71/// Parameters of `JSHandle.getProperty` (Get JS property).
72#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
73pub struct JSHandleGetPropertyParams {
74    #[serde(rename = "name")]
75    pub name: String,
76}
77
78/// Result of `JSHandle.getProperty` (Get JS property).
79#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
80pub struct JSHandleGetPropertyResult {
81    #[serde(rename = "handle")]
82    pub handle: Ref<JSHandle>,
83}
84
85/// Result of `JSHandle.jsonValue` (Get JSON value).
86#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
87pub struct JSHandleJsonValueResult {
88    #[serde(rename = "value")]
89    pub value: SerializedValue,
90}
91
92/// Payload of the `JSHandle.previewUpdated` event.
93#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
94pub struct JSHandlePreviewUpdatedEventParams {
95    #[serde(rename = "preview")]
96    pub preview: String,
97}
98
99/// Events a `JSHandle` channel can emit.
100#[derive(Debug, Clone, PartialEq)]
101pub enum JSHandleEvent {
102    /// `JSHandle.previewUpdated`
103    PreviewUpdated(JSHandlePreviewUpdatedEventParams),
104    /// An event this binding does not know (a newer driver).
105    Unknown {
106        /// Event name.
107        method: String,
108        /// Raw event parameters.
109        params: serde_json::Value,
110    },
111}
112
113impl ProtocolEvent for JSHandleEvent {
114    fn parse(method: &str, params: serde_json::Value) -> Result<Self, serde_json::Error> {
115        match method {
116            "previewUpdated" => Ok(Self::PreviewUpdated(serde_json::from_value(params)?)),
117            _ => Ok(Self::Unknown { method: method.to_string(), params }),
118        }
119    }
120}
121
122/// Channel for the `JSHandle` interface (`handles.yml`).
123#[derive(Debug, Clone)]
124pub struct JSHandle {
125    channel: Channel,
126}
127
128impl ChannelType for JSHandle {
129    const INTERFACE: &'static str = "JSHandle";
130    type Initializer = JSHandleInitializer;
131    type Event = JSHandleEvent;
132
133    fn accepts(interface: &str) -> bool {
134        matches!(interface, "JSHandle" | "ElementHandle")
135    }
136
137    fn from_channel(channel: Channel) -> Self {
138        Self { channel }
139    }
140
141    fn channel(&self) -> &Channel {
142        &self.channel
143    }
144}
145
146impl JSHandle {
147    /// `JSHandle.dispose` (internal).
148    pub async fn dispose(&self) -> Result<(), ProtocolError> {
149        self.channel.send_no_result("dispose", &serde_json::json!({})).await
150    }
151
152    /// `JSHandle.evaluateExpression` ("Evaluate").
153    pub async fn evaluate_expression(&self, params: JSHandleEvaluateExpressionParams) -> Result<JSHandleEvaluateExpressionResult, ProtocolError> {
154        self.channel.send("evaluateExpression", &params).await
155    }
156
157    /// `JSHandle.evaluateExpressionHandle` ("Evaluate").
158    pub async fn evaluate_expression_handle(&self, params: JSHandleEvaluateExpressionHandleParams) -> Result<JSHandleEvaluateExpressionHandleResult, ProtocolError> {
159        self.channel.send("evaluateExpressionHandle", &params).await
160    }
161
162    /// `JSHandle.getPropertyList` ("Get property list").
163    pub async fn get_property_list(&self) -> Result<JSHandleGetPropertyListResult, ProtocolError> {
164        self.channel.send("getPropertyList", &serde_json::json!({})).await
165    }
166
167    /// `JSHandle.getProperty` ("Get JS property").
168    pub async fn get_property(&self, params: JSHandleGetPropertyParams) -> Result<JSHandleGetPropertyResult, ProtocolError> {
169        self.channel.send("getProperty", &params).await
170    }
171
172    /// `JSHandle.jsonValue` ("Get JSON value").
173    pub async fn json_value(&self) -> Result<JSHandleJsonValueResult, ProtocolError> {
174        self.channel.send("jsonValue", &serde_json::json!({})).await
175    }
176}