Stealth profile consistency (#269)
* feat(stealth): randomize browser profile per session Add a pool of 8 realistic browser profiles (Win10/Win11/macOS, Chrome 143-146). One is picked randomly per BrowserContext instead of always advertising Linux, which is a strong bot signal. Each profile keeps navigator.platform, userAgentData.platform, and userAgentData.platformVersion internally consistent with the UA string. - profiles.rs: static PROFILES pool + random_profile() picker - context.rs: pick profile on construction, store platform fields - page.rs: call rt.set_platform() alongside rt.set_user_agent() - runtime.rs: add set_platform() to inject __obscura_platform globals - bootstrap.js: read platform/userAgentData from globals (default Win32) Co-Authored-By: Claude Sonnet 4.6 <[email protected]> * feat(stealth): match GPU renderer pool to OS profile Windows profiles get ANGLE Direct3D11 renderers; macOS profiles get ANGLE Metal renderers. Vendor strings updated to match (Google Inc. (Apple) for Apple Silicon/Intel Mac, Google Inc. (NVIDIA/AMD/Intel) for Windows). Co-Authored-By: Claude Sonnet 4.6 <[email protected]> * fix(stealth): navigator.webdriver returns false instead of undefined Browsers set navigator.webdriver to false when automation is not active. Returning undefined is a detectable bot signal — fingerprinting scripts check typeof navigator.webdriver === 'boolean' as part of headless detection. Co-Authored-By: Claude Sonnet 4.6 <[email protected]> * Make stealth profile stable by default, rotation opt-in Picking a random profile per BrowserContext meant one address would cycle through different browser identities, which is itself a bot signal, and the rotated profile carries no matching TLS or timezone fingerprint. Default to a single stable profile; opt into rotation with OBSCURA_ROTATE_PROFILE, or pin one with OBSCURA_PROFILE=<index>. Drive timezone from the process TZ so Intl.DateTimeFormat and Date report one consistent zone. Default Europe/Berlin; override with OBSCURA_TIMEZONE. Update navigator.webdriver test to expect false, matching real Chrome. --------- Co-authored-by: SGavrl <[email protected]>
This commit is contained in:
1 parent
f20626bdbd
commit
a23dad7cd9
7 files changed
+171
-26
No files matched your search
@@ -8,6 +8,9 @@ pub struct BrowserContext {
|
||||
pub cookie_jar: Arc<CookieJar>,
|
||||
pub http_client: Arc<ObscuraHttpClient>,
|
||||
pub user_agent: String,
|
||||
pub platform: String,
|
||||
pub ua_platform: String,
|
||||
pub ua_platform_version: String,
|
||||
pub proxy_url: Option<String>,
|
||||
pub robots_cache: Arc<RobotsCache>,
|
||||
pub obey_robots: bool,
|
||||
@@ -103,9 +106,11 @@ impl BrowserContext {
|
||||
if stealth {
|
||||
client.block_trackers = true;
|
||||
}
|
||||
let resolved_ua = user_agent.unwrap_or_else(|| {
|
||||
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36".to_string()
|
||||
});
|
||||
let profile = crate::profiles::select_profile();
|
||||
let resolved_ua = user_agent.unwrap_or_else(|| profile.user_agent.to_string());
|
||||
let platform = profile.platform.to_string();
|
||||
let ua_platform = profile.ua_platform.to_string();
|
||||
let ua_platform_version = profile.ua_platform_version.to_string();
|
||||
// Sync the http client's UA at construction so navigation requests pick it
|
||||
// up before any async setup runs. The lock has no other holders here, so
|
||||
// try_write always succeeds; we fall back silently if it ever fails.
|
||||
@@ -118,6 +123,9 @@ impl BrowserContext {
|
||||
cookie_jar,
|
||||
http_client,
|
||||
user_agent: resolved_ua,
|
||||
platform,
|
||||
ua_platform,
|
||||
ua_platform_version,
|
||||
proxy_url,
|
||||
robots_cache: Arc::new(RobotsCache::new()),
|
||||
obey_robots: false,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
pub mod page;
|
||||
pub mod context;
|
||||
pub mod lifecycle;
|
||||
pub mod profiles;
|
||||
|
||||
pub use page::{NetworkEvent, Page, PageError};
|
||||
pub use context::BrowserContext;
|
||||
|
||||
@@ -267,6 +267,11 @@ impl Page {
|
||||
if let Ok(ua) = self.http_client.user_agent.try_read() {
|
||||
rt.set_user_agent(&ua);
|
||||
}
|
||||
rt.set_platform(
|
||||
&self.context.platform,
|
||||
&self.context.ua_platform,
|
||||
&self.context.ua_platform_version,
|
||||
);
|
||||
|
||||
rt.set_cookie_jar(self.context.cookie_jar.clone());
|
||||
rt.set_http_client(self.http_client.clone());
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
pub struct BrowserProfile {
|
||||
pub user_agent: &'static str,
|
||||
pub platform: &'static str,
|
||||
pub ua_platform: &'static str,
|
||||
pub ua_platform_version: &'static str,
|
||||
}
|
||||
|
||||
pub static PROFILES: &[BrowserProfile] = &[
|
||||
BrowserProfile {
|
||||
user_agent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36",
|
||||
platform: "Win32",
|
||||
ua_platform: "Windows",
|
||||
ua_platform_version: "10.0.0",
|
||||
},
|
||||
BrowserProfile {
|
||||
user_agent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36",
|
||||
platform: "Win32",
|
||||
ua_platform: "Windows",
|
||||
ua_platform_version: "10.0.0",
|
||||
},
|
||||
BrowserProfile {
|
||||
user_agent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36",
|
||||
platform: "Win32",
|
||||
ua_platform: "Windows",
|
||||
ua_platform_version: "15.0.0",
|
||||
},
|
||||
BrowserProfile {
|
||||
user_agent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36",
|
||||
platform: "Win32",
|
||||
ua_platform: "Windows",
|
||||
ua_platform_version: "15.0.0",
|
||||
},
|
||||
BrowserProfile {
|
||||
user_agent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36",
|
||||
platform: "MacIntel",
|
||||
ua_platform: "macOS",
|
||||
ua_platform_version: "13.6.7",
|
||||
},
|
||||
BrowserProfile {
|
||||
user_agent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36",
|
||||
platform: "MacIntel",
|
||||
ua_platform: "macOS",
|
||||
ua_platform_version: "14.4.1",
|
||||
},
|
||||
BrowserProfile {
|
||||
user_agent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36",
|
||||
platform: "MacIntel",
|
||||
ua_platform: "macOS",
|
||||
ua_platform_version: "14.5.0",
|
||||
},
|
||||
BrowserProfile {
|
||||
user_agent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36",
|
||||
platform: "MacIntel",
|
||||
ua_platform: "macOS",
|
||||
ua_platform_version: "14.6.0",
|
||||
},
|
||||
];
|
||||
|
||||
pub fn random_profile() -> &'static BrowserProfile {
|
||||
let idx = (std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.unwrap_or_default()
|
||||
.subsec_nanos() as usize)
|
||||
% PROFILES.len();
|
||||
&PROFILES[idx]
|
||||
}
|
||||
|
||||
/// Pick the profile for a new browser context.
|
||||
///
|
||||
/// The default is a single stable profile. Cycling through different browser
|
||||
/// identities from one address is itself a bot signal (a real address maps to a
|
||||
/// stable device), and the rotated profile does not yet carry a matching TLS or
|
||||
/// timezone fingerprint, so rotation is opt-in:
|
||||
/// OBSCURA_PROFILE=<index> pin a specific profile from PROFILES
|
||||
/// OBSCURA_ROTATE_PROFILE=1 pick a random profile per context
|
||||
pub fn select_profile() -> &'static BrowserProfile {
|
||||
if let Some(idx) = std::env::var("OBSCURA_PROFILE")
|
||||
.ok()
|
||||
.as_deref()
|
||||
.map(str::trim)
|
||||
.and_then(|s| s.parse::<usize>().ok())
|
||||
{
|
||||
if idx < PROFILES.len() {
|
||||
return &PROFILES[idx];
|
||||
}
|
||||
}
|
||||
if env_enabled("OBSCURA_ROTATE_PROFILE") {
|
||||
return random_profile();
|
||||
}
|
||||
&PROFILES[0]
|
||||
}
|
||||
|
||||
fn env_enabled(key: &str) -> bool {
|
||||
matches!(
|
||||
std::env::var(key)
|
||||
.ok()
|
||||
.as_deref()
|
||||
.map(str::trim)
|
||||
.map(str::to_ascii_lowercase)
|
||||
.as_deref(),
|
||||
Some("1") | Some("true") | Some("yes") | Some("on")
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user