#![doc = include_str!("../README.md")]
#![warn(missing_docs)]
pub mod compatibility;
mod config;
pub mod environment;
mod error;
#[cfg(feature = "interceptor")]
pub mod interceptor;
pub mod launch;
pub mod network;
mod patches;
pub mod profiles;
pub mod redaction;
pub mod retry;
#[cfg(feature = "seeding")]
mod seeding;
pub mod targets;
pub mod topology;
mod validation;
use chromiumoxide::Page;
pub use compatibility::{CompatibilityStatus, compare_browser_versions};
pub use config::{
ApplyReport, ConsistencyPolicy, Patch, PatchMode, PatchPlan, PatchState, PlatformProfile,
StealthConfig,
};
pub use environment::{
Finding, FindingSeverity, Observation, check_device_memory, compare_page_worker,
compare_voice_language, valid_device_memory_bucket,
};
pub use error::{Error, Result, ValidationErrors, ValidationIssue};
pub use launch::ChromeLanguageConfig;
pub use network::{
FailureCategory, NetworkAudit, NetworkAuditHandle, NetworkAuditSummary, NetworkRequestAudit,
RedirectHop, classify_failure, increment_failure_count, sanitize_error_name,
validate_client_hint_negotiation, validate_request_identity,
};
pub use profiles::{
BUILT_IN_CHROME_MAJOR, BUILT_IN_CHROME_VERSION, BrowserProfile, BrowserProfileBuilder,
ColorGamut, ColorScheme, ForcedColors, IdentityConfig, MediaFeaturesConfig, ProfileVersion,
ReducedMotion, ScreenConfig, TouchConfig,
};
pub use retry::{
NavigationMethod, NavigationRetryPolicy, NoRetryReason, ResponseDisposition, RetryDecision,
classify_response, parse_retry_after,
};
#[cfg(feature = "seeding")]
pub use seeding::{
CookieSeed, IndexedDbSeed, OriginSeed, ProfileSeed, SeedReport, apply_profile_seeds,
};
pub use targets::{TargetApplyReport, TargetCoordinator};
pub use topology::{Coverage, ResourceScope, classify_resource, sanitize_initiator_origin};
pub use validation::validate_profile;
impl StealthConfig {
pub async fn apply(&self, page: &Page) -> Result<ApplyReport> {
let plan = self.plan();
let issues = plan.issues().to_vec();
if self.policy() == ConsistencyPolicy::Strict && !issues.is_empty() {
return Err(Error::Validation {
issues: issues.into(),
});
}
let mut report = ApplyReport::default();
if self.policy() == ConsistencyPolicy::Warn {
report.warnings = issues;
}
apply_mode(self.locale_mode(), Patch::Locale, &mut report, |value| {
patches::locale::apply(page, value)
})
.await?;
apply_mode(
self.timezone_mode(),
Patch::Timezone,
&mut report,
|value| patches::timezone::apply(page, value),
)
.await?;
apply_mode(
self.identity_mode(),
Patch::Identity,
&mut report,
|value| patches::identity::apply(page, value),
)
.await?;
apply_mode(self.screen_mode(), Patch::Screen, &mut report, |value| {
patches::screen::apply(page, value)
})
.await?;
apply_mode(
self.media_features_mode(),
Patch::MediaFeatures,
&mut report,
|value| patches::media_features::apply(page, value),
)
.await?;
apply_mode(self.touch_mode(), Patch::Touch, &mut report, |value| {
patches::touch::apply(page, value)
})
.await?;
Ok(report)
}
}
async fn apply_mode<'a, T, F, Fut>(
mode: &'a PatchMode<T>,
patch: Patch,
report: &mut ApplyReport,
apply: F,
) -> Result<()>
where
F: FnOnce(&'a T) -> Fut,
Fut: std::future::Future<Output = Result<()>>,
{
match mode {
PatchMode::Native => report.native.push(patch),
PatchMode::Disabled => report.skipped.push(patch),
PatchMode::Override(value) => match apply(value).await {
Ok(()) => report.applied.push(patch),
Err(source) => {
return Err(Error::Apply {
patch,
applied: report.applied.clone(),
source: Box::new(source),
});
}
},
}
Ok(())
}