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

impl Locator {
    /// `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<Locator, 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<Locator, 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<Locator, 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<Locator, BridgeError> {
        self.remote.call("removeAllListeners", vec![type_]).await
    }

    /// `Locator.timeout`
    ///
    /// ```text
    /// get timeout(): number
    /// ```
    pub async fn timeout(&self) -> Result<f64, BridgeError> {
        self.remote.get("timeout").await
    }

    /// `Locator.setTimeout`
    ///
    /// ```text
    /// setTimeout(timeout: number): Locator<T>
    /// ```
    pub async fn set_timeout(&self, timeout: f64) -> Result<Locator, BridgeError> {
        self.remote.call("setTimeout", vec![Some(Value::from(timeout))]).await
    }

    /// `Locator.setVisibility`
    ///
    /// ```text
    /// setVisibility<NodeType extends Node>(this: Locator<NodeType>, visibility: VisibilityOption): Locator<NodeType>
    /// ```
    pub async fn set_visibility(&self, this: &Locator, visibility: Option<&str>) -> Result<Locator, BridgeError> {
        self.remote.call("setVisibility", vec![Some(this.remote().to_wire()), Some(visibility.map(|x| Value::from(x)).unwrap_or(Value::Null))]).await
    }

    /// `Locator.setWaitForEnabled`
    ///
    /// ```text
    /// setWaitForEnabled<NodeType extends Node>(this: Locator<NodeType>, value: boolean): Locator<NodeType>
    /// ```
    pub async fn set_wait_for_enabled(&self, this: &Locator, value: bool) -> Result<Locator, BridgeError> {
        self.remote.call("setWaitForEnabled", vec![Some(this.remote().to_wire()), Some(Value::from(value))]).await
    }

    /// `Locator.setEnsureElementIsInTheViewport`
    ///
    /// ```text
    /// setEnsureElementIsInTheViewport<ElementType extends Element>(this: Locator<ElementType>, value: boolean): Locator<ElementType>
    /// ```
    pub async fn set_ensure_element_is_in_the_viewport(&self, this: &Locator, value: bool) -> Result<Locator, BridgeError> {
        self.remote.call("setEnsureElementIsInTheViewport", vec![Some(this.remote().to_wire()), Some(Value::from(value))]).await
    }

    /// `Locator.setWaitForStableBoundingBox`
    ///
    /// ```text
    /// setWaitForStableBoundingBox<ElementType extends Element>(this: Locator<ElementType>, value: boolean): Locator<ElementType>
    /// ```
    pub async fn set_wait_for_stable_bounding_box(&self, this: &Locator, value: bool) -> Result<Locator, BridgeError> {
        self.remote.call("setWaitForStableBoundingBox", vec![Some(this.remote().to_wire()), Some(Value::from(value))]).await
    }

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

    /// `Locator.waitHandle`
    ///
    /// ```text
    /// waitHandle(options?: Readonly<ActionOptions>): Promise<HandleFor<T>>
    /// ```
    pub async fn wait_handle(&self, options: Option<Value>) -> Result<JSHandle, BridgeError> {
        self.remote.call("waitHandle", vec![options]).await
    }

    /// `Locator.wait`
    ///
    /// ```text
    /// wait(options?: Readonly<ActionOptions>): Promise<T>
    /// ```
    pub async fn wait(&self, options: Option<Value>) -> Result<Value, BridgeError> {
        self.remote.call("wait", vec![options]).await
    }

    /// `Locator.map`
    ///
    /// ```text
    /// map<To>(mapper: Mapper<T, To>): Locator<To>
    /// ```
    pub async fn map(&self, mapper: impl Into<JsFunction>) -> Result<Locator, BridgeError> {
        self.remote.call("map", vec![Some(mapper.into().to_wire())]).await
    }

    /// `Locator.filter`
    ///
    /// ```text
    /// filter<S extends T>(predicate: Predicate<T, S>): Locator<S>
    /// ```
    pub async fn filter(&self, predicate: impl Into<JsFunction>) -> Result<Locator, BridgeError> {
        self.remote.call("filter", vec![Some(predicate.into().to_wire())]).await
    }

    /// `Locator.click`
    ///
    /// ```text
    /// click<ElementType extends Element>(this: Locator<ElementType>, options?: Readonly<LocatorClickOptions>): Promise<void>
    /// ```
    pub async fn click(&self, this: &Locator, options: Option<Value>) -> Result<(), BridgeError> {
        self.remote.call("click", vec![Some(this.remote().to_wire()), options]).await
    }

    /// `Locator.fill`
    ///
    /// ```text
    /// fill<ElementType extends Element>(this: Locator<ElementType>, value: string | boolean, options?: Readonly<LocatorFillOptions>): Promise<void>
    /// ```
    pub async fn fill(&self, this: &Locator, value: Value, options: Option<Value>) -> Result<(), BridgeError> {
        self.remote.call("fill", vec![Some(this.remote().to_wire()), Some(value), options]).await
    }

    /// `Locator.hover`
    ///
    /// ```text
    /// hover<ElementType extends Element>(this: Locator<ElementType>, options?: Readonly<ActionOptions>): Promise<void>
    /// ```
    pub async fn hover(&self, this: &Locator, options: Option<Value>) -> Result<(), BridgeError> {
        self.remote.call("hover", vec![Some(this.remote().to_wire()), options]).await
    }

    /// `Locator.scroll`
    ///
    /// ```text
    /// scroll<ElementType extends Element>(this: Locator<ElementType>, options?: Readonly<LocatorScrollOptions>): Promise<void>
    /// ```
    pub async fn scroll(&self, this: &Locator, options: Option<Value>) -> Result<(), BridgeError> {
        self.remote.call("scroll", vec![Some(this.remote().to_wire()), options]).await
    }
}