Skip to main content

browser_commander/puppeteer/api/
realm.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 `Realm` (puppeteer-core 25.10.0), a remote object
13    /// served by `browser-commander serve --stdio`.
14    Realm
15);
16
17impl Realm {
18    /// `Realm.origin`
19    ///
20    /// ```text
21    /// get origin(): string | undefined
22    /// ```
23    pub async fn origin(&self) -> Result<Option<String>, BridgeError> {
24        self.remote.get("origin").await
25    }
26
27    /// `Realm.extension`
28    ///
29    /// ```text
30    /// extension(): Promise<Extension | null>
31    /// ```
32    pub async fn extension(&self) -> Result<Option<Extension>, BridgeError> {
33        self.remote.call("extension", vec![]).await
34    }
35
36    /// `Realm.evaluateHandle`
37    ///
38    /// ```text
39    /// evaluateHandle<Params extends unknown[], Func extends EvaluateFunc<Params> = EvaluateFunc<Params>>(pageFunction: Func | string, ...args: Params ): Promise<HandleFor<Awaited<ReturnType<Func>>>>
40    /// ```
41    pub async fn evaluate_handle(&self, page_function: impl Into<JsFunction>, args: &[Value]) -> Result<JSHandle, BridgeError> {
42        let mut call_args: Vec<Option<Value>> = vec![Some(page_function.into().to_wire())];
43        call_args.extend(args.iter().map(|v| Some(v.clone())));
44        self.remote.call("evaluateHandle", call_args).await
45    }
46
47    /// `Realm.evaluate`
48    ///
49    /// ```text
50    /// evaluate<Params extends unknown[], Func extends EvaluateFunc<Params> = EvaluateFunc<Params>>(pageFunction: Func | string, ...args: Params ): Promise<Awaited<ReturnType<Func>>>
51    /// ```
52    pub async fn evaluate(&self, page_function: impl Into<JsFunction>, args: &[Value]) -> Result<Value, BridgeError> {
53        let mut call_args: Vec<Option<Value>> = vec![Some(page_function.into().to_wire())];
54        call_args.extend(args.iter().map(|v| Some(v.clone())));
55        self.remote.call("evaluate", call_args).await
56    }
57
58    /// `Realm.waitForFunction`
59    ///
60    /// ```text
61    /// waitForFunction<Params extends unknown[], Func extends EvaluateFunc<Params> = EvaluateFunc<Params>>(pageFunction: Func | string, options?: { polling?: 'raf' | 'mutation' | number; timeout?: number; root?: ElementHandle<Node>; signal?: AbortSignal; }, ...args: Params ): Promise<HandleFor<Awaited<ReturnType<Func>>>>
62    /// ```
63    pub async fn wait_for_function(&self, page_function: impl Into<JsFunction>, options: Option<Value>, args: &[Value]) -> Result<JSHandle, BridgeError> {
64        let mut call_args: Vec<Option<Value>> = vec![Some(page_function.into().to_wire()), options];
65        call_args.extend(args.iter().map(|v| Some(v.clone())));
66        self.remote.call("waitForFunction", call_args).await
67    }
68}