"""Browser identity personas + cookie policies. The "lock everything down" approach (Firefox RFP + WebRTC off + cookies blocked) keeps you safe from fingerprinting but makes the machine *look weird* — sites flag you as suspicious and ban / captcha you. Worse: very few users use that config, so RFP-on is itself a fingerprint. Two strategies are exposed: • **Blend-in personas** — mimic the most common Windows-Chrome-US-en setup. JS / cookies / WebGL all work; everything looks normal; only WebRTC is blocked (because that leaks the real IP behind the proxy). The proxy chain itself does the actual hiding. • **Hardened** — full RFP / blocked WebRTC / strict tracking / FPI. Stand-out but maximum block. Same behavior as the original profile. Cookie modes are independent of persona and let the user pick per-session behavior from a dropdown. """ from __future__ import annotations from dataclasses import dataclass # Order matters: dropdown order in the UI. PERSONAS: list[str] = [ "blend_windows_chrome", "blend_windows_firefox", "blend_mac_safari", "hardened", "custom", ] PERSONA_LABELS: dict[str, str] = { "blend_windows_chrome": "Blend in — Windows 10 + Chrome (US-en, most common)", "blend_windows_firefox": "Blend in — Windows 10 + Firefox (US-en)", "blend_mac_safari": "Blend in — macOS + Safari (US-en)", "hardened": "Hardened — block + RFP (stands out; max anti-fingerprint)", "custom": "Custom — use individual hardening toggles", } COOKIE_MODES: list[str] = [ "accept_all", "block_third_party", "block_third_party_trackers", "session_only", "block_all", ] COOKIE_LABELS: dict[str, str] = { "accept_all": "Accept all cookies (most sites work)", "block_third_party": "Block 3rd-party cookies (recommended)", "block_third_party_trackers": "Block 3rd-party trackers only (Firefox default-strict)", "session_only": "Session only — clear on close", "block_all": "Block ALL cookies (breaks logins)", } # Firefox network.cookie.cookieBehavior values _COOKIE_BEHAVIOR = { "accept_all": 0, "block_third_party": 1, "block_third_party_trackers": 4, "session_only": 0, "block_all": 2, } @dataclass(frozen=True) class Persona: """A user-agent / locale / timezone / screen tuple that mimics a real, common configuration. All fields are deliberately popular values so the persona blends in. """ key: str user_agent: str accept_language: str timezone: str # IANA tz; used only when persona drives env TZ screen_w: int screen_h: int platform: str # navigator.platform locale: str # general.useragent.locale equivalent PERSONA_DATA: dict[str, Persona] = { "blend_windows_chrome": Persona( key="blend_windows_chrome", # Stable Chrome on Win10 x64 — by far the most common UA on the web. user_agent=( "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 " "(KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36" ), accept_language="en-US,en;q=0.9", timezone="America/New_York", screen_w=1920, screen_h=1080, platform="Win32", locale="en-US", ), "blend_windows_firefox": Persona( key="blend_windows_firefox", user_agent=( "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) " "Gecko/20100101 Firefox/128.0" ), accept_language="en-US,en;q=0.5", timezone="America/New_York", screen_w=1920, screen_h=1080, platform="Win32", locale="en-US", ), "blend_mac_safari": Persona( key="blend_mac_safari", user_agent=( "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) " "AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4.1 Safari/605.1.15" ), accept_language="en-US,en;q=0.9", timezone="America/Los_Angeles", screen_w=1680, screen_h=1050, platform="MacIntel", locale="en-US", ), } def cookie_behavior_value(mode: str) -> int: return _COOKIE_BEHAVIOR.get(mode, 1) def cookie_session_only(mode: str) -> bool: return mode == "session_only" def get_persona(key: str) -> Persona | None: return PERSONA_DATA.get(key) def is_blend_persona(key: str) -> bool: return key.startswith("blend_")