browser-commander 0.17.0

Universal browser automation library that supports multiple browser engines with a unified API
Documentation
// @generated by scripts/generate-puppeteer-bindings.mjs from
// rust/protocol/puppeteer/api.json. Do not edit by hand.

#![allow(clippy::all, missing_docs, unused_imports, non_snake_case)]

use serde_json::Value;

use super::*;
use crate::puppeteer::bridge::{binary, remote_type, BridgeError, JsFunction, Remote};

remote_type!(
    /// Puppeteer's `Realm` (puppeteer-core 25.10.0), a remote object
    /// served by `browser-commander serve --stdio`.
    Realm
);

impl Realm {
    /// `Realm.origin`
    ///
    /// ```text
    /// get origin(): string | undefined
    /// ```
    pub async fn origin(&self) -> Result<Option<String>, BridgeError> {
        self.remote.get("origin").await
    }

    /// `Realm.extension`
    ///
    /// ```text
    /// extension(): Promise<Extension | null>
    /// ```
    pub async fn extension(&self) -> Result<Option<Extension>, BridgeError> {
        self.remote.call("extension", vec![]).await
    }

    /// `Realm.evaluateHandle`
    ///
    /// ```text
    /// evaluateHandle<Params extends unknown[], Func extends EvaluateFunc<Params> = EvaluateFunc<Params>>(pageFunction: Func | string, ...args: Params ): Promise<HandleFor<Awaited<ReturnType<Func>>>>
    /// ```
    pub async fn evaluate_handle(&self, page_function: impl Into<JsFunction>, args: &[Value]) -> Result<JSHandle, BridgeError> {
        let mut call_args: Vec<Option<Value>> = vec![Some(page_function.into().to_wire())];
        call_args.extend(args.iter().map(|v| Some(v.clone())));
        self.remote.call("evaluateHandle", call_args).await
    }

    /// `Realm.evaluate`
    ///
    /// ```text
    /// evaluate<Params extends unknown[], Func extends EvaluateFunc<Params> = EvaluateFunc<Params>>(pageFunction: Func | string, ...args: Params ): Promise<Awaited<ReturnType<Func>>>
    /// ```
    pub async fn evaluate(&self, page_function: impl Into<JsFunction>, args: &[Value]) -> Result<Value, BridgeError> {
        let mut call_args: Vec<Option<Value>> = vec![Some(page_function.into().to_wire())];
        call_args.extend(args.iter().map(|v| Some(v.clone())));
        self.remote.call("evaluate", call_args).await
    }

    /// `Realm.waitForFunction`
    ///
    /// ```text
    /// 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>>>>
    /// ```
    pub async fn wait_for_function(&self, page_function: impl Into<JsFunction>, options: Option<Value>, args: &[Value]) -> Result<JSHandle, BridgeError> {
        let mut call_args: Vec<Option<Value>> = vec![Some(page_function.into().to_wire()), options];
        call_args.extend(args.iter().map(|v| Some(v.clone())));
        self.remote.call("waitForFunction", call_args).await
    }
}