Skip to main content

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<SessionCreated, ClientError>

Create a new browser session. Returns the full session info including viewer_url, sse_url, and frame_url.

Source

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

Destroy a browser session.

Source

pub async fn create_shell_session( &self, request: ShellCreateSessionRequest, ) -> Result<ShellCreateSessionResponse, ClientError>

Create a new shell session.

Source

pub async fn list_shell_sessions( &self, ) -> Result<ShellSessionListResponse, ClientError>

List active shell sessions.

Source

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

Terminate a shell session.

Source

pub async fn shell_exec( &self, request: ShellExecRequest, ) -> Result<ShellExecResponse, ClientError>

Execute a shell command in an existing shell 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 cdp( &self, session_id: impl Into<String>, method: impl Into<String>, params: Option<Value>, ) -> Result<Value, ClientError>

Execute a raw CDP request against an existing session.

Source

pub async fn relay_events( &self, session_id: &str, limit: Option<usize>, ) -> Result<RelayEventsResponse, ClientError>

List recent buffered relay events for a relay session.

Source

pub async fn list_relay_sessions( &self, ) -> Result<RelaySessionListResponse, ClientError>

List relay sessions visible to the current authenticated user.

Source

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

Clear buffered relay events for a relay session.

Source

pub async fn scrape_v1( &self, request: ScrapeApiRequest, ) -> Result<ScrapeApiResponse, ClientError>

Scrape a URL with full format options (v1 API).

Source

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

Scrape a URL with default options (markdown output).

Source

pub async fn crawl( &self, request: CrawlApiRequest, ) -> Result<CrawlApiResponse, ClientError>

Crawl a website starting from a URL.

Source

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

Crawl a URL with default options (markdown, 10 pages, depth 2).

Source

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

Perform a web search via the /v1/search endpoint.

Source

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

Search with a query string.

Source

pub async fn step( &self, request: BrowserStepRequest, ) -> Result<BrowserStepResult, ClientError>

Execute a browser step with commands and optional context.

This is the primary method for agent integration, providing full control over browser automation with context for sequence persistence.

§Arguments
  • request - Full browser step request with commands and context
§Example
use browsr_client::{BrowsrClient, BrowserStepRequest, BrowserStepInput};
use browsr_types::Commands;

let client = BrowsrClient::from_env();

let input = BrowserStepInput::new(vec![
    Commands::NavigateTo { url: "https://example.com".to_string() },
    Commands::Screenshot { full_page: Some(false), path: None },
]);

let request = BrowserStepRequest::new(input)
    .with_session_id("my-session")
    .with_thread_id("thread-123");

let result = client.step(request).await?;
println!("Success: {}, URL: {:?}", result.success, result.url);
Source

pub async fn step_commands( &self, commands: Vec<Commands>, ) -> Result<BrowserStepResult, ClientError>

Execute a browser step with just commands (simple usage).

Use this for quick automation tasks without context tracking.

§Example
use browsr_client::BrowsrClient;
use browsr_types::Commands;

let client = BrowsrClient::from_env();

let result = client.step_commands(vec![
    Commands::NavigateTo { url: "https://example.com".to_string() },
]).await?;

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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