Files
archived-camoufox/python/tests/test_windows_identity.py
T
Jake WriterandClaude Opus 5.5 e90abccee6 Firefox 159: stock parity for a driven browser (#997)
* Firefox 159: stock parity for a driven browser

A page driven through Camoufox should read like stock Firefox in a
person's hands. This brings the Firefox 159 port up to that.

Stock defaults
- Remote Settings, Safe Browsing, region detection, Push, connectivity
  checks and the new tab keep Firefox's defaults; Nimbus is tied to
  Normandy so the new tab starts without it.
- No policies.json: any policy file puts Firefox in enterprise mode,
  which a page can see (DNS over HTTPS stands down).
- Firefox's 100% release rollouts are default prefs; stock's search
  engines are back.
- WebGL, devicePixelRatio and worker getters cost what stock's do; Linux
  builds use --enable-stdcxx-compat, as Mozilla's do.

Juggler
- Driver code defines no interfaces on the page's window, isolated and
  main-world evaluates included.
- Input arrives as a person's: click hold, hover dwell and double-click
  gap; fill() and insert_text() type key by key; the wheel turns notches;
  moves coalesce per frame; drags behave as a GTK drag session. Input
  waits for Firefox's user-input gate.
- Focus, Fission and bfcache stay Firefox's unless a driver needs them.
- Screenshots and document.fonts.ready leave the page alone.

Humanize
- One engine per channel (mouse, keyboard, scroll) behind one seam in
  Juggler, a seed for repeatable input, and custom(fn) engines run in the
  caller's process (Python). The build lists its engines in
  humanize-engines.json.

Network
- A SOCKS5 proxy with a username and password works for the launch and
  per context.
- The User-Agent header follows the context's identity.
- WebRTC UDP goes through a SOCKS5 proxy's UDP ASSOCIATE relay
  (webrtc-socks5-udp.patch), so a page's STUN server sees the exit and the
  srflx is real. Nothing goes around the proxy: a page with no HTTP-loaded
  document behind it counts as proxied, a proxy that carries no UDP gets
  none, and a relay address inside the proxy's own NAT is replaced by the
  proxy's public one.

Identity
- Bundled fonts and speech voices follow the drawn identity.
- The window holds the identity's size and position through startup, and
  on a virtual display a window outside the root is neither occluded nor
  refused focus.

CI runs every new guard.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BLGoGNeymhNcr3EAQX5hJE

* Paste inserted text; draw input delays from one normal helper

fill() and keyboard.insert_text() typed the text key by key, a quarter of a
second per character, which ran past Playwright's timeouts and is not how a
person enters a whole string. They now paste: the paste shortcut (Ctrl+V,
Cmd+V for a Mac platform) goes down, Firefox's own paste runs with the text
through nsIEditor.pasteTransferable (a trusted paste event with the text as
clipboardData, then beforeinput/input insertFromPaste), and the shortcut
comes up. The shortcut's keypress, where Firefox would read the system
clipboard, is cancelled in the system group, which content cannot observe;
the system clipboard is never used. A page that cancels the paste or the
shortcut gets nothing, and the call fails saying so.

input/HumanDelay.js holds normalDelay(mean, sd, min, max), the one draw for
the delays between a person's input events: the click hold (normal around
110 ms, SD 30, never under 50 ms, with no ceiling), the double-click gap,
the hover dwell, the paste key's hold, and the Shift and paste modifiers'
lead and trail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BLGoGNeymhNcr3EAQX5hJE

* Fix driven input and headless parity

* Headless with a display uses that display's GL

A headless probe that failed to load EGL still recorded TEST_TYPE EGL, so Firefox refused GLX and every headless WebGL context died. Probe EGL only when there is no display, and only claim it when that probe initialized. Move spacing starts when the move is sent, so a steps path stays a 125 Hz mouse instead of one move per frame.

* Fix focus, humanize-off, and WebRTC proxy parity

- A stock identity mirror adds no humanize keys when humanize is off.
- Keep the real focus and run the upstream focus tests.
- Add the per-context WebRTC proxy flag; do not fabricate a srflx behind a proxy.
- Refresh the Python/TypeScript parity tests, skiplist and docs.
- Install Mesa DRI so the software WebGL guards can run.

