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 `Frame` (puppeteer-core 25.10.0), a remote object
    /// served by `browser-commander serve --stdio`.
    ///
    /// Extends [`EventEmitter`]; the inherited methods are repeated here.
    Frame
);

impl Frame {
    /// `EventEmitter.on`
    ///
    /// ```text
    /// on<Key extends keyof EventsWithWildcard<Events>>(type: Key, handler: Handler<EventsWithWildcard<Events>[Key]>): this
    /// ```
    pub async fn on(&self, type_: Value, handler: impl Into<JsFunction>) -> Result<Frame, BridgeError> {
        self.remote.call("on", vec![Some(type_), Some(handler.into().to_wire())]).await
    }

    /// `EventEmitter.off`
    ///
    /// ```text
    /// off<Key extends keyof EventsWithWildcard<Events>>(type: Key, handler?: Handler<EventsWithWildcard<Events>[Key]>): this
    /// ```
    pub async fn off(&self, type_: Value, handler: Option<JsFunction>) -> Result<Frame, BridgeError> {
        self.remote.call("off", vec![Some(type_), handler.map(|x| x.to_wire())]).await
    }

    /// `EventEmitter.emit`
    ///
    /// ```text
    /// emit<Key extends keyof EventsWithWildcard<Events>>(type: Key, event: EventsWithWildcard<Events>[Key]): boolean
    /// ```
    pub async fn emit(&self, type_: Value, event: Value) -> Result<bool, BridgeError> {
        self.remote.call("emit", vec![Some(type_), Some(event)]).await
    }

    /// `EventEmitter.once`
    ///
    /// ```text
    /// once<Key extends keyof EventsWithWildcard<Events>>(type: Key, handler: Handler<EventsWithWildcard<Events>[Key]>): this
    /// ```
    pub async fn once(&self, type_: Value, handler: impl Into<JsFunction>) -> Result<Frame, BridgeError> {
        self.remote.call("once", vec![Some(type_), Some(handler.into().to_wire())]).await
    }

    /// `EventEmitter.listenerCount`
    ///
    /// ```text
    /// listenerCount(type: keyof EventsWithWildcard<Events>): number
    /// ```
    pub async fn listener_count(&self, type_: Value) -> Result<f64, BridgeError> {
        self.remote.call("listenerCount", vec![Some(type_)]).await
    }

    /// `EventEmitter.removeAllListeners`
    ///
    /// ```text
    /// removeAllListeners(type?: keyof EventsWithWildcard<Events>): this
    /// ```
    pub async fn remove_all_listeners(&self, type_: Option<Value>) -> Result<Frame, BridgeError> {
        self.remote.call("removeAllListeners", vec![type_]).await
    }

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

    /// `Frame.goto`
    ///
    /// ```text
    /// goto(url: string, options?: GoToOptions): Promise<HTTPResponse | null>
    /// ```
    pub async fn goto(&self, url: &str, options: Option<Value>) -> Result<Option<HTTPResponse>, BridgeError> {
        self.remote.call("goto", vec![Some(Value::from(url)), options]).await
    }

    /// `Frame.waitForNavigation`
    ///
    /// ```text
    /// waitForNavigation(options?: WaitForOptions): Promise<HTTPResponse | null>
    /// ```
    pub async fn wait_for_navigation(&self, options: Option<Value>) -> Result<Option<HTTPResponse>, BridgeError> {
        self.remote.call("waitForNavigation", vec![options]).await
    }

    /// `Frame.frameElement`
    ///
    /// ```text
    /// frameElement(): Promise<HandleFor<HTMLIFrameElement> | null>
    /// ```
    pub async fn frame_element(&self) -> Result<Option<JSHandle>, BridgeError> {
        self.remote.call("frameElement", vec![]).await
    }

