4 Commits
Author SHA1 Message Date
Jake WriterandClaude Opus 5.5 8589f980fd fix(screen): screen.availWidth/availHeight cost parity with stock (fixes main's getter-cost-parity failure) (#950)
* fix(screen): cache the spoofed screen per nsScreen so availWidth costs what stock's does

getter-cost-parity failed on main (run 40142262379): screen.availHeight took
361 ns against stock Firefox 158.0's 178 ns on the CI runner, just over the 2x
bound. Under the default fingerprinting protection, GetAvailRect does stock's
work and then read the context id twice, two per-context memo entries (each a
__tls_get_addr call from libxul), the global screen size, and the context's
navigator.platform, which it copied and converted to UTF-8 on every call.

nsScreen now keeps the spoofed rect and OS for its context and re-reads them
only when RoverfoxStorageManager's generation moves (a new Generation()
accessor; the same staleness rule its own memo uses). SpoofedOSFor also takes
UTF-16, so NavigatorManager::GetSpoofedOS no longer converts.

Local, same host, fastest of 3 guard runs each (stock 88-90 ns):
  availHeight, launch identity   117-122 ns -> 107-110 ns
  availHeight, context identity  132-134 ns -> 107 ns
  screen.width                    76-78 ns  ->  71 ns   (stock 54-56)
Launch and context identities now cost the same, and availHeight / height is
1.5, as stock's is (it was 1.74 here, 2.3 on the runner).

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

* test(virtdisplay): count a process reaped mid-read as dead

_alive opens /proc/<pid>/stat and then reads it. When Xvfb exits between the
two, which is the moment test_xvfb_dies_with_the_process_that_started_it waits
for, the read raises ProcessLookupError (ESRCH), not FileNotFoundError, and the
test failed instead of passing (PR #950's pythonlib job).

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

* test(virtdisplay): judge Xvfb's exit on the wait loop's own reading

The loop stops when it sees Xvfb as a zombie, and the assert then read /proc
again. That second read lands while Xvfb's new parent reaps it, the window in
which open() succeeds and read() raises ESRCH. Asserting on the loop's last
reading removes the second read; _alive already counts ESRCH as gone.

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

* test(guards): run on the binary under test, never the installed release

audio-matches-stock failed PR #950's spoofing job with a GitHub API 403 (rate
limit). Re-encoding its config, it called get_env_vars without path=, so the
fontconfig lookup fell back to camoufox_path(): on a runner with no release
installed that fetched one through the anonymous GitHub API (31.7 s of the
guard on main) and read the released bundle, not the build under test.

launch_camoufox, which system-ui-font-spoofing uses, passed no executable_path
at all, so that guard tested an installed or downloaded release and could not
catch a regression in the build.

Both now use the binary under test, and helpers makes camoufox_path() raise in
every guard, so a fallback to the installed release fails at once on a dev box
with a cached release as well as on a runner without one.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 06:31:03 +00:00
Jake WriterandClaude Opus 5.5 9f94b0ea46 Stop Xvfb when the process that launched it dies (#868)
headless="virtual" started Xvfb in its own session and stopped it only on
the browser's close path. A launcher ended by a signal (timeout, a
supervisor, a cancelled CI job) never reaches that path, so its Xvfb ran
forever, together with the session bus and desktop helpers Firefox
autolaunched on that display.

Both packages now exec Xvfb through `setpriv --pdeathsig TERM`, so the
kernel signals it when its launcher dies, even by SIGKILL. SIGTERM lets
Xvfb remove its own lock and socket, and the autolaunched bus exits when
it loses its X connection. setpriv comes from util-linux.

The leak suite missed this because every crash test keeps the launcher
alive to tear down, and leak_check follows only our descendants, which an
orphan no longer is. test_launcher_sigkill_leaves_nothing_on_its_display
kills the launcher and looks machine-wide.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 13:31:03 -06:00
Jake WriterandClaude Opus 5.5 6c3850f60a Remove dead and duplicated code across the launchers, scripts and CI
Values both launchers hard-coded (marker fonts, the Windows 11 fonts, the
Apple Silicon and Intel Mac core and panel tables, plausible DPR and core
counts, the macOS MacinTalk/Eloquence voices, the cache prefs) now live in
python/src/camoufox/launcher-constants.json, which the TypeScript package
ships as a data file. gen-fonts-json.py and verify-fonts.py read the same
file, so the drifted PingFang marker copy is gone (fonts.json regenerates
byte-identical) and verify-fonts no longer ast-parses fingerprints.py.

- Drop the duplicate fpgen model pin under browser/scripts/data; the TS
  test checks the fpgen package's MODEL_PIN against the Python copy.
- Move pin-fpgen-model.py and clean-fingerprint-data.py to python/scripts.
- Delete the font licence report (font-metrics/licences.py and its saved
  output, open-fonts.txt): the bundle ships as built, so the report checks
  nothing.
- Delete unreferenced files: cleanfonts.sh, python/examples,
  typescript/renovate.json.
- Delete dead code: classify_installs, remove_mmdb, write_upstream_sh,
  bump_release, unused test constants and fixture helpers, the
  _virtual_display attribute writes, package.py's pre-groups font copy (a
  missing groups.json now fails).
- Share require_bundle, zip_entries, gh_headers and parse_shard instead of
  keeping copies; fold GitHubDownloader into CamoufoxFetcher in both
  launchers.
- TS raises ValueError where Python does, and `camoufox version` prints the
  fpgen package version as Python does.
- Python tests get src/ from pytest's pythonpath instead of sys.path
  inserts; skips that hid untested paths now assert or test the behaviour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 13:38:55 -06:00
Jake Writer 658806eb23 chore: major code cleanup/refactor 2026-10-06 19:10:22 -06:00