* Fix TypeScript humanize float encoding

Encode humanize option values as PyFloat so a duration serializes as 1.0, matching Python, and apply Biome's import formatting.

* Close a relay overflow, stop inventing srflx, and fix driven input gaps

WebRTC:
- A SOCKS5 relay read larger than the caller's buffer overran the stack
  buffer. A page-named STUN server could send one. Drop the datagram.
- Remove the fabricated srflx candidate; a srflx now only comes from a
  STUN answer, and the guards run against a server that answers.
- Juggler records each proxy it sets, so a caller's own
  new_context(proxy=...) cannot gather around it. This replaces the
  launcher's webrtc:proxied key and its page-visible setter.
- Headless GL probes use the surfaceless platform without launcher plumbing.

Input:
- A wheel without a scroll engine takes the activation slot per notch, so
  a long scroll no longer stalls input in every other context.
- Paste and fill work inside an iframe.
- Python fill honours the caller's timeout.

TypeScript humanize matches Python: off, seeds, duplicate options and the
scroll warning.

Guards with a missing prerequisite fail rather than pass. Add
navigation-preconnect-proxied. Move the tweened click test to a skiplist
pattern entry, since whether it passes depends on machine speed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Check the tweened click entry with its guard, not the audit

Whether test_click_with_tweened_mouse_movement passes depends on machine
speed: 0 of 20 runs on all cores here, 3 of 15 on two, and it passed on CI.
The audit cannot demand a failure from it, and a pattern entry would leave
its reason unchecked. A skiplist entry's checked_by now names the patch
guard that checks the reason, here driven-move-coalescing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Ask the display-less GL probe for a pbuffer config

Mesa's surfaceless platform has only pbuffer configs. The probe asked for
the default window surface type, so eglChooseConfig matched nothing and
eglCreateContext got an uninitialized config. With no GPU, a display-less
headless launch then had an empty gfxInfo: no WebGL and no WebRTC H264.

A host where NVIDIA's EGL answers first never reaches Mesa here, so the
guards only failed on machines without a GPU.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Open about:blank for a driver and run first-page init scripts after PageAgent

A headed persistent launch opened about:home once the start page prefs went
back to stock. browser.startup.page now becomes 0 only when a driver attaches,
so a browser nobody drives keeps Firefox's start page.

Init scripts on a page's initial document ran before PageAgent existed, so
their binding calls and console messages had no listener and were lost. They
now run after PageAgent has reported the page's execution contexts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Warm up the crash growth test past Firefox 159's timed startup work

The parent holds up to 400 MB more for a while at fixed times after launch, in
stock Firefox 159 as well. Two RSS readings taken across one of those peaks
read as growth or shrinkage, and pushed the test over its limit with no leak.
Warm up by time instead of by context count. The metric and limit are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Close WebRTC paths around a proxy, stop background traffic, fix driven input

WebRTC behind a proxy no longer shows the host's address: ICE uses the proxy's
SOCKS5 UDP relay when it has one, and UDP is dropped otherwise. A page on the
bypass list behind a forced proxy is blocked on UDP and ICE TCP. A proxy hanging
up straight after CONNECT no longer crashes the parent process.

Remote Settings stops polling, with the page-visible lists bundled as a snapshot
pinned by scripts/remote_settings.py, and Push connects on demand.

fill clicks an unfocused text field and types when a page blocks paste. Click
throughput across contexts is restored. The TypeScript launcher gains custom
humanize engines and driver defaults, in step with Python, and caps WebGL2
MAX_UNIFORM_BLOCK_SIZE at Firefox 159's 64 KiB.

docs/input-dispatch.md records a person's wheel on macOS, which is one line a
notch where the driven wheel sends three.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Leave the humanize engine system for its own pull request

