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    connect_browser, emulate_media, launch_browser, Browser, ChromiumoxidePage, ColorScheme,
54    ConnectOptions, EmulateMediaOptions, 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        connect_browser, emulate_media, goto, launch_browser, verify_navigation,
70        wait_for_navigation, wait_for_url_stabilization, Browser, ColorScheme, ConnectOptions,
71        EmulateMediaOptions, LaunchOptions, LaunchResult, NavigationOptions, NavigationResult,
72        WaitUntil,
73    };
74    pub use crate::core::{
75        is_navigation_error, is_timeout_error, DialogEvent, DialogManager, DialogType,
76        EngineAdapter, EngineError, EngineType, Logger, LoggerOptions, PdfOptions, Timing,
77        CHROME_ARGS, TIMING,
78    };
79    pub use crate::elements::{
80        count, get_attribute, input_value, is_enabled, is_visible, normalize_selector,
81        text_content, ParsedSelector,
82    };
83    pub use crate::high_level::{
84        check_and_clear_flag, find_toggle_button, install_click_listener, wait_for_url_condition,
85    };
86    pub use crate::interactions::{
87        click_button, click_element, fill_text_area, key_down, key_up, perform_fill, press_key,
88        scroll_into_view, scroll_into_view_if_needed, type_text, ClickOptions, ClickResult,
89        FillOptions, FillResult, ScrollBehavior, ScrollOptions, ScrollResult,
90    };
91    pub use crate::utilities::{
92        evaluate, get_domain, get_url, parse_url, safe_evaluate, same_origin, unfocus_address_bar,
93        wait, wait_with_cancel, WaitResult,
94    };
95}