Skip to main content

browser_commander/puppeteer/api/
element_handle.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 `ElementHandle` (puppeteer-core 25.10.0), a remote object
13    /// served by `browser-commander serve --stdio`.
14    ///
15    /// Extends [`JSHandle`]; the inherited methods are repeated here.
16    ElementHandle
17);
18
19impl ElementHandle {
20    /// `JSHandle.evaluate`
21    ///
22    /// ```text
23    /// evaluate<Params extends unknown[], Func extends EvaluateFuncWith<T, Params> = EvaluateFuncWith<T, Params>>(pageFunction: Func | string, ...args: Params ): Promise<Awaited<ReturnType<Func>>>
24    /// ```
25    pub async fn evaluate(&self, page_function: impl Into<JsFunction>, args: &[Value]) -> Result<Value, BridgeError> {
26        let mut call_args: Vec<Option<Value>> = vec![Some(page_function.into().to_wire())];
27        call_args.extend(args.iter().map(|v| Some(v.clone())));
28        self.remote.call("evaluate", call_args).await
29    }
30
31    /// `JSHandle.evaluateHandle`
32    ///
33    /// ```text
34    /// evaluateHandle<Params extends unknown[], Func extends EvaluateFuncWith<T, Params> = EvaluateFuncWith<T, Params>>(pageFunction: Func | string, ...args: Params ): Promise<HandleFor<Awaited<ReturnType<Func>>>>
35    /// ```
36    pub async fn evaluate_handle(&self, page_function: impl Into<JsFunction>, args: &[Value]) -> Result<JSHandle, BridgeError> {
37        let mut call_args: Vec<Option<Value>> = vec![Some(page_function.into().to_wire())];
38        call_args.extend(args.iter().map(|v| Some(v.clone())));
39        self.remote.call("evaluateHandle", call_args).await
40    }
41
42    /// `JSHandle.getProperty`
43    ///
44    /// ```text
45    /// getProperty<K extends keyof T>(propertyName: HandleOr<K>): Promise<HandleFor<T[K]>>
46    /// getProperty(propertyName: string): Promise<JSHandle<unknown>>
47    /// ```
48    pub async fn get_property(&self, property_name: Value) -> Result<JSHandle, BridgeError> {
49        self.remote.call("getProperty", vec![Some(property_name)]).await
50    }
51
52    /// `JSHandle.getProperties`
53    ///
54    /// ```text
55    /// getProperties(): Promise<Map<string, JSHandle>>
56    /// ```
57    pub async fn get_properties(&self) -> Result<Value, BridgeError> {
58        self.remote.call("getProperties", vec![]).await
59    }
60
61    /// `JSHandle.jsonValue`
62    ///
63    /// ```text
64    /// jsonValue(): Promise<T>
65    /// ```
66    pub async fn json_value(&self) -> Result<Value, BridgeError> {
67        self.remote.call("jsonValue", vec![]).await
68    }
69
70    /// `JSHandle.asElement`
71    ///
72    /// ```text
73    /// asElement(): ElementHandle<Node> | null
74    /// ```
75    pub async fn as_element(&self) -> Result<Option<ElementHandle>, BridgeError> {
76        self.remote.call("asElement", vec![]).await
77    }
78
79    /// `JSHandle.dispose`
80    ///
81    /// ```text
82    /// dispose(): Promise<void>
83    /// ```
84    pub async fn dispose(&self) -> Result<(), BridgeError> {
85        self.remote.call("dispose", vec![]).await
86    }
87
88    /// `JSHandle.toString`
89    ///
90    /// ```text
91    /// toString(): string
92    /// ```
93    pub async fn to_string(&self) -> Result<String, BridgeError> {
94        self.remote.call("toString", vec![]).await
95    }
96
97    /// `JSHandle.remoteObject`
98    ///
99    /// ```text
100    /// remoteObject(): Protocol.Runtime.RemoteObject
101    /// ```
102    pub async fn remote_object(&self) -> Result<Value, BridgeError> {
103        self.remote.call("remoteObject", vec![]).await
104    }
105
106    /// `ElementHandle.frame`
107    ///
108    /// ```text
109    /// get frame(): Frame
110    /// ```
111    pub async fn frame(&self) -> Result<Frame, BridgeError> {
112        self.remote.get("frame").await
113    }
114
115    /// `ElementHandle.$`
116    ///
117    /// ```text
118    /// $<Selector extends string>(selector: Selector): Promise<ElementHandle<NodeFor<Selector>> | null>
119    /// ```
120    pub async fn query_selector(&self, selector: &str) -> Result<Option<ElementHandle>, BridgeError> {
121        self.remote.call("$", vec![Some(Value::from(selector))]).await
122    }
123
124    /// `ElementHandle.$$`
125    ///
126    /// ```text
127    /// $$<Selector extends string>(selector: Selector, options?: QueryOptions): Promise<Array<ElementHandle<NodeFor<Selector>>>>
128    /// ```
129    pub async fn query_selector_all(&self, selector: &str, options: Option<Value>) -> Result<Vec<ElementHandle>, BridgeError> {
130        self.remote.call("$$", vec![Some(Value::from(selector)), options]).await
131    }
132
133    /// `ElementHandle.$eval`
134    ///
135    /// ```text
136    /// $eval<Selector extends string, Params extends unknown[], Func extends EvaluateFuncWith<NodeFor<Selector>, Params> = EvaluateFuncWith<NodeFor<Selector>, Params >>(selector: Selector, pageFunction: Func | string, ...args: Params ): Promise<Awaited<ReturnType<Func>>>
137    /// ```
138    pub async fn eval_on_selector(&self, selector: &str, page_function: impl Into<JsFunction>, args: &[Value]) -> Result<Value, BridgeError> {
139        let mut call_args: Vec<Option<Value>> = vec![Some(Value::from(selector)), Some(page_function.into().to_wire())];
140        call_args.extend(args.iter().map(|v| Some(v.clone())));
141        self.remote.call("$eval", call_args).await
142    }
143
144    /// `ElementHandle.$$eval`
145    ///
146    /// ```text
147    /// $$eval<Selector extends string, Params extends unknown[], Func extends EvaluateFuncWith<Array<NodeFor<Selector>>, Params> = EvaluateFuncWith<Array<NodeFor<Selector>>, Params>>(selector: Selector, pageFunction: Func | string, ...args: Params ): Promise<Awaited<ReturnType<Func>>>
148    /// ```
149    pub async fn eval_on_selector_all(&self, selector: &str, page_function: impl Into<JsFunction>, args: &[Value]) -> Result<Value, BridgeError> {
150        let mut call_args: Vec<Option<Value>> = vec![Some(Value::from(selector)), Some(page_function.into().to_wire())];
151        call_args.extend(args.iter().map(|v| Some(v.clone())));
152        self.remote.call("$$eval", call_args).await
153    }
154
155    /// `ElementHandle.waitForSelector`
156    ///
157    /// ```text
158    /// waitForSelector<Selector extends string>(selector: Selector, options?: WaitForSelectorOptions): Promise<ElementHandle<NodeFor<Selector>> | null>
159    /// ```
160    pub async fn wait_for_selector(&self, selector: &str, options: Option<Value>) -> Result<Option<ElementHandle>, BridgeError> {
161        self.remote.call("waitForSelector", vec![Some(Value::from(selector)), options]).await
162    }
163
164    /// `ElementHandle.isVisible`
165    ///
166    /// ```text
167    /// isVisible(): Promise<boolean>
168    /// ```
169    pub async fn is_visible(&self) -> Result<bool, BridgeError> {
170        self.remote.call("isVisible", vec![]).await
171    }
172
173    /// `ElementHandle.isHidden`
174    ///
175    /// ```text
176    /// isHidden(): Promise<boolean>
177    /// ```
178    pub async fn is_hidden(&self) -> Result<bool, BridgeError> {
179        self.remote.call("isHidden", vec![]).await
180    }
181
182    /// `ElementHandle.toElement`
183    ///
184    /// ```text
185    /// toElement<K extends keyof HTMLElementTagNameMap | keyof SVGElementTagNameMap>(tagName: K): Promise<HandleFor<ElementFor<K>>>
186    /// ```
187    pub async fn to_element(&self, tag_name: Value) -> Result<JSHandle, BridgeError> {
188        self.remote.call("toElement", vec![Some(tag_name)]).await
189    }
190
191    /// `ElementHandle.contentFrame`
192    ///
193    /// ```text
194    /// contentFrame(this: ElementHandle<HTMLIFrameElement>): Promise<Frame>
195    /// contentFrame(): Promise<Frame | null>
196    /// ```
197    pub async fn content_frame(&self, this: Option<&ElementHandle>) -> Result<Value, BridgeError> {
198        self.remote.call("contentFrame", vec![this.map(|x| x.remote().to_wire())]).await
199    }
200
201    /// `ElementHandle.clickablePoint`
202    ///
203    /// ```text
204    /// clickablePoint(offset?: Offset): Promise<Point>
205    /// ```
206    pub async fn clickable_point(&self, offset: Option<Value>) -> Result<Value, BridgeError> {
207        self.remote.call("clickablePoint", vec![offset]).await
208    }
209
210    /// `ElementHandle.hover`
211    ///
212    /// ```text
213    /// hover(this: ElementHandle<Element>): Promise<void>
214    /// ```
215    pub async fn hover(&self, this: &ElementHandle) -> Result<(), BridgeError> {
216        self.remote.call("hover", vec![Some(this.remote().to_wire())]).await
217    }
218
219    /// `ElementHandle.click`
220    ///
221    /// ```text
222    /// click(this: ElementHandle<Element>, options?: Readonly<ClickOptions>): Promise<void>
223    /// ```
224    pub async fn click(&self, this: &ElementHandle, options: Option<Value>) -> Result<(), BridgeError> {
225        self.remote.call("click", vec![Some(this.remote().to_wire()), options]).await
226    }
227
228    /// `ElementHandle.drag`
229    ///
230    /// ```text
231    /// drag(this: ElementHandle<Element>, target: Point | ElementHandle<Element>): Promise<Protocol.Input.DragData | void>
232    /// ```
233    pub async fn drag(&self, this: &ElementHandle, target: Value) -> Result<Option<Value>, BridgeError> {
234        self.remote.call("drag", vec![Some(this.remote().to_wire()), Some(target)]).await
235    }
236
237    /// `ElementHandle.dragEnter`
238    ///
239    /// ```text
240    /// dragEnter(this: ElementHandle<Element>, data?: Protocol.Input.DragData): Promise<void>
241    /// ```
242    pub async fn drag_enter(&self, this: &ElementHandle, data: Option<Value>) -> Result<(), BridgeError> {
243        self.remote.call("dragEnter", vec![Some(this.remote().to_wire()), data]).await
244    }
245
246    /// `ElementHandle.dragOver`
247    ///
248    /// ```text
249    /// dragOver(this: ElementHandle<Element>, data?: Protocol.Input.DragData): Promise<void>
250    /// ```
251    pub async fn drag_over(&self, this: &ElementHandle, data: Option<Value>) -> Result<(), BridgeError> {
252        self.remote.call("dragOver", vec![Some(this.remote().to_wire()), data]).await
253    }
254
255    /// `ElementHandle.drop`
256    ///
257    /// ```text
258    /// drop(this: ElementHandle<Element>, element: ElementHandle<Element>): Promise<void>
259    /// drop(this: ElementHandle<Element>, data?: Protocol.Input.DragData): Promise<void>
260    /// ```
261    pub async fn drop(&self, this: &ElementHandle, element: Option<Value>) -> Result<(), BridgeError> {
262        self.remote.call("drop", vec![Some(this.remote().to_wire()), element]).await
263    }
264
265    /// `ElementHandle.dragAndDrop`
266    ///
267    /// ```text
268    /// dragAndDrop(this: ElementHandle<Element>, target: ElementHandle<Node>, options?: { delay: number; }): Promise<void>
269    /// ```
270    pub async fn drag_and_drop(&self, this: &ElementHandle, target: &ElementHandle, options: Option<Value>) -> Result<(), BridgeError> {
271        self.remote.call("dragAndDrop", vec![Some(this.remote().to_wire()), Some(target.remote().to_wire()), options]).await
272    }
273
274    /// `ElementHandle.select`
275    ///
276    /// ```text
277    /// select(...values: string[]): Promise<string[]>
278    /// ```
279    pub async fn select(&self, values: &[&str]) -> Result<Vec<String>, BridgeError> {
280        let mut call_args: Vec<Option<Value>> = vec![];
281        call_args.extend(values.iter().map(|v| Some(Value::from(*v))));
282        self.remote.call("select", call_args).await
283    }
284
285    /// `ElementHandle.uploadFile`
286    ///
287    /// ```text
288    /// uploadFile(this: ElementHandle<HTMLInputElement>, ...paths: string[] ): Promise<void>
289    /// ```
290    pub async fn upload_file(&self, this: &ElementHandle, paths: &[&str]) -> Result<(), BridgeError> {
291        let mut call_args: Vec<Option<Value>> = vec![Some(this.remote().to_wire())];
292        call_args.extend(paths.iter().map(|v| Some(Value::from(*v))));
293        self.remote.call("uploadFile", call_args).await
294    }
295
296    /// `ElementHandle.tap`
297    ///
298    /// ```text
299    /// tap(this: ElementHandle<Element>): Promise<void>
300    /// ```
301    pub async fn tap(&self, this: &ElementHandle) -> Result<(), BridgeError> {
302        self.remote.call("tap", vec![Some(this.remote().to_wire())]).await
303    }
304
305    /// `ElementHandle.touchStart`
306    ///
307    /// ```text
308    /// touchStart(this: ElementHandle<Element>): Promise<TouchHandle>
309    /// ```
310    pub async fn touch_start(&self, this: &ElementHandle) -> Result<TouchHandle, BridgeError> {
311        self.remote.call("touchStart", vec![Some(this.remote().to_wire())]).await
312    }
313
314    /// `ElementHandle.touchMove`
315    ///
316    /// ```text
317    /// touchMove(this: ElementHandle<Element>, touch?: TouchHandle): Promise<void>
318    /// ```
319    pub async fn touch_move(&self, this: &ElementHandle, touch: Option<&TouchHandle>) -> Result<(), BridgeError> {
320        self.remote.call("touchMove", vec![Some(this.remote().to_wire()), touch.map(|x| x.remote().to_wire())]).await
321    }
322
323    /// `ElementHandle.touchEnd`
324    ///
325    /// ```text
326    /// touchEnd(this: ElementHandle<Element>): Promise<void>
327    /// ```
328    pub async fn touch_end(&self, this: &ElementHandle) -> Result<(), BridgeError> {
329        self.remote.call("touchEnd", vec![Some(this.remote().to_wire())]).await
330    }
331
332    /// `ElementHandle.focus`
333    ///
334    /// ```text
335    /// focus(): Promise<void>
336    /// ```
337    pub async fn focus(&self) -> Result<(), BridgeError> {
338        self.remote.call("focus", vec![]).await
339    }
340
341    /// `ElementHandle.type`
342    ///
343    /// ```text
344    /// type(text: string, options?: Readonly<KeyboardTypeOptions>): Promise<void>
345    /// ```
346    pub async fn r#type(&self, text: &str, options: Option<Value>) -> Result<(), BridgeError> {
347        self.remote.call("type", vec![Some(Value::from(text)), options]).await
348    }
349
350    /// `ElementHandle.press`
351    ///
352    /// ```text
353    /// press(key: KeyInput, options?: Readonly<KeyPressOptions>): Promise<void>
354    /// ```
355    pub async fn press(&self, key: &str, options: Option<Value>) -> Result<(), BridgeError> {
356        self.remote.call("press", vec![Some(Value::from(key)), options]).await
357    }
358
359    /// `ElementHandle.boundingBox`
360    ///
361    /// ```text
362    /// boundingBox(): Promise<BoundingBox | null>
363    /// ```
364    pub async fn bounding_box(&self) -> Result<Option<Value>, BridgeError> {
365        self.remote.call("boundingBox", vec![]).await
366    }
367
368    /// `ElementHandle.boxModel`
369    ///
370    /// ```text
371    /// boxModel(): Promise<BoxModel | null>
372    /// ```
373    pub async fn box_model(&self) -> Result<Option<Value>, BridgeError> {
374        self.remote.call("boxModel", vec![]).await
375    }
376
377    /// `ElementHandle.screenshot`
378    ///
379    /// ```text
380    /// screenshot(options: Readonly<ScreenshotOptions> & { encoding: 'base64'; }): Promise<string>
381    /// screenshot(options?: Readonly<ScreenshotOptions>): Promise<Uint8Array>
382    /// ```
383    pub async fn screenshot(&self, options: Option<Value>) -> Result<Value, BridgeError> {
384        self.remote.call("screenshot", vec![options]).await
385    }
386
387    /// `ElementHandle.isIntersectingViewport`
388    ///
389    /// ```text
390    /// isIntersectingViewport(this: ElementHandle<Element>, options?: { threshold?: number; }): Promise<boolean>
391    /// ```
392    pub async fn is_intersecting_viewport(&self, this: &ElementHandle, options: Option<Value>) -> Result<bool, BridgeError> {
393        self.remote.call("isIntersectingViewport", vec![Some(this.remote().to_wire()), options]).await
394    }
395
396    /// `ElementHandle.scrollIntoView`
397    ///
398    /// ```text
399    /// scrollIntoView(this: ElementHandle<Element>): Promise<void>
400    /// ```
401    pub async fn scroll_into_view(&self, this: &ElementHandle) -> Result<(), BridgeError> {
402        self.remote.call("scrollIntoView", vec![Some(this.remote().to_wire())]).await
403    }
404
405    /// `ElementHandle.asLocator`
406    ///
407    /// ```text
408    /// asLocator(this: ElementHandle<Element>): Locator<Element>
409    /// ```
410    pub async fn as_locator(&self, this: &ElementHandle) -> Result<Locator, BridgeError> {
411        self.remote.call("asLocator", vec![Some(this.remote().to_wire())]).await
412    }
413
414    /// `ElementHandle.autofill`
415    ///
416    /// ```text
417    /// autofill(data: AutofillData): Promise<void>
418    /// ```
419    pub async fn autofill(&self, data: Value) -> Result<(), BridgeError> {
420        self.remote.call("autofill", vec![Some(data)]).await
421    }
422
423    /// `ElementHandle.backendNodeId`
424    ///
425    /// ```text
426    /// backendNodeId(): Promise<number>
427    /// ```
428    pub async fn backend_node_id(&self) -> Result<f64, BridgeError> {
429        self.remote.call("backendNodeId", vec![]).await
430    }
431}