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//! | Level | Navigator spoof | Canvas noise | WebGL random | CDP protection | Human behavior |
52//! | ----- | --------------- | ------------ | ------------ | -------------- | -------------- |
53//! | `None` | — | — | — | — | — |
54//! | `Basic` | ✓ | — | — | ✓ | — |
55//! | `Advanced` | ✓ | ✓ | ✓ | ✓ | ✓ |
56//!
57//! ## Module Overview
58//!
59//! | Module | Description |
60//! | -------- | ------------- |
61//! | [`browser`] | [`BrowserInstance`] — launch, health-check, shutdown |
62//! | [`pool`] | [`BrowserPool`] + [`BrowserHandle`] — warm pool management |
63//! | [`page`] | [`PageHandle`] — navigate, eval, content, cookies |
64//! | [`config`] | [`BrowserConfig`] + builder pattern |
65//! | [`error`] | [`BrowserError`] and [`Result`] alias |
66//! | [`fingerprint`] | [`DeviceProfile`], [`BrowserKind`] |
67//! | [`webrtc`] | [`WebRtcConfig`], [`WebRtcPolicy`], [`ProxyLocation`] |
68//! | [`cdp_protection`] | CDP leak protection modes |
69
70pub mod browser;
71pub mod cdp_protection;
72pub mod config;
73pub mod error;
74pub mod page;
75pub mod pool;
76pub mod proxy;
77
78#[cfg(feature = "extract")]
79pub mod extract;
80
81#[cfg(feature = "extract")]
82pub use extract::Extractable;
83
84#[cfg(feature = "similarity")]
85pub mod similarity;
86
87#[cfg(feature = "similarity")]
88pub use similarity::{ElementFingerprint, SimilarMatch, SimilarityConfig};
89
90#[cfg(feature = "stealth")]
91pub mod stealth;
92
93#[cfg(feature = "stealth")]
94pub mod behavior;
95
96#[cfg(feature = "stealth")]
97pub mod fingerprint;
98
99#[cfg(feature = "stealth")]
100pub mod tls;
101
102#[cfg(feature = "stealth")]
103pub mod webrtc;
104
105#[cfg(feature = "stealth")]
106pub mod noise;
107
108#[cfg(feature = "stealth")]
109pub mod canvas_noise;
110
111#[cfg(feature = "stealth")]
112pub mod webgl_noise;
113
114#[cfg(feature = "stealth")]
115pub mod audio_noise;
116
117#[cfg(feature = "stealth")]
118pub mod rects_noise;
119
120#[cfg(feature = "stealth")]
121pub mod cdp_hardening;
122
123#[cfg(feature = "stealth")]
124pub mod peripheral_stealth;
125
126#[cfg(feature = "stealth")]
127pub mod validation;
128
129pub mod tls_validation;
130
131#[cfg(feature = "stealth")]
132pub mod profile;
133
134#[cfg(feature = "stealth")]
135pub mod navigator_coherence;
136
137#[cfg(feature = "stealth")]
138pub mod timing_noise;
139
140#[cfg(feature = "stealth")]
141pub mod diagnostic;
142
143#[cfg(feature = "mcp")]
144pub mod mcp;
145
146#[cfg(feature = "metrics")]
147pub mod metrics;
148
149pub mod session;
150
151pub mod recorder;
152
153pub use browser::BrowserInstance;
154pub use config::{BrowserConfig, HeadlessMode, StealthLevel};
155pub use error::{BrowserError, Result};
156pub use page::{NodeHandle, PageHandle, ResourceFilter, WaitUntil};
157pub use pool::{BrowserHandle, BrowserPool, PoolStats};
158pub use proxy::{DirectLease, ProxyLease, ProxySource};
159
160#[cfg(feature = "stealth")]
161pub use stealth::{NavigatorProfile, StealthConfig, StealthProfile};
162
163#[cfg(feature = "stealth")]
164pub use behavior::InteractionLevel;
165#[cfg(feature = "stealth")]
166pub use behavior::RequestPacer;
167#[cfg(feature = "stealth")]
168pub use fingerprint::{BrowserKind, DeviceProfile};
169
170#[cfg(feature = "stealth")]
171pub use webrtc::{ProxyLocation, WebRtcConfig, WebRtcPolicy};
172
173pub mod prelude {
174 pub use crate::config::BrowserConfig;
175 pub use crate::error::{BrowserError, Result};
176 pub use crate::pool::{BrowserHandle, BrowserPool, PoolStats};
177
178 #[cfg(feature = "stealth")]
179 pub use crate::stealth::{NavigatorProfile, StealthConfig, StealthProfile};
180}