Skip to main content

browser_commander/
lib.rs

1//! Browser Commander - Universal Browser Automation Library
2//!
3//! A Rust library for browser automation that provides a unified API
4//! for different browser automation engines.
5//!
6//! # Features
7//!
8//! - Unified API across multiple browser engines
9//! - Built-in navigation safety handling
10//! - Element visibility and scroll management
11//! - Click, fill, and other interaction support with verification
12//! - Async/await support with Tokio
13//!
14//! # Example
15//!
16//! ```rust,no_run
17//! use browser_commander::browser::{launch_browser, LaunchOptions};
18//!
19//! #[tokio::main]
20//! async fn main() -> anyhow::Result<()> {
21//!     // Launch a browser
22//!     let options = LaunchOptions::chromiumoxide().headless(true);
23//!     let result = launch_browser(options).await?;
24//!
25//!     // The returned `page` is an `Arc<dyn EngineAdapter>` and can be
26//!     // passed to any of the crate's navigation / interaction helpers.
27//!     let page = result.page.as_ref();
28//!     page.goto("https://example.com").await?;
29//!     println!("Current URL: {}", page.url().await?);
30//!
31//!     Ok(())
32//! }
33//! ```
34//!
35//! # Modules
36//!
37//! - [`core`] - Core types and traits (constants, engine adapter, logger)
38//! - [`elements`] - Element operations (selectors, visibility, content)
39//! - [`interactions`] - User interactions (click, scroll, fill)
40//! - [`browser`] - Browser management (launcher, navigation)
41//! - [`utilities`] - General utilities (URL handling, wait operations)
42//! - [`high_level`] - High-level DRY utilities
43
44pub mod browser;
45pub mod core;
46pub mod elements;
47pub mod high_level;
48pub mod interactions;
49pub mod utilities;
50
51// Re-export commonly used items at crate root
52pub use browser::{
53    emulate_media, launch_browser, Browser, ChromiumoxidePage, ColorScheme, EmulateMediaOptions,
54    LaunchOptions, LaunchResult, NodeBridgePage,
55};
56pub use core::{
57    DialogEvent, DialogManager, DialogType, EngineAdapter, EngineError, EngineType, Logger,
58    LoggerOptions, PdfOptions, Timing, CHROME_ARGS, TIMING,
59};
60
61/// Prelude module for convenient imports.
62///
63/// Import everything commonly needed with:
64/// ```rust
65/// use browser_commander::prelude::*;
66/// ```
67pub mod prelude {
68    pub use crate::browser::{
69        emulate_media, goto, launch_browser, verify_navigation, wait_for_navigation,
70        wait_for_url_stabilization, Browser, ColorScheme, EmulateMediaOptions, LaunchOptions,
71        LaunchResult, NavigationOptions, NavigationResult, WaitUntil,
72    };
73    pub use crate::core::{
74        is_navigation_error, is_timeout_error, DialogEvent, DialogManager, DialogType,
75        EngineAdapter, EngineError, EngineType, Logger, LoggerOptions, PdfOptions, Timing,
76        CHROME_ARGS, TIMING,
77    };
78    pub use crate::elements::{
79        count, get_attribute, input_value, is_enabled, is_visible, normalize_selector,
80        text_content, ParsedSelector,
81    };
82    pub use crate::high_level::{
83        check_and_clear_flag, find_toggle_button, install_click_listener, wait_for_url_condition,
84    };
85    pub use crate::interactions::{
86        click_button, click_element, fill_text_area, key_down, key_up, perform_fill, press_key,
87        scroll_into_view, scroll_into_view_if_needed, type_text, ClickOptions, ClickResult,
88        FillOptions, FillResult, ScrollBehavior, ScrollOptions, ScrollResult,
89    };
90    pub use crate::utilities::{
91        evaluate, get_domain, get_url, parse_url, safe_evaluate, same_origin, unfocus_address_bar,
92        wait, wait_with_cancel, WaitResult,
93    };
94}