Browser Commander
A Rust library for universal browser automation that provides a unified API for different browser automation engines. The key focus is on stoppable page triggers - ensuring automation logic is properly mounted/unmounted during page navigation.
Installation
Add this to your Cargo.toml:
[]
= "0.4"
= { = "1.0", = ["full"] }
Core Concept: Page State Machine
Browser Commander manages the browser as a state machine with two states:
+------------------+ +------------------+
| | navigation start | |
| WORKING STATE | -------------------> | LOADING STATE |
| (action runs) | | (wait only) |
| | <----------------- | |
+------------------+ page ready +------------------+
LOADING STATE: Page is loading. Only waiting/tracking operations are allowed. No automation logic runs.
WORKING STATE: Page is fully loaded (30 seconds of network idle). Page triggers can safely interact with DOM.
Quick Start
use *;
async
Features
- Unified API across multiple browser engines
- Built-in navigation safety handling
- Element visibility and scroll management
- Click, fill, and other interaction support with verification
- Async/await support with Tokio
API Reference
Browser Launch
use *;
// Launch with chromiumoxide (CDP-based)
let options = chromiumoxide
.headless
.user_data_dir;
let result = launch_browser.await?;
Navigation
// Navigate to URL
goto.await?;
// Navigate with options
let nav_options = NavigationOptions ;
goto.await?;
// Wait for URL to match condition
wait_for_url_condition.await?;
Element Interactions
// Click a button
click_button.await?;
// Click with options
let click_options = ClickOptions ;
click_button.await?;
// Fill text area
fill_text_area.await?;
// Scroll element into view
scroll_into_view.await?;
Element Queries
// Check visibility
let visible = is_visible.await?;
// Check if enabled
let enabled = is_enabled.await?;
// Get text content
let text = text_content.await?;
// Get attribute value
let href = get_attribute.await?;
// Count matching elements
let count = count.await?;
Utilities
// Wait for a duration
wait.await;
// Get current URL
let url = get_url.await?;
// Parse URL
let parsed = parse_url?;
// Evaluate JavaScript
let result: String = evaluate.await?;
Modules
core- Core types and traits (constants, engine adapter, logger)elements- Element operations (selectors, visibility, content)interactions- User interactions (click, scroll, fill)browser- Browser management (launcher, navigation)utilities- General utilities (URL handling, wait operations)high_level- High-level DRY utilities
Prelude
For convenience, import everything commonly needed with:
use *;