stygian_browser/lib.rs
1//! # stygian-browser
2//!
3#![doc = include_str!("../README.md")]
4#![allow(clippy::multiple_crate_versions)]
5#![deny(unsafe_code)] // All unsafe usage is confined to #[cfg(test)] modules with explicit #[allow]
6//!
7//! Browser automation and stealth tooling for sites protected by Cloudflare,
8//! `DataDome`, `PerimeterX`, and Akamai Bot Manager.
9//!
10//! ## Features
11//!
12//! - **Browser pooling** — warm pool with min/max sizing, LRU eviction, and backpressure;
13//! sub-100 ms acquire from the warm queue
14//! - **Anti-detection** — User-Agent patching and plugin population
15//! - **Human behaviour** — Bézier-curve mouse paths, human-paced typing with typos,
16//! random scroll and micro-interactions
17//! - **Fingerprint generation** — statistically-weighted device profiles matching
18//! real-world browser market share distributions
19//!
20//! ## Quick Start
21//!
22//! ```rust,no_run
23//! use stygian_browser::{BrowserPool, BrowserConfig, WaitUntil};
24//! use std::time::Duration;
25//!
26//! # async fn run() -> Result<(), Box<dyn std::error::Error>> {
27//! // Default config: headless, Advanced stealth, pool of 2–10 browsers
28//! let config = BrowserConfig::default();
29//! let pool = BrowserPool::new(config).await?;
30//!
31//! // Acquire a browser from the warm pool (< 100 ms)
32//! let handle = pool.acquire().await?;
33//!
34//! // Open a tab and navigate
35//! let mut page = handle.browser().expect("valid browser").new_page().await?;
36//! page.navigate(
37//! "https://example.com",
38//! WaitUntil::DomContentLoaded,
39//! Duration::from_secs(30),
40//! ).await?;
41//!
42//! println!("Title: {}", page.title().await?);
43//!
44//! handle.release().await;
45//! Ok(())
46//! # }
47//! ```
48//!
49//! ## Stealth Levels
50//!
51//! | ------- |:-----------:|:------:|:-----:|:-----------:|:--------------:|
52//! | `None` | — | — | — | — | — |
53//! | `Basic` | ✓ | — | — | ✓ | — |
54//! | `Advanced` | ✓ | ✓ | ✓ | ✓ | ✓ |
55//!
56//! ## Module Overview
57//!
58//! | Module | Description |
59//! | -------- | ------------- |
60//! | [`browser`] | [`BrowserInstance`] — launch, health-check, shutdown |
61//! | [`pool`] | [`BrowserPool`] + [`BrowserHandle`] — warm pool management |
62//! | [`page`] | [`PageHandle`] — navigate, eval, content, cookies |
63//! | [`config`] | [`BrowserConfig`] + builder pattern |
64//! | [`error`] | [`BrowserError`] and [`Result`] alias |
65//! | [`fingerprint`] | [`DeviceProfile`], [`BrowserKind`] |
66//! | [`webrtc`] | [`WebRtcConfig`], [`WebRtcPolicy`], [`ProxyLocation`] |
67//! | [`cdp_protection`] | CDP leak protection modes |
68
69pub mod browser;
70pub mod cdp_protection;
71pub mod config;
72pub mod error;
73pub mod page;
74pub mod pool;
75
76#[cfg(feature = "extract")]
77pub mod extract;
78
79#[cfg(feature = "extract")]
80pub use extract::Extractable;
81
82#[cfg(feature = "similarity")]
83pub mod similarity;
84
85#[cfg(feature = "similarity")]
86pub use similarity::{ElementFingerprint, SimilarMatch, SimilarityConfig};
87
88#[cfg(feature = "stealth")]
89pub mod stealth;
90
91#[cfg(feature = "stealth")]
92pub mod behavior;
93
94#[cfg(feature = "stealth")]
95pub mod fingerprint;
96
97#[cfg(feature = "stealth")]
98pub mod tls;
99
100#[cfg(feature = "stealth")]
101pub mod webrtc;
102
103#[cfg(feature = "stealth")]
104pub mod diagnostic;
105
106#[cfg(feature = "mcp")]
107pub mod mcp;
108
109#[cfg(feature = "metrics")]
110pub mod metrics;
111
112pub mod session;
113
114pub mod recorder;
115
116pub use browser::BrowserInstance;
117pub use config::{BrowserConfig, HeadlessMode, StealthLevel};
118pub use error::{BrowserError, Result};
119pub use page::{NodeHandle, PageHandle, ResourceFilter, WaitUntil};
120pub use pool::{BrowserHandle, BrowserPool, PoolStats};
121
122#[cfg(feature = "stealth")]
123pub use stealth::{NavigatorProfile, StealthConfig, StealthProfile};
124
125#[cfg(feature = "stealth")]
126pub use behavior::InteractionLevel;
127#[cfg(feature = "stealth")]
128pub use behavior::RequestPacer;
129#[cfg(feature = "stealth")]
130pub use fingerprint::{BrowserKind, DeviceProfile};
131
132#[cfg(feature = "stealth")]
133pub use webrtc::{ProxyLocation, WebRtcConfig, WebRtcPolicy};
134
135pub mod prelude {
136 pub use crate::config::BrowserConfig;
137 pub use crate::error::{BrowserError, Result};
138 pub use crate::pool::{BrowserHandle, BrowserPool, PoolStats};
139
140 #[cfg(feature = "stealth")]
141 pub use crate::stealth::{NavigatorProfile, StealthConfig, StealthProfile};
142}