1#![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#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
15pub struct FrameWaitForFunctionParams {
16 #[serde(rename = "expression")]
17 pub expression: String,
18 #[serde(rename = "isFunction", default, skip_serializing_if = "Option::is_none")]
19 pub is_function: Option<bool>,
20 #[serde(rename = "arg")]
21 pub arg: SerializedArgument,
22 #[serde(rename = "pollingInterval", default, skip_serializing_if = "Option::is_none")]
23 pub polling_interval: Option<f64>,
24 #[serde(rename = "selector", default, skip_serializing_if = "Option::is_none")]
25 pub selector: Option<String>,
26 #[serde(rename = "strict", default, skip_serializing_if = "Option::is_none")]
27 pub strict: Option<bool>,
28}
29
30#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
32pub struct FrameWaitForFunctionResult {
33 #[serde(rename = "handle", default, skip_serializing_if = "Option::is_none")]
34 pub handle: Option<Ref<JSHandle>>,
35}
36
37#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
38pub enum FrameWaitForSelectorParamsState {
39 #[default]
40 #[serde(rename = "attached")]
41 Attached,
42 #[serde(rename = "detached")]
43 Detached,
44 #[serde(rename = "visible")]
45 Visible,
46 #[serde(rename = "hidden")]
47 Hidden,
48}
49
50#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
52pub struct FrameWaitForSelectorParams {
53 #[serde(rename = "selector")]
54 pub selector: String,
55 #[serde(rename = "strict", default, skip_serializing_if = "Option::is_none")]
56 pub strict: Option<bool>,
57 #[serde(rename = "state", default, skip_serializing_if = "Option::is_none")]
58 pub state: Option<FrameWaitForSelectorParamsState>,
59 #[serde(rename = "omitReturnValue", default, skip_serializing_if = "Option::is_none")]
60 pub omit_return_value: Option<bool>,
61}
62
63#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
65pub struct FrameWaitForSelectorResult {
66 #[serde(rename = "element", default, skip_serializing_if = "Option::is_none")]
67 pub element: Option<Ref<ElementHandle>>,
68}
69
70#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
71pub enum FrameExpectParamsPseudo {
72 #[default]
73 #[serde(rename = "before")]
74 Before,
75 #[serde(rename = "after")]
76 After,
77}
78
79#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
81pub struct FrameExpectParams {
82 #[serde(rename = "selector", default, skip_serializing_if = "Option::is_none")]
83 pub selector: Option<String>,
84 #[serde(rename = "expression")]
85 pub expression: String,
86 #[serde(rename = "expressionArg", default, skip_serializing_if = "Option::is_none")]
87 pub expression_arg: Option<serde_json::Value>,
88 #[serde(rename = "pseudo", default, skip_serializing_if = "Option::is_none")]
89 pub pseudo: Option<FrameExpectParamsPseudo>,
90 #[serde(rename = "expectedText", default, skip_serializing_if = "Option::is_none")]
91 pub expected_text: Option<Vec<ExpectedTextValue>>,
92 #[serde(rename = "expectedNumber", default, skip_serializing_if = "Option::is_none")]
93 pub expected_number: Option<f64>,
94 #[serde(rename = "expectedValue", default, skip_serializing_if = "Option::is_none")]
95 pub expected_value: Option<SerializedArgument>,
96 #[serde(rename = "useInnerText", default, skip_serializing_if = "Option::is_none")]
97 pub use_inner_text: Option<bool>,
98 #[serde(rename = "isNot")]
99 pub is_not: bool,
100}
101
102#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
104pub struct FrameLoadstateEventParams {
105 #[serde(rename = "add", default, skip_serializing_if = "Option::is_none")]
106 pub add: Option<LifecycleEvent>,
107 #[serde(rename = "remove", default, skip_serializing_if = "Option::is_none")]
108 pub remove: Option<LifecycleEvent>,
109}
110
111#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
112pub struct FrameNavigatedEventParamsNewDocument {
113 #[serde(rename = "request", default, skip_serializing_if = "Option::is_none")]
114 pub request: Option<Ref<Request>>,
115}
116
117#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
119pub struct FrameNavigatedEventParams {
120 #[serde(rename = "url")]
121 pub url: String,
122 #[serde(rename = "name")]
123 pub name: String,
124 #[serde(rename = "newDocument", default, skip_serializing_if = "Option::is_none")]
125 pub new_document: Option<FrameNavigatedEventParamsNewDocument>,
126 #[serde(rename = "error", default, skip_serializing_if = "Option::is_none")]
127 pub error: Option<String>,
128}
129
130#[derive(Debug, Clone, PartialEq)]
132pub enum FrameEvent {
133 Loadstate(FrameLoadstateEventParams),
135 Navigated(FrameNavigatedEventParams),
137 Unknown {
139 method: String,
141 params: serde_json::Value,
143 },
144}
145
146impl ProtocolEvent for FrameEvent {
147 fn parse(method: &str, params: serde_json::Value) -> Result<Self, serde_json::Error> {
148 match method {
149 "loadstate" => Ok(Self::Loadstate(serde_json::from_value(params)?)),
150 "navigated" => Ok(Self::Navigated(serde_json::from_value(params)?)),
151 _ => Ok(Self::Unknown { method: method.to_string(), params }),
152 }
153 }
154}
155
156#[derive(Debug, Clone)]
158pub struct Frame {
159 channel: Channel,
160}
161
162impl ChannelType for Frame {
163 const INTERFACE: &'static str = "Frame";
164 type Initializer = FrameInitializer;
165 type Event = FrameEvent;
166
167 fn accepts(interface: &str) -> bool {
168 matches!(interface, "Frame")
169 }
170
171 fn from_channel(channel: Channel) -> Self {
172 Self { channel }
173 }
174
175 fn channel(&self) -> &Channel {
176 &self.channel
177 }
178}
179
180impl Frame {
181 pub async fn eval_on_selector(&self, params: FrameEvalOnSelectorParams) -> Result<FrameEvalOnSelectorResult, ProtocolError> {
183 self.channel.send("evalOnSelector", ¶ms).await
184 }
185
186 pub async fn eval_on_selector_all(&self, params: FrameEvalOnSelectorAllParams) -> Result<FrameEvalOnSelectorAllResult, ProtocolError> {
188 self.channel.send("evalOnSelectorAll", ¶ms).await
189 }
190
191 pub async fn add_script_tag(&self, params: FrameAddScriptTagParams) -> Result<FrameAddScriptTagResult, ProtocolError> {
193 self.channel.send("addScriptTag", ¶ms).await
194 }
195
196 pub async fn add_style_tag(&self, params: FrameAddStyleTagParams) -> Result<FrameAddStyleTagResult, ProtocolError> {
198 self.channel.send("addStyleTag", ¶ms).await
199 }
200
201 pub async fn aria_snapshot(&self, params: FrameAriaSnapshotParams) -> Result<FrameAriaSnapshotResult, ProtocolError> {
203 self.channel.send("ariaSnapshot", ¶ms).await
204 }
205
206 pub async fn blur(&self, params: FrameBlurParams) -> Result<(), ProtocolError> {
208 self.channel.send_no_result("blur", ¶ms).await
209 }
210
211 pub async fn check(&self, params: FrameCheckParams) -> Result<(), ProtocolError> {
213 self.channel.send_no_result("check", ¶ms).await
214 }
215
216 pub async fn click(&self, params: FrameClickParams) -> Result<(), ProtocolError> {
218 self.channel.send_no_result("click", ¶ms).await
219 }
220
221 pub async fn content(&self) -> Result<FrameContentResult, ProtocolError> {
223 self.channel.send("content", &serde_json::json!({})).await
224 }
225
226 pub async fn drag_and_drop(&self, params: FrameDragAndDropParams) -> Result<(), ProtocolError> {
228 self.channel.send_no_result("dragAndDrop", ¶ms).await
229 }
230
231 pub async fn drop(&self, params: FrameDropParams) -> Result<(), ProtocolError> {
233 self.channel.send_no_result("drop", ¶ms).await
234 }
235
236 pub async fn dblclick(&self, params: FrameDblclickParams) -> Result<(), ProtocolError> {
238 self.channel.send_no_result("dblclick", ¶ms).await
239 }
240
241 pub async fn dispatch_event(&self, params: FrameDispatchEventParams) -> Result<(), ProtocolError> {
243 self.channel.send_no_result("dispatchEvent", ¶ms).await
244 }
245
246 pub async fn evaluate_expression(&self, params: FrameEvaluateExpressionParams) -> Result<FrameEvaluateExpressionResult, ProtocolError> {
248 self.channel.send("evaluateExpression", ¶ms).await
249 }
250
251 pub async fn evaluate_expression_handle(&self, params: FrameEvaluateExpressionHandleParams) -> Result<FrameEvaluateExpressionHandleResult, ProtocolError> {
253 self.channel.send("evaluateExpressionHandle", ¶ms).await
254 }
255
256 pub async fn fill(&self, params: FrameFillParams) -> Result<(), ProtocolError> {
258 self.channel.send_no_result("fill", ¶ms).await
259 }
260
261 pub async fn focus(&self, params: FrameFocusParams) -> Result<(), ProtocolError> {
263 self.channel.send_no_result("focus", ¶ms).await
264 }
265
266 pub async fn frame_element(&self) -> Result<FrameFrameElementResult, ProtocolError> {
268 self.channel.send("frameElement", &serde_json::json!({})).await
269 }
270
271 pub async fn resolve_selector(&self, params: FrameResolveSelectorParams) -> Result<FrameResolveSelectorResult, ProtocolError> {
273 self.channel.send("resolveSelector", ¶ms).await
274 }
275
276 pub async fn highlight(&self, params: FrameHighlightParams) -> Result<(), ProtocolError> {
278 self.channel.send_no_result("highlight", ¶ms).await
279 }
280
281 pub async fn hide_highlight(&self, params: FrameHideHighlightParams) -> Result<(), ProtocolError> {
283 self.channel.send_no_result("hideHighlight", ¶ms).await
284 }
285
286 pub async fn get_attribute(&self, params: FrameGetAttributeParams) -> Result<FrameGetAttributeResult, ProtocolError> {
288 self.channel.send("getAttribute", ¶ms).await
289 }
290
291 pub async fn goto(&self, params: FrameGotoParams) -> Result<FrameGotoResult, ProtocolError> {
293 self.channel.send("goto", ¶ms).await
294 }
295
296 pub async fn hover(&self, params: FrameHoverParams) -> Result<(), ProtocolError> {
298 self.channel.send_no_result("hover", ¶ms).await
299 }
300
301 pub async fn inner_html(&self, params: FrameInnerHTMLParams) -> Result<FrameInnerHTMLResult, ProtocolError> {
303 self.channel.send("innerHTML", ¶ms).await
304 }
305
306 pub async fn inner_text(&self, params: FrameInnerTextParams) -> Result<FrameInnerTextResult, ProtocolError> {
308 self.channel.send("innerText", ¶ms).await
309 }
310
311 pub async fn input_value(&self, params: FrameInputValueParams) -> Result<FrameInputValueResult, ProtocolError> {
313 self.channel.send("inputValue", ¶ms).await
314 }
315
316 pub async fn is_checked(&self, params: FrameIsCheckedParams) -> Result<FrameIsCheckedResult, ProtocolError> {
318 self.channel.send("isChecked", ¶ms).await
319 }
320
321 pub async fn is_disabled(&self, params: FrameIsDisabledParams) -> Result<FrameIsDisabledResult, ProtocolError> {
323 self.channel.send("isDisabled", ¶ms).await
324 }
325
326 pub async fn is_enabled(&self, params: FrameIsEnabledParams) -> Result<FrameIsEnabledResult, ProtocolError> {
328 self.channel.send("isEnabled", ¶ms).await
329 }
330
331 pub async fn is_hidden(&self, params: FrameIsHiddenParams) -> Result<FrameIsHiddenResult, ProtocolError> {
333 self.channel.send("isHidden", ¶ms).await
334 }
335
336 pub async fn is_visible(&self, params: FrameIsVisibleParams) -> Result<FrameIsVisibleResult, ProtocolError> {
338 self.channel.send("isVisible", ¶ms).await
339 }
340
341 pub async fn is_editable(&self, params: FrameIsEditableParams) -> Result<FrameIsEditableResult, ProtocolError> {
343 self.channel.send("isEditable", ¶ms).await
344 }
345
346 pub async fn press(&self, params: FramePressParams) -> Result<(), ProtocolError> {
348 self.channel.send_no_result("press", ¶ms).await
349 }
350
351 pub async fn query_selector(&self, params: FrameQuerySelectorParams) -> Result<FrameQuerySelectorResult, ProtocolError> {
353 self.channel.send("querySelector", ¶ms).await
354 }
355
356 pub async fn query_selector_all(&self, params: FrameQuerySelectorAllParams) -> Result<FrameQuerySelectorAllResult, ProtocolError> {
358 self.channel.send("querySelectorAll", ¶ms).await
359 }
360
361 pub async fn query_count(&self, params: FrameQueryCountParams) -> Result<FrameQueryCountResult, ProtocolError> {
363 self.channel.send("queryCount", ¶ms).await
364 }
365
366 pub async fn select_option(&self, params: FrameSelectOptionParams) -> Result<FrameSelectOptionResult, ProtocolError> {
368 self.channel.send("selectOption", ¶ms).await
369 }
370
371 pub async fn set_content(&self, params: FrameSetContentParams) -> Result<(), ProtocolError> {
373 self.channel.send_no_result("setContent", ¶ms).await
374 }
375
376 pub async fn set_input_files(&self, params: FrameSetInputFilesParams) -> Result<(), ProtocolError> {
378 self.channel.send_no_result("setInputFiles", ¶ms).await
379 }
380
381 pub async fn tap(&self, params: FrameTapParams) -> Result<(), ProtocolError> {
383 self.channel.send_no_result("tap", ¶ms).await
384 }
385
386 pub async fn text_content(&self, params: FrameTextContentParams) -> Result<FrameTextContentResult, ProtocolError> {
388 self.channel.send("textContent", ¶ms).await
389 }
390
391 pub async fn title(&self) -> Result<FrameTitleResult, ProtocolError> {
393 self.channel.send("title", &serde_json::json!({})).await
394 }
395
396 pub async fn r#type(&self, params: FrameTypeParams) -> Result<(), ProtocolError> {
398 self.channel.send_no_result("type", ¶ms).await
399 }
400
401 pub async fn uncheck(&self, params: FrameUncheckParams) -> Result<(), ProtocolError> {
403 self.channel.send_no_result("uncheck", ¶ms).await
404 }
405
406 pub async fn wait_for_timeout(&self, params: FrameWaitForTimeoutParams) -> Result<(), ProtocolError> {
408 self.channel.send_no_result("waitForTimeout", ¶ms).await
409 }
410
411 pub async fn wait_for_function(&self, params: FrameWaitForFunctionParams) -> Result<FrameWaitForFunctionResult, ProtocolError> {
413 self.channel.send("waitForFunction", ¶ms).await
414 }
415
416 pub async fn wait_for_selector(&self, params: FrameWaitForSelectorParams) -> Result<FrameWaitForSelectorResult, ProtocolError> {
418 self.channel.send("waitForSelector", ¶ms).await
419 }
420
421 pub async fn expect(&self, params: FrameExpectParams) -> Result<(), ProtocolError> {
423 self.channel.send_no_result("expect", ¶ms).await
424 }
425}