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
impl BrowsrClient
Sourcepub fn new(base_url: impl Into<String>) -> Self
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.
Sourcepub fn from_env() -> Self
pub fn from_env() -> Self
Create a new client from environment variables.
BROWSR_BASE_URL: Base URL (defaults tohttps://api.browsr.dev)BROWSR_API_KEY: Optional API key for authentication
Sourcepub fn from_client_config(config: BrowsrClientConfig) -> Self
pub fn from_client_config(config: BrowsrClientConfig) -> Self
Create a new client from explicit configuration.
Sourcepub fn with_api_key(self, api_key: impl Into<String>) -> Self
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.
Sourcepub fn new_http(base_url: impl Into<String>) -> Self
pub fn new_http(base_url: impl Into<String>) -> Self
Create HTTP transport client (legacy method).
Sourcepub fn new_stdout(command: impl Into<String>) -> Self
pub fn new_stdout(command: impl Into<String>) -> Self
Create stdout transport client.
Sourcepub fn from_config(cfg: TransportConfig) -> Self
pub fn from_config(cfg: TransportConfig) -> Self
Create client from transport config (legacy method).
Sourcepub fn config(&self) -> &BrowsrClientConfig
pub fn config(&self) -> &BrowsrClientConfig
Get the current configuration.
Sourcepub async fn list_sessions(&self) -> Result<Vec<String>, ClientError>
pub async fn list_sessions(&self) -> Result<Vec<String>, ClientError>
List all active browser sessions.
Sourcepub async fn create_session(&self) -> Result<SessionCreated, ClientError>
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.
Sourcepub async fn destroy_session(&self, session_id: &str) -> Result<(), ClientError>
pub async fn destroy_session(&self, session_id: &str) -> Result<(), ClientError>
Destroy a browser session.
Sourcepub async fn create_shell_session(
&self,
request: ShellCreateSessionRequest,
) -> Result<ShellCreateSessionResponse, ClientError>
pub async fn create_shell_session( &self, request: ShellCreateSessionRequest, ) -> Result<ShellCreateSessionResponse, ClientError>
Create a new shell session.
Sourcepub async fn list_shell_sessions(
&self,
) -> Result<ShellSessionListResponse, ClientError>
pub async fn list_shell_sessions( &self, ) -> Result<ShellSessionListResponse, ClientError>
List active shell sessions.
Sourcepub async fn terminate_shell_session(
&self,
session_id: &str,
) -> Result<ShellTerminateResponse, ClientError>
pub async fn terminate_shell_session( &self, session_id: &str, ) -> Result<ShellTerminateResponse, ClientError>
Terminate a shell session.
Sourcepub async fn shell_exec(
&self,
request: ShellExecRequest,
) -> Result<ShellExecResponse, ClientError>
pub async fn shell_exec( &self, request: ShellExecRequest, ) -> Result<ShellExecResponse, ClientError>
Execute a shell command in an existing shell session.
Sourcepub async fn execute_commands(
&self,
commands: Vec<Commands>,
session_id: Option<String>,
headless: Option<bool>,
context: Option<BrowserContext>,
) -> Result<AutomateResponse, ClientError>
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.
Sourcepub async fn execute_command(
&self,
command: Commands,
session_id: Option<String>,
headless: Option<bool>,
) -> Result<AutomateResponse, ClientError>
pub async fn execute_command( &self, command: Commands, session_id: Option<String>, headless: Option<bool>, ) -> Result<AutomateResponse, ClientError>
Execute a single browser command.
Navigate to a URL.
Sourcepub async fn click(
&self,
selector: &str,
session_id: Option<String>,
) -> Result<AutomateResponse, ClientError>
pub async fn click( &self, selector: &str, session_id: Option<String>, ) -> Result<AutomateResponse, ClientError>
Click an element by selector.
Sourcepub async fn type_text(
&self,
selector: &str,
text: &str,
clear: Option<bool>,
session_id: Option<String>,
) -> Result<AutomateResponse, ClientError>
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.
Sourcepub async fn wait_for_element(
&self,
selector: &str,
timeout_ms: Option<u64>,
session_id: Option<String>,
) -> Result<AutomateResponse, ClientError>
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.
Sourcepub async fn screenshot(
&self,
full_page: bool,
session_id: Option<String>,
) -> Result<AutomateResponse, ClientError>
pub async fn screenshot( &self, full_page: bool, session_id: Option<String>, ) -> Result<AutomateResponse, ClientError>
Take a screenshot.
Sourcepub async fn get_title(
&self,
session_id: Option<String>,
) -> Result<AutomateResponse, ClientError>
pub async fn get_title( &self, session_id: Option<String>, ) -> Result<AutomateResponse, ClientError>
Get page title.
Sourcepub async fn get_text(
&self,
selector: &str,
session_id: Option<String>,
) -> Result<AutomateResponse, ClientError>
pub async fn get_text( &self, selector: &str, session_id: Option<String>, ) -> Result<AutomateResponse, ClientError>
Get text content of an element.
Sourcepub async fn get_content(
&self,
selector: Option<String>,
session_id: Option<String>,
) -> Result<AutomateResponse, ClientError>
pub async fn get_content( &self, selector: Option<String>, session_id: Option<String>, ) -> Result<AutomateResponse, ClientError>
Get HTML content of an element or page.
Sourcepub async fn evaluate(
&self,
expression: &str,
session_id: Option<String>,
) -> Result<AutomateResponse, ClientError>
pub async fn evaluate( &self, expression: &str, session_id: Option<String>, ) -> Result<AutomateResponse, ClientError>
Evaluate JavaScript expression.
Sourcepub async fn extract_structured(
&self,
query: &str,
schema: Option<Value>,
max_chars: Option<usize>,
session_id: Option<String>,
) -> Result<AutomateResponse, ClientError>
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 extractschema- Optional JSON schema for the outputmax_chars- Optional maximum characters to processsession_id- Optional session ID
§Example
let data = client.extract_structured(
"Extract all product names and prices",
None,
None,
).await?;Sourcepub async fn observe(
&self,
session_id: Option<String>,
headless: Option<bool>,
opts: ObserveOptions,
) -> Result<ObserveResponse, ClientError>
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).
Sourcepub async fn cdp(
&self,
session_id: impl Into<String>,
method: impl Into<String>,
params: Option<Value>,
) -> Result<Value, ClientError>
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.
Sourcepub async fn relay_events(
&self,
session_id: &str,
limit: Option<usize>,
) -> Result<RelayEventsResponse, ClientError>
pub async fn relay_events( &self, session_id: &str, limit: Option<usize>, ) -> Result<RelayEventsResponse, ClientError>
List recent buffered relay events for a relay session.
Sourcepub async fn list_relay_sessions(
&self,
) -> Result<RelaySessionListResponse, ClientError>
pub async fn list_relay_sessions( &self, ) -> Result<RelaySessionListResponse, ClientError>
List relay sessions visible to the current authenticated user.
Sourcepub async fn clear_relay_events(
&self,
session_id: &str,
) -> Result<Value, ClientError>
pub async fn clear_relay_events( &self, session_id: &str, ) -> Result<Value, ClientError>
Clear buffered relay events for a relay session.
Sourcepub async fn scrape_v1(
&self,
request: ScrapeApiRequest,
) -> Result<ScrapeApiResponse, ClientError>
pub async fn scrape_v1( &self, request: ScrapeApiRequest, ) -> Result<ScrapeApiResponse, ClientError>
Scrape a URL with full format options (v1 API).
Sourcepub async fn scrape_url(
&self,
url: &str,
) -> Result<ScrapeApiResponse, ClientError>
pub async fn scrape_url( &self, url: &str, ) -> Result<ScrapeApiResponse, ClientError>
Scrape a URL with default options (markdown output).
Sourcepub async fn crawl(
&self,
request: CrawlApiRequest,
) -> Result<CrawlApiResponse, ClientError>
pub async fn crawl( &self, request: CrawlApiRequest, ) -> Result<CrawlApiResponse, ClientError>
Crawl a website starting from a URL.
Sourcepub async fn crawl_url(
&self,
url: &str,
) -> Result<CrawlApiResponse, ClientError>
pub async fn crawl_url( &self, url: &str, ) -> Result<CrawlApiResponse, ClientError>
Crawl a URL with default options (markdown, 10 pages, depth 2).
Sourcepub async fn search(
&self,
options: SearchOptions,
) -> Result<SearchResponse, ClientError>
pub async fn search( &self, options: SearchOptions, ) -> Result<SearchResponse, ClientError>
Perform a web search via the /v1/search endpoint.
Sourcepub async fn search_query(
&self,
query: &str,
) -> Result<SearchResponse, ClientError>
pub async fn search_query( &self, query: &str, ) -> Result<SearchResponse, ClientError>
Search with a query string.
Sourcepub async fn step(
&self,
request: BrowserStepRequest,
) -> Result<BrowserStepResult, ClientError>
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);Sourcepub async fn step_commands(
&self,
commands: Vec<Commands>,
) -> Result<BrowserStepResult, ClientError>
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
impl Clone for BrowsrClient
Source§fn clone(&self) -> BrowsrClient
fn clone(&self) -> BrowsrClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more