1#![doc = include_str!("../README.md")]
2#![warn(missing_docs)]
3
4pub mod compatibility;
6mod config;
7pub mod environment;
9mod error;
10#[cfg(feature = "interceptor")]
11pub mod interceptor;
12pub mod launch;
14pub mod network;
16mod patches;
17pub mod profiles;
19pub mod redaction;
21pub mod retry;
23#[cfg(feature = "seeding")]
24mod seeding;
25pub mod targets;
27pub mod topology;
29mod validation;
30
31use chromiumoxide::Page;
32
33pub use compatibility::{CompatibilityStatus, compare_browser_versions};
34pub use config::{
35 ApplyReport, ConsistencyPolicy, Patch, PatchMode, PatchPlan, PatchState, PlatformProfile,
36 StealthConfig,
37};
38pub use environment::{
39 Finding, FindingSeverity, Observation, check_device_memory, compare_page_worker,
40 compare_voice_language, valid_device_memory_bucket,
41};
42pub use error::{Error, Result, ValidationErrors, ValidationIssue};
43pub use launch::ChromeLanguageConfig;
44pub use network::{
45 FailureCategory, NetworkAudit, NetworkAuditHandle, NetworkAuditSummary, NetworkRequestAudit,
46 RedirectHop, classify_failure, increment_failure_count, sanitize_error_name,
47 validate_client_hint_negotiation, validate_request_identity,
48};
49pub use profiles::{
50 BUILT_IN_CHROME_MAJOR, BUILT_IN_CHROME_VERSION, BrowserProfile, BrowserProfileBuilder,
51 ColorGamut, ColorScheme, ForcedColors, IdentityConfig, MediaFeaturesConfig, ProfileVersion,
52 ReducedMotion, ScreenConfig, TouchConfig,
53};
54pub use retry::{
55 NavigationMethod, NavigationRetryPolicy, NoRetryReason, ResponseDisposition, RetryDecision,
56 classify_response, parse_retry_after,
57};
58#[cfg(feature = "seeding")]
59pub use seeding::{
60 CookieSeed, IndexedDbSeed, OriginSeed, ProfileSeed, SeedReport, apply_profile_seeds,
61};
62pub use targets::{TargetApplyReport, TargetCoordinator};
63pub use topology::{Coverage, ResourceScope, classify_resource, sanitize_initiator_origin};
64pub use validation::validate_profile;
65
66impl StealthConfig {
67 pub async fn apply(&self, page: &Page) -> Result<ApplyReport> {
79 let plan = self.plan();
80 let issues = plan.issues().to_vec();
81 if self.policy() == ConsistencyPolicy::Strict && !issues.is_empty() {
82 return Err(Error::Validation {
83 issues: issues.into(),
84 });
85 }
86
87 let mut report = ApplyReport::default();
88 if self.policy() == ConsistencyPolicy::Warn {
89 report.warnings = issues;
90 }
91
92 apply_mode(self.locale_mode(), Patch::Locale, &mut report, |value| {
93 patches::locale::apply(page, value)
94 })
95 .await?;
96 apply_mode(
97 self.timezone_mode(),
98 Patch::Timezone,
99 &mut report,
100 |value| patches::timezone::apply(page, value),
101 )
102 .await?;
103 apply_mode(
104 self.identity_mode(),
105 Patch::Identity,
106 &mut report,
107 |value| patches::identity::apply(page, value),
108 )
109 .await?;
110 apply_mode(self.screen_mode(), Patch::Screen, &mut report, |value| {
111 patches::screen::apply(page, value)
112 })
113 .await?;
114 apply_mode(
115 self.media_features_mode(),
116 Patch::MediaFeatures,
117 &mut report,
118 |value| patches::media_features::apply(page, value),
119 )
120 .await?;
121 apply_mode(self.touch_mode(), Patch::Touch, &mut report, |value| {
122 patches::touch::apply(page, value)
123 })
124 .await?;
125
126 Ok(report)
127 }
128}
129
130async fn apply_mode<'a, T, F, Fut>(
131 mode: &'a PatchMode<T>,
132 patch: Patch,
133 report: &mut ApplyReport,
134 apply: F,
135) -> Result<()>
136where
137 F: FnOnce(&'a T) -> Fut,
138 Fut: std::future::Future<Output = Result<()>>,
139{
140 match mode {
141 PatchMode::Native => report.native.push(patch),
142 PatchMode::Disabled => report.skipped.push(patch),
143 PatchMode::Override(value) => match apply(value).await {
144 Ok(()) => report.applied.push(patch),
145 Err(source) => {
146 return Err(Error::Apply {
147 patch,
148 applied: report.applied.clone(),
149 source: Box::new(source),
150 });
151 }
152 },
153 }
154 Ok(())
155}