BrowsrClient

Struct BrowsrClient 

Source
pub struct BrowsrClient { /* private fields */ }
Expand description

Browsr HTTP client for browser automation.

§Example

use browsr_client::BrowsrClient;

// From environment variables (BROWSR_BASE_URL, BROWSR_API_KEY)
let client = BrowsrClient::from_env();

// From explicit URL (for local development)
let client = BrowsrClient::new("http://localhost:8082");

// With API key authentication
let client = BrowsrClient::new("https://api.browsr.dev")
    .with_api_key("your-api-key");

Implementations§

Source§

impl BrowsrClient

Source

pub fn new(base_url: impl Into<String>) -> Self

Create a new client with the specified base URL (no authentication). For local development, use this method.

Source

pub fn from_env() -> Self

Create a new client from environment variables.

  • BROWSR_BASE_URL: Base URL (defaults to https://api.browsr.dev)
  • BROWSR_API_KEY: Optional API key for authentication
Source

pub fn from_client_config(config: BrowsrClientConfig) -> Self

Create a new client from explicit configuration.

Source

pub fn with_api_key(self, api_key: impl Into<String>) -> Self

Set the API key for authentication. This rebuilds the HTTP client with the new authentication header.

Source

pub fn new_http(base_url: impl Into<String>) -> Self

Create HTTP transport client (legacy method).

Source

pub fn new_stdout(command: impl Into<String>) -> Self

Create stdout transport client.

Source

pub fn from_config(cfg: TransportConfig) -> Self

Create client from transport config (legacy method).

Source

pub fn base_url(&self) -> &str

Get the base URL.

Source

pub fn config(&self) -> &BrowsrClientConfig

Get the current configuration.

Source

pub fn has_auth(&self) -> bool

Check if the client has authentication configured.

Source

pub fn is_local(&self) -> bool

Check if this is a local development client.

Source

pub async fn list_sessions(&self) -> Result<Vec<String>, ClientError>

List all active browser sessions.

Source

pub async fn create_session(&self) -> Result<String, ClientError>

Create a new browser session.

Source

pub async fn destroy_session(&self, session_id: &str) -> Result<(), ClientError>

Destroy a browser session.

Source

pub async fn execute_commands( &self, commands: Vec<Commands>, session_id: Option<String>, headless: Option<bool>, context: Option<BrowserContext>, ) -> Result<AutomateResponse, ClientError>

Execute a list of browser commands.

Source

pub async fn execute_command( &self, command: Commands, session_id: Option<String>, headless: Option<bool>, ) -> Result<AutomateResponse, ClientError>

Execute a single browser command.

Source

pub async fn navigate( &self, url: &str, session_id: Option<String>, ) -> Result<AutomateResponse, ClientError>

Navigate to a URL.

Source

pub async fn click( &self, selector: &str, session_id: Option<String>, ) -> Result<AutomateResponse, ClientError>

Click an element by selector.

Source

pub async fn type_text( &self, selector: &str, text: &str, clear: Option<bool>, session_id: Option<String>, ) -> Result<AutomateResponse, ClientError>

Type text into an element.

Source

pub async fn wait_for_element( &self, selector: &str, timeout_ms: Option<u64>, session_id: Option<String>, ) -> Result<AutomateResponse, ClientError>

Wait for an element to appear.

Source

pub async fn screenshot( &self, full_page: bool, session_id: Option<String>, ) -> Result<AutomateResponse, ClientError>

Take a screenshot.

Source

pub async fn get_title( &self, session_id: Option<String>, ) -> Result<AutomateResponse, ClientError>

Get page title.

Source

pub async fn get_text( &self, selector: &str, session_id: Option<String>, ) -> Result<AutomateResponse, ClientError>

Get text content of an element.

Source

pub async fn get_content( &self, selector: Option<String>, session_id: Option<String>, ) -> Result<AutomateResponse, ClientError>

Get HTML content of an element or page.

Source

pub async fn evaluate( &self, expression: &str, session_id: Option<String>, ) -> Result<AutomateResponse, ClientError>

Evaluate JavaScript expression.

Source

pub async fn extract_structured( &self, query: &str, schema: Option<Value>, max_chars: Option<usize>, session_id: Option<String>, ) -> Result<AutomateResponse, ClientError>

Extract structured content from the current page using AI.

§Arguments
  • query - Natural language description of what to extract
  • schema - Optional JSON schema for the output
  • max_chars - Optional maximum characters to process
  • session_id - Optional session ID
§Example
let data = client.extract_structured(
    "Extract all product names and prices",
    None,
    None,
).await?;
Source

pub async fn observe( &self, session_id: Option<String>, headless: Option<bool>, opts: ObserveOptions, ) -> Result<ObserveResponse, ClientError>

Observe the current browser state (screenshot + DOM snapshot).

Source

pub async fn scrape(&self, options: ScrapeOptions) -> Result<Value, ClientError>

Scrape content from a URL or the current page.

Source

pub async fn scrape_url(&self, url: &str) -> Result<Value, ClientError>

Scrape a URL with default options.

Source

pub async fn search( &self, options: SearchOptions, ) -> Result<SearchResponse, ClientError>

Perform a web search.

Source

pub async fn search_query( &self, query: &str, ) -> Result<SearchResponse, ClientError>

Search with a query string.

Trait Implementations§

Source§

impl Clone for BrowsrClient

Source§

fn clone(&self) -> BrowsrClient

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BrowsrClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more