Per-channel engines, seeded streams, custom() and the keyboard and
scroll-into-view plans are a separate feature. humanize keeps main's meaning
here: a human cursor move, on or off, with an optional duration cap, planned by
CursorTrajectory.js and paced by Pacer.js. The five per-channel config keys were
declared on this branch, so they stay declared as removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Warn, not raise, on a browser that cannot read voices:speechd

A new package has to launch an older build (#835, and the install gate launches
the last release). A Linux identity there reports no voices, so it warns and the
warning cannot be silenced.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Give a macOS identity macOS's wheel

A person's notched mouse on macOS sends one line for a slow notch, with no native
tick, and accelerates a faster turn from there. Driven input sent Linux's three
ticked lines. A macOS identity now sends lines at 16 px each, starting at one and
growing, and stock's per-OS system scroll override follows the identity.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Install the tracking lists where a clean build's reader looks

A relative wildcard keeps its directory under recursive make and drops it under
faster make. The clean build nested the attachments one directory too deep, so
the classifier had no tables. An incremental objdir hid this with old links.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Make two guards deterministic: the wheel's OS and a dropped relay

A launch without `os` draws one, and a macOS draw now gets macOS's wheel, so the
guards asserting three notches failed by the draw. They assert Linux's now.

The browser flushes queued datagrams when UDP ASSOCIATE is granted, so a relay
closed just after the grant could forward one, and the STUN server heard the
proxy's own relay port as if it had gone around the proxy. It closes first now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-07 17:51:40 +00:00

160 lines
5.9 KiB
Python

