browser-commander 0.18.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 `JSHandle` (puppeteer-core 25.10.0), a remote object
    /// served by `browser-commander serve --stdio`.
    JSHandle
);

impl JSHandle {
    /// `JSHandle.evaluate`
    ///
    /// ```text
    /// evaluate<Params extends unknown[], Func extends EvaluateFuncWith<T, Params> = EvaluateFuncWith<T, 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
    }

    /// `JSHandle.evaluateHandle`
    ///
    /// ```text
    /// evaluateHandle<Params extends unknown[], Func extends EvaluateFuncWith<T, Params> = EvaluateFuncWith<T, 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
    }

    /// `JSHandle.getProperty`
    ///
    /// ```text
    /// getProperty<K extends keyof T>(propertyName: HandleOr<K>): Promise<HandleFor<T[K]>>
    /// getProperty(propertyName: string): Promise<JSHandle<unknown>>
    /// ```
    pub async fn get_property(&self, property_name: Value) -> Result<JSHandle, BridgeError> {
        self.remote.call("getProperty", vec![Some(property_name)]).await
    }

    /// `JSHandle.getProperties`
    ///
    /// ```text
    /// getProperties(): Promise<Map<string, JSHandle>>
    /// ```
    pub async fn get_properties(&self) -> Result<Value, BridgeError> {
        self.remote.call("getProperties", vec![]).await
    }

    /// `JSHandle.jsonValue`
    ///
    /// ```text
    /// jsonValue(): Promise<T>
    /// ```
    pub async fn json_value(&self) -> Result<Value, BridgeError> {
        self.remote.call("jsonValue", vec![]).await
    }

    /// `JSHandle.asElement`
    ///
    /// ```text
    /// asElement(): ElementHandle<Node> | null
    /// ```
    pub async fn as_element(&self) -> Result<Option<ElementHandle>, BridgeError> {
        self.remote.call("asElement", vec![]).await
    }

    /// `JSHandle.dispose`
    ///
    /// ```text
    /// dispose(): Promise<void>
    /// ```
    pub async fn dispose(&self) -> Result<(), BridgeError> {
        self.remote.call("dispose", vec![]).await
    }

    /// `JSHandle.toString`
    ///
    /// ```text
    /// toString(): string
    /// ```
    pub async fn to_string(&self) -> Result<String, BridgeError> {
        self.remote.call("toString", vec![]).await
    }

    /// `JSHandle.remoteObject`
    ///
    /// ```text
    /// remoteObject(): Protocol.Runtime.RemoteObject
    /// ```
    pub async fn remote_object(&self) -> Result<Value, BridgeError> {
        self.remote.call("remoteObject", vec![]).await
    }
}