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<String, ClientError>
pub async fn create_session(&self) -> Result<String, ClientError>
Create a new browser session.
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 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 scrape(&self, options: ScrapeOptions) -> Result<Value, ClientError>
pub async fn scrape(&self, options: ScrapeOptions) -> Result<Value, ClientError>
Scrape content from a URL or the current page.
Sourcepub async fn scrape_url(&self, url: &str) -> Result<Value, ClientError>
pub async fn scrape_url(&self, url: &str) -> Result<Value, ClientError>
Scrape a URL with default options.
Sourcepub async fn search(
&self,
options: SearchOptions,
) -> Result<SearchResponse, ClientError>
pub async fn search( &self, options: SearchOptions, ) -> Result<SearchResponse, ClientError>
Perform a web search.
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.
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