"""A Windows identity on another host behaves as stock Windows Firefox does.
What was measured on stock Firefox on Windows against this build on a Linux
host claiming Windows: the math (browser/tests/ucrt-math), the keyboard (the
windows-keyboard guard), the scrollbar width, and four behaviour prefs
(middlemouse.paste, general.autoScroll, eat_space_to_next_word and the
fullscreen transition, the spot checks below). The other behaviour prefs are
Firefox 158's Windows defaults, read from all.js, firefox.js and
StaticPrefList.yaml, not measured. On a Windows host the build already behaves
that way, and a macOS or Linux identity is left as it is.
"""
import pytest
from camoufox import utils
from test_launch_environment import isolated_launch_dependencies # noqa: F401
WIN_UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:158.0) Gecko/20100101 Firefox/158.0"
MAC_UA = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:158.0) Gecko/20100101 Firefox/158.0"
LIN_UA = "Mozilla/5.0 (X11; Linux x86_64; rv:158.0) Gecko/20100101 Firefox/158.0"
@pytest.fixture
def launch(monkeypatch, isolated_launch_dependencies): # noqa: F811
"""launch_options on a Linux host; returns (config, prefs)."""
monkeypatch.setattr(utils, "_host_os_key", lambda: "lin")
seen = {}
def capture(config, *args, **kwargs):
seen["config"] = dict(config)
return {}
monkeypatch.setattr(utils, "get_env_vars", capture)
def run(ua, **kwargs):
config = {"navigator.userAgent": ua, **kwargs.pop("config", {})}
prefs = utils.launch_options(config=config, i_know_what_im_doing=True, **kwargs)["firefox_user_prefs"]
return seen["config"], prefs
return run
def test_windows_identity_gets_windows_crt_math(launch):
_, prefs = launch(WIN_UA)
assert prefs["javascript.options.use_ucrt_math"] is True
@pytest.mark.parametrize("ua", [MAC_UA, LIN_UA])
def test_other_identities_keep_host_math(launch, ua):
_, prefs = launch(ua)
assert "javascript.options.use_ucrt_math" not in prefs
def test_windows_identity_on_windows_host_is_left_alone(launch, monkeypatch):
monkeypatch.setattr(utils, "_host_os_key", lambda: "win")
_, prefs = launch(WIN_UA)
assert "javascript.options.use_ucrt_math" not in prefs
def test_caller_values_win(launch):
_, prefs = launch(WIN_UA, firefox_user_prefs={"javascript.options.use_ucrt_math": False})
assert prefs["javascript.options.use_ucrt_math"] is False
def test_windows_identity_gets_windows_keyboard(launch):
config, _ = launch(WIN_UA)
assert config["input:windowsKeyboard"] is True
@pytest.mark.parametrize("ua", [MAC_UA, LIN_UA])
def test_other_identities_keep_host_keyboard(launch, ua):
config, _ = launch(ua)
assert "input:windowsKeyboard" not in config
def test_windows_keyboard_on_windows_host_is_left_alone(launch, monkeypatch):
monkeypatch.setattr(utils, "_host_os_key", lambda: "win")
config, _ = launch(WIN_UA)
assert "input:windowsKeyboard" not in config
def test_caller_keyboard_wins(launch):
config, _ = launch(WIN_UA, config={"input:windowsKeyboard": False})
assert config["input:windowsKeyboard"] is False
def test_windows_identity_gets_windows_behaviour(launch):
_, prefs = launch(WIN_UA)
for pref, value in utils.WINDOWS_BEHAVIOUR_PREFS.items():
assert prefs[pref] == value
# Spot checks against stock Firefox on Windows, so an edit to the table
# cannot quietly agree with itself.
assert prefs["middlemouse.paste"] is False
assert prefs["general.autoScroll"] is True
assert prefs["layout.word_select.eat_space_to_next_word"] is True
assert prefs["full-screen-api.transition-duration.enter"] == "200 200"
def test_windows_identity_leaves_eme_off(launch):
# Windows Firefox has PlayReady behind EME; a Linux build cannot, so EME on
# would claim key systems it does not deliver. The build's default stands.
_, prefs = launch(WIN_UA)
assert "media.eme.enabled" not in prefs
@pytest.mark.parametrize("ua", [MAC_UA, LIN_UA])
def test_other_identities_keep_host_behaviour(launch, ua):
_, prefs = launch(ua)
assert not set(utils.WINDOWS_BEHAVIOUR_PREFS) & set(prefs)
def test_windows_behaviour_on_windows_host_is_left_alone(launch, monkeypatch):
monkeypatch.setattr(utils, "_host_os_key", lambda: "win")
_, prefs = launch(WIN_UA)
assert not set(utils.WINDOWS_BEHAVIOUR_PREFS) & set(prefs)
def test_caller_behaviour_wins(launch):
_, prefs = launch(WIN_UA, firefox_user_prefs={"middlemouse.paste": True})
assert prefs["middlemouse.paste"] is True
@pytest.mark.parametrize("ua, enabled", [(WIN_UA, True), (LIN_UA, True), (MAC_UA, False)])
def test_wheel_override_follows_the_identity(launch, ua, enabled):
_, prefs = launch(ua)
assert prefs["mousewheel.system_scroll_override.enabled"] is enabled
# Scrollbars are drawn by the host build's theme: GTK's are 12 px where stock
# Windows measures 17 (classic, ui.useOverlayScrollbars 0), so a Windows 10
# identity on a Linux host showed a 12 px gutter.
SCROLLBAR_STYLE = "widget.non-native-theme.scrollbar.style"
@pytest.mark.parametrize(
"overlay, style",
[pytest.param(0, 4, id="windows-10-classic"), pytest.param(1, 5, id="windows-11-overlay")],
)
def test_windows_identity_draws_windows_scrollbars(launch, overlay, style):
_, prefs = launch(WIN_UA, firefox_user_prefs={"ui.useOverlayScrollbars": overlay})
assert prefs[SCROLLBAR_STYLE] == style
@pytest.mark.parametrize("ua", [MAC_UA, LIN_UA])
def test_other_identities_keep_host_scrollbars(launch, ua):
_, prefs = launch(ua)
assert SCROLLBAR_STYLE not in prefs
def test_scrollbars_on_a_windows_host_are_left_alone(launch, monkeypatch):
monkeypatch.setattr(utils, "_host_os_key", lambda: "win")
_, prefs = launch(WIN_UA)
assert SCROLLBAR_STYLE not in prefs
def test_caller_scrollbar_style_wins(launch):
_, prefs = launch(WIN_UA, firefox_user_prefs={SCROLLBAR_STYLE: 2})
assert prefs[SCROLLBAR_STYLE] == 2