    /// `Frame.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
    }

    /// `Frame.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
    }

    /// `Frame.locator`
    ///
    /// ```text
    /// locator<Selector extends string>(selector: Selector): Locator<NodeFor<Selector>>
    /// locator<Ret>(func: () => Awaitable<Ret>): Locator<Ret>
    /// ```
    pub async fn locator(&self, selector: impl Into<JsFunction>) -> Result<Locator, BridgeError> {
        self.remote.call("locator", vec![Some(selector.into().to_wire())]).await
    }

    /// `Frame.$`
    ///
    /// ```text
    /// $<Selector extends string>(selector: Selector): Promise<ElementHandle<NodeFor<Selector>> | null>
    /// ```
    pub async fn query_selector(&self, selector: &str) -> Result<Option<ElementHandle>, BridgeError> {
        self.remote.call("$", vec![Some(Value::from(selector))]).await
    }

    /// `Frame.$$`
    ///
    /// ```text
    /// $$<Selector extends string>(selector: Selector, options?: QueryOptions): Promise<Array<ElementHandle<NodeFor<Selector>>>>
    /// ```
    pub async fn query_selector_all(&self, selector: &str, options: Option<Value>) -> Result<Vec<ElementHandle>, BridgeError> {
        self.remote.call("$$", vec![Some(Value::from(selector)), options]).await
    }

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

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

    /// `Frame.waitForSelector`
    ///
    /// ```text
    /// waitForSelector<Selector extends string>(selector: Selector, options?: WaitForSelectorOptions): Promise<ElementHandle<NodeFor<Selector>> | null>
    /// ```
    pub async fn wait_for_selector(&self, selector: &str, options: Option<Value>) -> Result<Option<ElementHandle>, BridgeError> {
        self.remote.call("waitForSelector", vec![Some(Value::from(selector)), options]).await
    }

    /// `Frame.waitForFunction`
    ///
    /// ```text
    /// waitForFunction<Params extends unknown[], Func extends EvaluateFunc<Params> = EvaluateFunc<Params>>(pageFunction: Func | string, options?: FrameWaitForFunctionOptions, ...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
    }

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

    /// `Frame.setContent`
    ///
    /// ```text
    /// setContent(html: string, options?: SetContentWaitForOptions): Promise<void>
    /// ```
    pub async fn set_content(&self, html: &str, options: Option<Value>) -> Result<(), BridgeError> {
        self.remote.call("setContent", vec![Some(Value::from(html)), options]).await
    }

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

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

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

    /// `Frame.childFrames`
    ///
    /// ```text
    /// childFrames(): Frame[]
    /// ```
    pub async fn child_frames(&self) -> Result<Vec<Frame>, BridgeError> {
        self.remote.call("childFrames", vec![]).await
    }

    /// `Frame.detached`
    ///
    /// ```text
    /// get detached(): boolean
    /// ```
    pub async fn detached(&self) -> Result<bool, BridgeError> {
        self.remote.get("detached").await
    }

    /// `Frame.isDetached`
    ///
    /// ```text
    /// isDetached(): boolean
    /// ```
    pub async fn is_detached(&self) -> Result<bool, BridgeError> {
        self.remote.call("isDetached", vec![]).await
    }

    /// `Frame.addScriptTag`
    ///
    /// ```text
    /// addScriptTag(options: FrameAddScriptTagOptions): Promise<ElementHandle<HTMLScriptElement>>
    /// ```
    pub async fn add_script_tag(&self, options: Value) -> Result<ElementHandle, BridgeError> {
        self.remote.call("addScriptTag", vec![Some(options)]).await
    }

    /// `Frame.addStyleTag`
    ///
    /// ```text
    /// addStyleTag(options: Omit<FrameAddStyleTagOptions, 'url'>): Promise<ElementHandle<HTMLStyleElement>>
    /// addStyleTag(options: FrameAddStyleTagOptions): Promise<ElementHandle<HTMLLinkElement>>
    /// ```
    pub async fn add_style_tag(&self, options: Value) -> Result<ElementHandle, BridgeError> {
        self.remote.call("addStyleTag", vec![Some(options)]).await
    }

    /// `Frame.click`
    ///
    /// ```text
    /// click(selector: string, options?: Readonly<ClickOptions>): Promise<void>
    /// ```
    pub async fn click(&self, selector: &str, options: Option<Value>) -> Result<(), BridgeError> {
        self.remote.call("click", vec![Some(Value::from(selector)), options]).await
    }

    /// `Frame.focus`
    ///
    /// ```text
    /// focus(selector: string): Promise<void>
    /// ```
    pub async fn focus(&self, selector: &str) -> Result<(), BridgeError> {
        self.remote.call("focus", vec![Some(Value::from(selector))]).await
    }

    /// `Frame.hover`
    ///
    /// ```text
    /// hover(selector: string): Promise<void>
    /// ```
    pub async fn hover(&self, selector: &str) -> Result<(), BridgeError> {
        self.remote.call("hover", vec![Some(Value::from(selector))]).await
    }

    /// `Frame.select`
    ///
    /// ```text
    /// select(selector: string, ...values: string[]): Promise<string[]>
    /// ```
    pub async fn select(&self, selector: &str, values: &[&str]) -> Result<Vec<String>, BridgeError> {
        let mut call_args: Vec<Option<Value>> = vec![Some(Value::from(selector))];
        call_args.extend(values.iter().map(|v| Some(Value::from(*v))));
        self.remote.call("select", call_args).await
    }

    /// `Frame.tap`
    ///
    /// ```text
    /// tap(selector: string): Promise<void>
    /// ```
    pub async fn tap(&self, selector: &str) -> Result<(), BridgeError> {
        self.remote.call("tap", vec![Some(Value::from(selector))]).await
    }

    /// `Frame.type`
    ///
    /// ```text
    /// type(selector: string, text: string, options?: Readonly<KeyboardTypeOptions>): Promise<void>
    /// ```
    pub async fn r#type(&self, selector: &str, text: &str, options: Option<Value>) -> Result<(), BridgeError> {
        self.remote.call("type", vec![Some(Value::from(selector)), Some(Value::from(text)), options]).await
    }

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

    /// `Frame.extensionRealms`
    ///
    /// ```text
    /// extensionRealms(): Realm[]
    /// ```
    pub async fn extension_realms(&self) -> Result<Vec<Realm>, BridgeError> {
        self.remote.call("extensionRealms", vec![]).await
    }
}