mirror of
https://github.com/daijro/camoufox.git
synced 2026-11-19 00:07:28 +00:00
launch_options/launchOptions filled the caller's config, prefs, args and addons in place. A config reused for a second launch then carried the first identity's webGl:vendor in, which read as a GPU the caller named: the second launch covered its canvas while claiming the host's GPU. The TypeScript end-to-end test caught it through its Python probe, which calls launch_options before Camoufox with the same kwargs. Both launchers now work on copies. Firefox's baseline fingerprinting protection reports the available screen as the screen less a fixed taskbar for the claimed OS (48px Windows, 76px macOS, none on Linux) and collapses more than one touch point to 5, and the browser applies that to the spoofed values. The launchers still claimed fpgen's recorded avail rect, adjusted by fix_screen_no_taskbar, so a Linux identity's config said availHeight 1053 while the page read 1080. follow_baseline_protection / followBaselineProtection replaces it and claims what the browser reports. The end-to-end test now compares a covered canvas by being covered (its readback is random on every read, so its size was too), launches the NewContext scenario with canvas_noise, since an uncovered browser binds its contexts to the host, and checks a headful launch against its own config, because Xvfb can render on another device than headless. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
60 lines
2.3 KiB
Python
60 lines
2.3 KiB
Python
"""
|
|
launch_options() resolves the browser it will launch before reading its version.
|
|
|
|
It used to read the version of the active install first and resolve the binary
|
|
last. With nothing installed that raised CamoufoxNotInstalled ("run `camoufox
|
|
fetch`") before the download in camoufox_path() was ever reached (#835), while
|
|
the TypeScript launcher downloaded. With an outdated install it generated the
|
|
identity for the old Firefox version and then launched the upgraded one.
|
|
"""
|
|
|
|
import pytest
|
|
|
|
from camoufox import utils
|
|
from camoufox.exceptions import CamoufoxNotInstalled
|
|
|
|
|
|
@pytest.fixture
|
|
def nothing_installed(monkeypatch, tmp_path):
|
|
"""No active install; launch_path() is where the download happens."""
|
|
binary = tmp_path / "camoufox-bin"
|
|
downloads = []
|
|
|
|
def installed_verstr():
|
|
if not downloads:
|
|
raise CamoufoxNotInstalled("Official is not installed. Please run `camoufox fetch` to install.")
|
|
return "157.0-beta.34"
|
|
|
|
def launch_path(*_args, **_kwargs):
|
|
downloads.append(True)
|
|
return str(binary)
|
|
|
|
seen = {}
|
|
|
|
def from_fpgen(_fingerprint, ff_version, *_args, **_kwargs):
|
|
seen["ff_version"] = ff_version
|
|
return {}
|
|
|
|
monkeypatch.setattr(utils, "installed_verstr", installed_verstr)
|
|
monkeypatch.setattr(utils, "launch_path", launch_path)
|
|
monkeypatch.setattr(utils, "generate_fingerprint", lambda *args, **kwargs: object())
|
|
monkeypatch.setattr(utils, "from_fpgen", from_fpgen)
|
|
for name in ("add_default_addons", "get_screen_cons", "fix_navigator_arch",
|
|
"follow_baseline_protection", "clamp_window_dimensions",
|
|
"set_media_devices_defaults", "validate_config"):
|
|
monkeypatch.setattr(utils, name, lambda *args, **kwargs: None)
|
|
monkeypatch.setattr(utils, "_generate_random_font_subset", lambda *args, **kwargs: [])
|
|
monkeypatch.setattr(utils, "_generate_random_voice_subset", lambda *args, **kwargs: [])
|
|
monkeypatch.setattr(utils, "get_env_vars", lambda *args, **kwargs: {})
|
|
return downloads, seen, str(binary)
|
|
|
|
|
|
def test_a_first_launch_installs_instead_of_raising(nothing_installed):
|
|
downloads, seen, binary = nothing_installed
|
|
|
|
options = utils.launch_options(headless=True, i_know_what_im_doing=True)
|
|
|
|
assert downloads
|
|
assert options["executable_path"] == binary
|
|
assert seen["ff_version"] == "157"
|