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 FrameUncheckParams {
16 #[serde(rename = "selector")]
17 pub selector: String,
18 #[serde(rename = "strict", default, skip_serializing_if = "Option::is_none")]
19 pub strict: Option<bool>,
20 #[serde(rename = "force", default, skip_serializing_if = "Option::is_none")]
21 pub force: Option<bool>,
22 #[serde(rename = "scroll", default, skip_serializing_if = "Option::is_none")]
23 pub scroll: Option<FrameUncheckParamsScroll>,
24 #[serde(rename = "position", default, skip_serializing_if = "Option::is_none")]
25 pub position: Option<Point>,
26 #[serde(rename = "trial", default, skip_serializing_if = "Option::is_none")]
27 pub trial: Option<bool>,
28}
29
30#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
32pub struct FrameWaitForTimeoutParams {
33 #[serde(rename = "waitTimeout")]
34 pub wait_timeout: f64,
35}
36
37#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
39pub struct FrameWaitForFunctionParams {
40 #[serde(rename = "expression")]
41 pub expression: String,
42 #[serde(rename = "isFunction", default, skip_serializing_if = "Option::is_none")]
43 pub is_function: Option<bool>,
44 #[serde(rename = "arg")]
45 pub arg: SerializedArgument,
46 #[serde(rename = "pollingInterval", default, skip_serializing_if = "Option::is_none")]
47 pub polling_interval: Option<f64>,
48 #[serde(rename = "selector", default, skip_serializing_if = "Option::is_none")]
49 pub selector: Option<String>,
50 #[serde(rename = "strict", default, skip_serializing_if = "Option::is_none")]
51 pub strict: Option<bool>,
52}
53
54#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
56pub struct FrameWaitForFunctionResult {
57 #[serde(rename = "handle", default, skip_serializing_if = "Option::is_none")]
58 pub handle: Option<Ref<JSHandle>>,
59}
60
61#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
62pub enum FrameWaitForSelectorParamsState {
63 #[default]
64 #[serde(rename = "attached")]
65 Attached,
66 #[serde(rename = "detached")]
67 Detached,
68 #[serde(rename = "visible")]
69 Visible,
70 #[serde(rename = "hidden")]
71 Hidden,
72}
73
74#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
76pub struct FrameWaitForSelectorParams {
77 #[serde(rename = "selector")]
78 pub selector: String,
79 #[serde(rename = "strict", default, skip_serializing_if = "Option::is_none")]
80 pub strict: Option<bool>,
81 #[serde(rename = "state", default, skip_serializing_if = "Option::is_none")]
82 pub state: Option<FrameWaitForSelectorParamsState>,
83 #[serde(rename = "omitReturnValue", default, skip_serializing_if = "Option::is_none")]
84 pub omit_return_value: Option<bool>,
85}
86
87#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
89pub struct FrameWaitForSelectorResult {
90 #[serde(rename = "element", default, skip_serializing_if = "Option::is_none")]
91 pub element: Option<Ref<ElementHandle>>,
92}
93
94#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
95pub enum FrameExpectParamsPseudo {
96 #[default]
97 #[serde(rename = "before")]
98 Before,
99 #[serde(rename = "after")]
100 After,
101}
102
103#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
105pub struct FrameExpectParams {
106 #[serde(rename = "selector", default, skip_serializing_if = "Option::is_none")]
107 pub selector: Option<String>,
108 #[serde(rename = "expression")]
109 pub expression: String,
110 #[serde(rename = "expressionArg", default, skip_serializing_if = "Option::is_none")]
111 pub expression_arg: Option<serde_json::Value>,
112 #[serde(rename = "pseudo", default, skip_serializing_if = "Option::is_none")]
113 pub pseudo: Option<FrameExpectParamsPseudo>,
114 #[serde(rename = "expectedText", default, skip_serializing_if = "Option::is_none")]
115 pub expected_text: Option<Vec<ExpectedTextValue>>,
116 #[serde(rename = "expectedNumber", default, skip_serializing_if = "Option::is_none")]
117 pub expected_number: Option<f64>,
118 #[serde(rename = "expectedValue", default, skip_serializing_if = "Option::is_none")]
119 pub expected_value: Option<SerializedArgument>,
120 #[serde(rename = "useInnerText", default, skip_serializing_if = "Option::is_none")]
121 pub use_inner_text: Option<bool>,
122 #[serde(rename = "isNot")]
123 pub is_not: bool,
124}
125
126#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
128pub struct FrameLoadstateEventParams {
129 #[serde(rename = "add", default, skip_serializing_if = "Option::is_none")]
130 pub add: Option<LifecycleEvent>,
131 #[serde(rename = "remove", default, skip_serializing_if = "Option::is_none")]
132 pub remove: Option<LifecycleEvent>,
133}
134
135#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
136pub struct FrameNavigatedEventParamsNewDocument {
137 #[serde(rename = "request", default, skip_serializing_if = "Option::is_none")]
138 pub request: Option<Ref<Request>>,
139}
140
141#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
143pub struct FrameNavigatedEventParams {
144 #[serde(rename = "url")]
145 pub url: String,
146 #[serde(rename = "name")]
147 pub name: String,
148 #[serde(rename = "newDocument", default, skip_serializing_if = "Option::is_none")]
149 pub new_document: Option<FrameNavigatedEventParamsNewDocument>,
150 #[serde(rename = "error", default, skip_serializing_if = "Option::is_none")]
151 pub error: Option<String>,
152}
153
154#[derive(Debug, Clone, PartialEq)]
156pub enum FrameEvent {
157 Loadstate(FrameLoadstateEventParams),
159 Navigated(FrameNavigatedEventParams),
161 Unknown {
163 method: String,
165 params: serde_json::Value,
167 },
168}
169
170impl ProtocolEvent for FrameEvent {
171 fn parse(method: &str, params: serde_json::Value) -> Result<Self, serde_json::Error> {
172 match method {
173 "loadstate" => Ok(Self::Loadstate(serde_json::from_value(params)?)),
174 "navigated" => Ok(Self::Navigated(serde_json::from_value(params)?)),
175 _ => Ok(Self::Unknown { method: method.to_string(), params }),
176 }
177 }
178}
179
180#[derive(Debug, Clone)]
182pub struct Frame {
183 channel: Channel,
184}
185
186impl ChannelType for Frame {
187 const INTERFACE: &'static str = "Frame";
188 type Initializer = FrameInitializer;
189 type Event = FrameEvent;
190
191 fn accepts(interface: &str) -> bool {
192 matches!(interface, "Frame")
193 }
194
195 fn from_channel(channel: Channel) -> Self {
196 Self { channel }
197 }
198
199 fn channel(&self) -> &Channel {
200 &self.channel
201 }
202}
203
204impl Frame {
205 pub async fn eval_on_selector(&self, params: FrameEvalOnSelectorParams) -> Result<FrameEvalOnSelectorResult, ProtocolError> {
207 self.channel.send("evalOnSelector", ¶ms).await
208 }
209
210 pub async fn eval_on_selector_all(&self, params: FrameEvalOnSelectorAllParams) -> Result<FrameEvalOnSelectorAllResult, ProtocolError> {
212 self.channel.send("evalOnSelectorAll", ¶ms).await
213 }
214
215 pub async fn add_script_tag(&self, params: FrameAddScriptTagParams) -> Result<FrameAddScriptTagResult, ProtocolError> {
217 self.channel.send("addScriptTag", ¶ms).await
218 }
219
220 pub async fn add_style_tag(&self, params: FrameAddStyleTagParams) -> Result<FrameAddStyleTagResult, ProtocolError> {
222 self.channel.send("addStyleTag", ¶ms).await
223 }
224
225 pub async fn aria_snapshot(&self, params: FrameAriaSnapshotParams) -> Result<FrameAriaSnapshotResult, ProtocolError> {
227 self.channel.send("ariaSnapshot", ¶ms).await
228 }
229
230 pub async fn aria_snapshot_json(&self, params: FrameAriaSnapshotJSONParams) -> Result<FrameAriaSnapshotJSONResult, ProtocolError> {
232 self.channel.send("ariaSnapshotJSON", ¶ms).await
233 }
234
235 pub async fn blur(&self, params: FrameBlurParams) -> Result<(), ProtocolError> {
237 self.channel.send_no_result("blur", ¶ms).await
238 }
239
240 pub async fn check(&self, params: FrameCheckParams) -> Result<(), ProtocolError> {
242 self.channel.send_no_result("check", ¶ms).await
243 }
244
245 pub async fn click(&self, params: FrameClickParams) -> Result<(), ProtocolError> {
247 self.channel.send_no_result("click", ¶ms).await
248 }
249
250 pub async fn content(&self) -> Result<FrameContentResult, ProtocolError> {
252 self.channel.send("content", &serde_json::json!({})).await
253 }
254
255 pub async fn drag_and_drop(&self, params: FrameDragAndDropParams) -> Result<(), ProtocolError> {
257 self.channel.send_no_result("dragAndDrop", ¶ms).await
258 }
259
260 pub async fn drop(&self, params: FrameDropParams) -> Result<(), ProtocolError> {
262 self.channel.send_no_result("drop", ¶ms).await
263 }
264
265 pub async fn dblclick(&self, params: FrameDblclickParams) -> Result<(), ProtocolError> {
267 self.channel.send_no_result("dblclick", ¶ms).await
268 }
269
270 pub async fn dispatch_event(&self, params: FrameDispatchEventParams) -> Result<(), ProtocolError> {
272 self.channel.send_no_result("dispatchEvent", ¶ms).await
273 }
274
275 pub async fn evaluate_expression(&self, params: FrameEvaluateExpressionParams) -> Result<FrameEvaluateExpressionResult, ProtocolError> {
277 self.channel.send("evaluateExpression", ¶ms).await
278 }
279
280 pub async fn evaluate_expression_handle(&self, params: FrameEvaluateExpressionHandleParams) -> Result<FrameEvaluateExpressionHandleResult, ProtocolError> {
282 self.channel.send("evaluateExpressionHandle", ¶ms).await
283 }
284
285 pub async fn fill(&self, params: FrameFillParams) -> Result<(), ProtocolError> {
287 self.channel.send_no_result("fill", ¶ms).await
288 }
289
290 pub async fn focus(&self, params: FrameFocusParams) -> Result<(), ProtocolError> {
292 self.channel.send_no_result("focus", ¶ms).await
293 }
294
295 pub async fn frame_element(&self) -> Result<FrameFrameElementResult, ProtocolError> {
297 self.channel.send("frameElement", &serde_json::json!({})).await
298 }
299
300 pub async fn resolve_selector(&self, params: FrameResolveSelectorParams) -> Result<FrameResolveSelectorResult, ProtocolError> {
302 self.channel.send("resolveSelector", ¶ms).await
303 }
304
305 pub async fn highlight(&self, params: FrameHighlightParams) -> Result<(), ProtocolError> {
307 self.channel.send_no_result("highlight", ¶ms).await
308 }
309
310 pub async fn hide_highlight(&self, params: FrameHideHighlightParams) -> Result<(), ProtocolError> {
312 self.channel.send_no_result("hideHighlight", ¶ms).await
313 }
314
315 pub async fn get_attribute(&self, params: FrameGetAttributeParams) -> Result<FrameGetAttributeResult, ProtocolError> {
317 self.channel.send("getAttribute", ¶ms).await
318 }
319
320 pub async fn goto(&self, params: FrameGotoParams) -> Result<FrameGotoResult, ProtocolError> {
322 self.channel.send("goto", ¶ms).await
323 }
324
325 pub async fn hover(&self, params: FrameHoverParams) -> Result<(), ProtocolError> {
327 self.channel.send_no_result("hover", ¶ms).await
328 }
329
330 pub async fn inner_html(&self, params: FrameInnerHTMLParams) -> Result<FrameInnerHTMLResult, ProtocolError> {
332 self.channel.send("innerHTML", ¶ms).await
333 }
334
335 pub async fn inner_text(&self, params: FrameInnerTextParams) -> Result<FrameInnerTextResult, ProtocolError> {
337 self.channel.send("innerText", ¶ms).await
338 }
339
340 pub async fn input_value(&self, params: FrameInputValueParams) -> Result<FrameInputValueResult, ProtocolError> {
342 self.channel.send("inputValue", ¶ms).await
343 }
344
345 pub async fn is_checked(&self, params: FrameIsCheckedParams) -> Result<FrameIsCheckedResult, ProtocolError> {
347 self.channel.send("isChecked", ¶ms).await
348 }
349
350 pub async fn is_disabled(&self, params: FrameIsDisabledParams) -> Result<FrameIsDisabledResult, ProtocolError> {
352 self.channel.send("isDisabled", ¶ms).await
353 }
354
355 pub async fn is_enabled(&self, params: FrameIsEnabledParams) -> Result<FrameIsEnabledResult, ProtocolError> {
357 self.channel.send("isEnabled", ¶ms).await
358 }
359
360 pub async fn is_hidden(&self, params: FrameIsHiddenParams) -> Result<FrameIsHiddenResult, ProtocolError> {
362 self.channel.send("isHidden", ¶ms).await
363 }
364
365 pub async fn is_visible(&self, params: FrameIsVisibleParams) -> Result<FrameIsVisibleResult, ProtocolError> {
367 self.channel.send("isVisible", ¶ms).await
368 }
369
370 pub async fn is_editable(&self, params: FrameIsEditableParams) -> Result<FrameIsEditableResult, ProtocolError> {
372 self.channel.send("isEditable", ¶ms).await
373 }
374
375 pub async fn press(&self, params: FramePressParams) -> Result<(), ProtocolError> {
377 self.channel.send_no_result("press", ¶ms).await
378 }
379
380 pub async fn query_selector(&self, params: FrameQuerySelectorParams) -> Result<FrameQuerySelectorResult, ProtocolError> {
382 self.channel.send("querySelector", ¶ms).await
383 }
384
385 pub async fn query_selector_all(&self, params: FrameQuerySelectorAllParams) -> Result<FrameQuerySelectorAllResult, ProtocolError> {
387 self.channel.send("querySelectorAll", ¶ms).await
388 }
389
390 pub async fn query_count(&self, params: FrameQueryCountParams) -> Result<FrameQueryCountResult, ProtocolError> {
392 self.channel.send("queryCount", ¶ms).await
393 }
394
395 pub async fn select_option(&self, params: FrameSelectOptionParams) -> Result<FrameSelectOptionResult, ProtocolError> {
397 self.channel.send("selectOption", ¶ms).await
398 }
399
400 pub async fn set_content(&self, params: FrameSetContentParams) -> Result<(), ProtocolError> {
402 self.channel.send_no_result("setContent", ¶ms).await
403 }
404
405 pub async fn set_input_files(&self, params: FrameSetInputFilesParams) -> Result<(), ProtocolError> {
407 self.channel.send_no_result("setInputFiles", ¶ms).await
408 }
409
410 pub async fn tap(&self, params: FrameTapParams) -> Result<(), ProtocolError> {
412 self.channel.send_no_result("tap", ¶ms).await
413 }
414
415 pub async fn text_content(&self, params: FrameTextContentParams) -> Result<FrameTextContentResult, ProtocolError> {
417 self.channel.send("textContent", ¶ms).await
418 }
419
420 pub async fn title(&self) -> Result<FrameTitleResult, ProtocolError> {
422 self.channel.send("title", &serde_json::json!({})).await
423 }
424
425 pub async fn r#type(&self, params: FrameTypeParams) -> Result<(), ProtocolError> {
427 self.channel.send_no_result("type", ¶ms).await
428 }
429
430 pub async fn uncheck(&self, params: FrameUncheckParams) -> Result<(), ProtocolError> {
432 self.channel.send_no_result("uncheck", ¶ms).await
433 }
434
435 pub async fn wait_for_timeout(&self, params: FrameWaitForTimeoutParams) -> Result<(), ProtocolError> {
437 self.channel.send_no_result("waitForTimeout", ¶ms).await
438 }
439
440 pub async fn wait_for_function(&self, params: FrameWaitForFunctionParams) -> Result<FrameWaitForFunctionResult, ProtocolError> {
442 self.channel.send("waitForFunction", ¶ms).await
443 }
444
445 pub async fn wait_for_selector(&self, params: FrameWaitForSelectorParams) -> Result<FrameWaitForSelectorResult, ProtocolError> {
447 self.channel.send("waitForSelector", ¶ms).await
448 }
449
450 pub async fn expect(&self, params: FrameExpectParams) -> Result<(), ProtocolError> {
452 self.channel.send_no_result("expect", ¶ms).await
453 }
454}