Browsr Client
Rust client for browser automation via the Browsr API.
Installation
[]
= { = "../browsr-client" }
Configuration
Environment Variables
| Variable | Description | Default |
|---|---|---|
BROWSR_BASE_URL |
Base URL of the Browsr server | https://api.browsr.dev |
BROWSR_API_KEY |
API key for authentication | None (optional for local) |
BROWSR_API_URL |
Legacy alias for BROWSR_BASE_URL |
None |
BROWSR_HOST / BROWSR_PORT |
Alternative local server specification | None |
Initialization
use ;
// From environment variables (recommended for production)
let client = from_env;
// Local development (no auth needed)
let client = new;
// With API key authentication
let client = new
.with_api_key;
// Explicit configuration
let config = new
.with_api_key
.with_timeout
.with_headless;
let client = from_client_config;
API Reference
Session Management
// List sessions
let sessions = client.list_sessions.await?;
// Create a session
let session_id = client.create_session.await?;
// Destroy a session
client.destroy_session.await?;
Navigation
// Navigate to a URL
let response = client.navigate.await?;
Element Interaction
// Click an element
client.click.await?;
// Type text into an input
client.type_text.await?;
// Wait for an element
client.wait_for_element.await?;
Content Extraction
// Get page title
let response = client.get_title.await?;
// Get element text
let response = client.get_text.await?;
// Get HTML content
let response = client.get_content.await?;
Structured Extraction (AI-powered)
// Extract structured data using natural language
let response = client.extract_structured.await?;
Screenshots
// Take a screenshot
let response = client.screenshot.await?; // viewport only
// Full page screenshot
let response = client.screenshot.await?;
JavaScript Execution
// Evaluate JavaScript
let response = client.evaluate.await?;
Observation
Get a complete snapshot of the browser state:
use ObserveOptions;
let options = ObserveOptions ;
let observation = client.observe.await?;
println!;
println!;
Web Scraping
use BrowsrClient;
use ScrapeApiRequest;
// Simple URL scraping
let result = client.scrape_url.await?;
// With full options
let request = new;
let result = client.scrape_v1.await?;
Web Search
// Simple search
let results = client.search_query.await?;
// With options
use SearchOptions;
let options = SearchOptions ;
let results = client.search.await?;
Low-Level Command Execution
use Commands;
// Execute multiple commands
let commands = vec!;
let response = client.execute_commands.await?;
Utilities
// Check if client has API key configured
if client.has_auth
// Check if using local server
if client.is_local
// Get base URL
let url = client.base_url;
Error Handling
use ClientError;
match client.navigate.await
Complete Example
use ;
async