mirror of
https://github.com/daijro/camoufox.git
synced 2026-08-23 16:00:07 +00:00
Add config_overrides to generate_context_fingerprint(), fix font spacing disable (#601)
* Add system-ui font spoofing patch GetSystemUIFontFamilies() now reads navigator.platform from MaskConfig and returns the appropriate system font (Helvetica for macOS, Segoe UI for Windows) before falling through to LookAndFeel::GetFont. Fixes the CreepJS headless.systemFonts "Sans:Linux" leak when spoofing macOS from Linux. * Add patch verification test for system-ui font spoofing Tests macOS and Windows presets: launches Camoufox with a fingerprint, measures canvas text width with unquoted system-ui, asserts it matches the expected system font (Helvetica / Segoe UI). * Rename test to match patch naming convention tests/patches/ files should mirror patch names, not use dated prefixes. * Add config_overrides param to generate_context_fingerprint() There was no clean way to override config values (like disabling font spacing perturbation with fonts:spacing_seed=0) because init_script is rendered inside generate_context_fingerprint() — by the time the caller gets the config dict back, the init_script string is already baked. config_overrides is applied after all config building (preset/seeds/ timezone/locale) but before init_script rendering, giving callers a clean override point without touching the preset (which represents real device data, not perturbation config). The longer-term fix is separating config building from init_script rendering so callers can modify config and re-render. config_overrides is the minimal API addition that unblocks the use case without that refactor. * Rename test to match patch naming convention
This commit is contained in:
@@ -423,6 +423,7 @@ def generate_context_fingerprint(
|
||||
webrtc_ip: Optional[str] = None,
|
||||
timezone: Optional[str] = None,
|
||||
locale: Optional[str] = None,
|
||||
config_overrides: Optional[Dict[str, Any]] = None,
|
||||
) -> Dict[str, Any]:
|
||||
"""
|
||||
Generate fingerprint values for a single per-context identity.
|
||||
@@ -438,6 +439,9 @@ def generate_context_fingerprint(
|
||||
locale: BCP-47 locale string (e.g. 'en-GB'). When provided, parsed via
|
||||
normalize_locale() and injected into config. Also sets
|
||||
context_options['locale'] for Playwright.
|
||||
config_overrides: Dict of CAMOU_CONFIG keys to override after config
|
||||
is built but before init_script is rendered. Useful for disabling
|
||||
perturbation (e.g. {'fonts:spacing_seed': 0}).
|
||||
"""
|
||||
if preset is not None:
|
||||
# Use real fingerprint preset
|
||||
@@ -535,6 +539,10 @@ def generate_context_fingerprint(
|
||||
if parsed.script:
|
||||
config['locale:script'] = parsed.script
|
||||
|
||||
# Apply caller overrides before rendering init_script
|
||||
if config_overrides:
|
||||
config.update(config_overrides)
|
||||
|
||||
# Build the values dict for the init script (works for both paths)
|
||||
init_values: Dict[str, Any] = {
|
||||
'fontSpacingSeed': config.get('fonts:spacing_seed'),
|
||||
|
||||
Reference in New Issue
Block a user