browser_commander/puppeteer/api/frame.rs
1// @generated by scripts/generate-puppeteer-bindings.mjs from
2// rust/protocol/puppeteer/api.json. Do not edit by hand.
3
4#![allow(clippy::all, missing_docs, unused_imports, non_snake_case)]
5
6use serde_json::Value;
7
8use super::*;
9use crate::puppeteer::bridge::{binary, remote_type, BridgeError, JsFunction, Remote};
10
11remote_type!(
12 /// Puppeteer's `Frame` (puppeteer-core 25.10.0), a remote object
13 /// served by `browser-commander serve --stdio`.
14 ///
15 /// Extends [`EventEmitter`]; the inherited methods are repeated here.
16 Frame
17);
18
19impl Frame {
20 /// `EventEmitter.on`
21 ///
22 /// ```text
23 /// on<Key extends keyof EventsWithWildcard<Events>>(type: Key, handler: Handler<EventsWithWildcard<Events>[Key]>): this
24 /// ```
25 pub async fn on(&self, type_: Value, handler: impl Into<JsFunction>) -> Result<Frame, BridgeError> {
26 self.remote.call("on", vec![Some(type_), Some(handler.into().to_wire())]).await
27 }
28
29 /// `EventEmitter.off`
30 ///
31 /// ```text
32 /// off<Key extends keyof EventsWithWildcard<Events>>(type: Key, handler?: Handler<EventsWithWildcard<Events>[Key]>): this
33 /// ```
34 pub async fn off(&self, type_: Value, handler: Option<JsFunction>) -> Result<Frame, BridgeError> {
35 self.remote.call("off", vec![Some(type_), handler.map(|x| x.to_wire())]).await
36 }
37
38 /// `EventEmitter.emit`
39 ///
40 /// ```text
41 /// emit<Key extends keyof EventsWithWildcard<Events>>(type: Key, event: EventsWithWildcard<Events>[Key]): boolean
42 /// ```
43 pub async fn emit(&self, type_: Value, event: Value) -> Result<bool, BridgeError> {
44 self.remote.call("emit", vec![Some(type_), Some(event)]).await
45 }
46
47 /// `EventEmitter.once`
48 ///
49 /// ```text
50 /// once<Key extends keyof EventsWithWildcard<Events>>(type: Key, handler: Handler<EventsWithWildcard<Events>[Key]>): this
51 /// ```
52 pub async fn once(&self, type_: Value, handler: impl Into<JsFunction>) -> Result<Frame, BridgeError> {
53 self.remote.call("once", vec![Some(type_), Some(handler.into().to_wire())]).await
54 }
55
56 /// `EventEmitter.listenerCount`
57 ///
58 /// ```text
59 /// listenerCount(type: keyof EventsWithWildcard<Events>): number
60 /// ```
61 pub async fn listener_count(&self, type_: Value) -> Result<f64, BridgeError> {
62 self.remote.call("listenerCount", vec![Some(type_)]).await
63 }
64
65 /// `EventEmitter.removeAllListeners`
66 ///
67 /// ```text
68 /// removeAllListeners(type?: keyof EventsWithWildcard<Events>): this
69 /// ```
70 pub async fn remove_all_listeners(&self, type_: Option<Value>) -> Result<Frame, BridgeError> {
71 self.remote.call("removeAllListeners", vec![type_]).await
72 }
73
74 /// `Frame.page`
75 ///
76 /// ```text
77 /// page(): Page
78 /// ```
79 pub async fn page(&self) -> Result<Page, BridgeError> {
80 self.remote.call("page", vec![]).await
81 }
82
83 /// `Frame.goto`
84 ///
85 /// ```text
86 /// goto(url: string, options?: GoToOptions): Promise<HTTPResponse | null>
87 /// ```
88 pub async fn goto(&self, url: &str, options: Option<Value>) -> Result<Option<HTTPResponse>, BridgeError> {
89 self.remote.call("goto", vec![Some(Value::from(url)), options]).await
90 }
91
92 /// `Frame.waitForNavigation`
93 ///
94 /// ```text
95 /// waitForNavigation(options?: WaitForOptions): Promise<HTTPResponse | null>
96 /// ```
97 pub async fn wait_for_navigation(&self, options: Option<Value>) -> Result<Option<HTTPResponse>, BridgeError> {
98 self.remote.call("waitForNavigation", vec![options]).await
99 }
100
101 /// `Frame.frameElement`
102 ///
103 /// ```text
104 /// frameElement(): Promise<HandleFor<HTMLIFrameElement> | null>
105 /// ```
106 pub async fn frame_element(&self) -> Result<Option<JSHandle>, BridgeError> {
107 self.remote.call("frameElement", vec![]).await
108 }
109
110 /// `Frame.evaluateHandle`
111 ///
112 /// ```text
113 /// evaluateHandle<Params extends unknown[], Func extends EvaluateFunc<Params> = EvaluateFunc<Params>>(pageFunction: Func | string, ...args: Params ): Promise<HandleFor<Awaited<ReturnType<Func>>>>
114 /// ```
115 pub async fn evaluate_handle(&self, page_function: impl Into<JsFunction>, args: &[Value]) -> Result<JSHandle, BridgeError> {
116 let mut call_args: Vec<Option<Value>> = vec![Some(page_function.into().to_wire())];
117 call_args.extend(args.iter().map(|v| Some(v.clone())));
118 self.remote.call("evaluateHandle", call_args).await
119 }
120
121 /// `Frame.evaluate`
122 ///
123 /// ```text
124 /// evaluate<Params extends unknown[], Func extends EvaluateFunc<Params> = EvaluateFunc<Params>>(pageFunction: Func | string, ...args: Params ): Promise<Awaited<ReturnType<Func>>>
125 /// ```
126 pub async fn evaluate(&self, page_function: impl Into<JsFunction>, args: &[Value]) -> Result<Value, BridgeError> {
127 let mut call_args: Vec<Option<Value>> = vec![Some(page_function.into().to_wire())];
128 call_args.extend(args.iter().map(|v| Some(v.clone())));
129 self.remote.call("evaluate", call_args).await
130 }
131
132 /// `Frame.locator`
133 ///
134 /// ```text
135 /// locator<Selector extends string>(selector: Selector): Locator<NodeFor<Selector>>
136 /// locator<Ret>(func: () => Awaitable<Ret>): Locator<Ret>
137 /// ```
138 pub async fn locator(&self, selector: impl Into<JsFunction>) -> Result<Locator, BridgeError> {
139 self.remote.call("locator", vec![Some(selector.into().to_wire())]).await
140 }
141
142 /// `Frame.$`
143 ///
144 /// ```text
145 /// $<Selector extends string>(selector: Selector): Promise<ElementHandle<NodeFor<Selector>> | null>
146 /// ```
147 pub async fn query_selector(&self, selector: &str) -> Result<Option<ElementHandle>, BridgeError> {
148 self.remote.call("$", vec![Some(Value::from(selector))]).await
149 }
150
151 /// `Frame.$$`
152 ///
153 /// ```text
154 /// $$<Selector extends string>(selector: Selector, options?: QueryOptions): Promise<Array<ElementHandle<NodeFor<Selector>>>>
155 /// ```
156 pub async fn query_selector_all(&self, selector: &str, options: Option<Value>) -> Result<Vec<ElementHandle>, BridgeError> {
157 self.remote.call("$$", vec![Some(Value::from(selector)), options]).await
158 }
159
160 /// `Frame.$eval`
161 ///
162 /// ```text
163 /// $eval<Selector extends string, Params extends unknown[], Func extends EvaluateFuncWith<NodeFor<Selector>, Params> = EvaluateFuncWith<NodeFor<Selector>, Params >>(selector: Selector, pageFunction: string | Func, ...args: Params ): Promise<Awaited<ReturnType<Func>>>
164 /// ```
165 pub async fn eval_on_selector(&self, selector: &str, page_function: impl Into<JsFunction>, args: &[Value]) -> Result<Value, BridgeError> {
166 let mut call_args: Vec<Option<Value>> = vec![Some(Value::from(selector)), Some(page_function.into().to_wire())];
167 call_args.extend(args.iter().map(|v| Some(v.clone())));
168 self.remote.call("$eval", call_args).await
169 }
170
171 /// `Frame.$$eval`
172 ///
173 /// ```text
174 /// $$eval<Selector extends string, Params extends unknown[], Func extends EvaluateFuncWith<Array<NodeFor<Selector>>, Params> = EvaluateFuncWith<Array<NodeFor<Selector>>, Params>>(selector: Selector, pageFunction: string | Func, ...args: Params ): Promise<Awaited<ReturnType<Func>>>
175 /// ```
176 pub async fn eval_on_selector_all(&self, selector: &str, page_function: impl Into<JsFunction>, args: &[Value]) -> Result<Value, BridgeError> {
177 let mut call_args: Vec<Option<Value>> = vec![Some(Value::from(selector)), Some(page_function.into().to_wire())];
178 call_args.extend(args.iter().map(|v| Some(v.clone())));
179 self.remote.call("$$eval", call_args).await
180 }
181
182 /// `Frame.waitForSelector`
183 ///
184 /// ```text
185 /// waitForSelector<Selector extends string>(selector: Selector, options?: WaitForSelectorOptions): Promise<ElementHandle<NodeFor<Selector>> | null>
186 /// ```
187 pub async fn wait_for_selector(&self, selector: &str, options: Option<Value>) -> Result<Option<ElementHandle>, BridgeError> {
188 self.remote.call("waitForSelector", vec![Some(Value::from(selector)), options]).await
189 }
190
191 /// `Frame.waitForFunction`
192 ///
193 /// ```text
194 /// waitForFunction<Params extends unknown[], Func extends EvaluateFunc<Params> = EvaluateFunc<Params>>(pageFunction: Func | string, options?: FrameWaitForFunctionOptions, ...args: Params ): Promise<HandleFor<Awaited<ReturnType<Func>>>>
195 /// ```
196 pub async fn wait_for_function(&self, page_function: impl Into<JsFunction>, options: Option<Value>, args: &[Value]) -> Result<JSHandle, BridgeError> {
197 let mut call_args: Vec<Option<Value>> = vec![Some(page_function.into().to_wire()), options];
198 call_args.extend(args.iter().map(|v| Some(v.clone())));
199 self.remote.call("waitForFunction", call_args).await
200 }
201
202 /// `Frame.content`
203 ///
204 /// ```text
205 /// content(): Promise<string>
206 /// ```
207 pub async fn content(&self) -> Result<String, BridgeError> {
208 self.remote.call("content", vec![]).await
209 }
210
211 /// `Frame.setContent`
212 ///
213 /// ```text
214 /// setContent(html: string, options?: SetContentWaitForOptions): Promise<void>
215 /// ```
216 pub async fn set_content(&self, html: &str, options: Option<Value>) -> Result<(), BridgeError> {
217 self.remote.call("setContent", vec![Some(Value::from(html)), options]).await
218 }
219
220 /// `Frame.name`
221 ///
222 /// ```text
223 /// name(): string
224 /// ```
225 pub async fn name(&self) -> Result<String, BridgeError> {
226 self.remote.call("name", vec![]).await
227 }
228
229 /// `Frame.url`
230 ///
231 /// ```text
232 /// url(): string
233 /// ```
234 pub async fn url(&self) -> Result<String, BridgeError> {
235 self.remote.call("url", vec![]).await
236 }
237
238 /// `Frame.parentFrame`
239 ///
240 /// ```text
241 /// parentFrame(): Frame | null
242 /// ```
243 pub async fn parent_frame(&self) -> Result<Option<Frame>, BridgeError> {
244 self.remote.call("parentFrame", vec![]).await
245 }
246
247 /// `Frame.childFrames`
248 ///
249 /// ```text
250 /// childFrames(): Frame[]
251 /// ```
252 pub async fn child_frames(&self) -> Result<Vec<Frame>, BridgeError> {
253 self.remote.call("childFrames", vec![]).await
254 }
255
256 /// `Frame.detached`
257 ///
258 /// ```text
259 /// get detached(): boolean
260 /// ```
261 pub async fn detached(&self) -> Result<bool, BridgeError> {
262 self.remote.get("detached").await
263 }
264
265 /// `Frame.isDetached`
266 ///
267 /// ```text
268 /// isDetached(): boolean
269 /// ```
270 pub async fn is_detached(&self) -> Result<bool, BridgeError> {
271 self.remote.call("isDetached", vec![]).await
272 }
273
274 /// `Frame.addScriptTag`
275 ///
276 /// ```text
277 /// addScriptTag(options: FrameAddScriptTagOptions): Promise<ElementHandle<HTMLScriptElement>>
278 /// ```
279 pub async fn add_script_tag(&self, options: Value) -> Result<ElementHandle, BridgeError> {
280 self.remote.call("addScriptTag", vec![Some(options)]).await
281 }
282
283 /// `Frame.addStyleTag`
284 ///
285 /// ```text
286 /// addStyleTag(options: Omit<FrameAddStyleTagOptions, 'url'>): Promise<ElementHandle<HTMLStyleElement>>
287 /// addStyleTag(options: FrameAddStyleTagOptions): Promise<ElementHandle<HTMLLinkElement>>
288 /// ```
289 pub async fn add_style_tag(&self, options: Value) -> Result<ElementHandle, BridgeError> {
290 self.remote.call("addStyleTag", vec![Some(options)]).await
291 }
292
293 /// `Frame.click`
294 ///
295 /// ```text
296 /// click(selector: string, options?: Readonly<ClickOptions>): Promise<void>
297 /// ```
298 pub async fn click(&self, selector: &str, options: Option<Value>) -> Result<(), BridgeError> {
299 self.remote.call("click", vec![Some(Value::from(selector)), options]).await
300 }
301
302 /// `Frame.focus`
303 ///
304 /// ```text
305 /// focus(selector: string): Promise<void>
306 /// ```
307 pub async fn focus(&self, selector: &str) -> Result<(), BridgeError> {
308 self.remote.call("focus", vec![Some(Value::from(selector))]).await
309 }
310
311 /// `Frame.hover`
312 ///
313 /// ```text
314 /// hover(selector: string): Promise<void>
315 /// ```
316 pub async fn hover(&self, selector: &str) -> Result<(), BridgeError> {
317 self.remote.call("hover", vec![Some(Value::from(selector))]).await
318 }
319
320 /// `Frame.select`
321 ///
322 /// ```text
323 /// select(selector: string, ...values: string[]): Promise<string[]>
324 /// ```
325 pub async fn select(&self, selector: &str, values: &[&str]) -> Result<Vec<String>, BridgeError> {
326 let mut call_args: Vec<Option<Value>> = vec![Some(Value::from(selector))];
327 call_args.extend(values.iter().map(|v| Some(Value::from(*v))));
328 self.remote.call("select", call_args).await
329 }
330
331 /// `Frame.tap`
332 ///
333 /// ```text
334 /// tap(selector: string): Promise<void>
335 /// ```
336 pub async fn tap(&self, selector: &str) -> Result<(), BridgeError> {
337 self.remote.call("tap", vec![Some(Value::from(selector))]).await
338 }
339
340 /// `Frame.type`
341 ///
342 /// ```text
343 /// type(selector: string, text: string, options?: Readonly<KeyboardTypeOptions>): Promise<void>
344 /// ```
345 pub async fn r#type(&self, selector: &str, text: &str, options: Option<Value>) -> Result<(), BridgeError> {
346 self.remote.call("type", vec![Some(Value::from(selector)), Some(Value::from(text)), options]).await
347 }
348
349 /// `Frame.title`
350 ///
351 /// ```text
352 /// title(): Promise<string>
353 /// ```
354 pub async fn title(&self) -> Result<String, BridgeError> {
355 self.remote.call("title", vec![]).await
356 }
357
358 /// `Frame.extensionRealms`
359 ///
360 /// ```text
361 /// extensionRealms(): Realm[]
362 /// ```
363 pub async fn extension_realms(&self) -> Result<Vec<Realm>, BridgeError> {
364 self.remote.call("extensionRealms", vec![]).await
365 }
366}