Files
Jake WriterandClaude Opus 5.5 9b74600adc Render at devicePixelRatio 1 too, not only at other ratios
The launcher set layout.css.devPixelsPerPx only when the identity's
devicePixelRatio was not 1, on the assumption that the host renders at 1.
On a HiDPI host (a Retina Mac, Linux with GDK_SCALE=2, Windows at 200%) the
browser then rendered at the host's scale, so a page read devicePixelRatio 1
while (resolution: 2dppx) matched (#964). Measured on 158.0.1-beta.41 headed on a
MacBook Pro's 2x Retina panel and on an Xvfb display with GDK_SCALE=2. Both
launchers now set the pref whenever the identity carries a ratio; a pref the
caller passes still wins.

On the Retina panel, innerWidth, visualViewport and the (width) media query
are unchanged by the pref. The window draws at half its physical size there,
as a 1x display's window would.

display-scale-resolution now also launches a ratio-1 identity on a 2x host,
which fails on main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 20:59:05 +00:00

34 lines
1.4 KiB
Python

"""The browser renders at the identity's devicePixelRatio (#933)."""
import pytest
from camoufox import utils
from camoufox.fingerprints import Screen
from test_launch_environment import isolated_launch_dependencies # noqa: F401
PREF = "layout.css.devPixelsPerPx"
WIN = {"navigator.userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:158.0) Gecko/20100101 Firefox/158.0",
"screen.width": 1382, "screen.height": 864, "window.outerWidth": 1280, "window.outerHeight": 900}
def prefs(dpr, **kwargs):
return utils.launch_options(config={**WIN, "window.devicePixelRatio": dpr}, i_know_what_im_doing=True,
**{"headless": True, **kwargs})["firefox_user_prefs"]
def test_renders_at_the_claimed_scale(isolated_launch_dependencies): # noqa: F811
assert prefs(2.5)[PREF] == "2.5"
assert prefs(1)[PREF] == "1"
def test_caller_pref_wins(isolated_launch_dependencies): # noqa: F811
assert prefs(2.5, firefox_user_prefs={PREF: "1.0"})[PREF] == "1.0"
def test_window_too_large_for_the_monitor_raises(monkeypatch, isolated_launch_dependencies): # noqa: F811
monkeypatch.setattr(utils, "OS_NAME", "lin")
with pytest.raises(ValueError, match="needs 3200 pixels, but this monitor has 1920"):
prefs(2.5, headless=False, screen=Screen(max_width=1920, max_height=1080))
assert prefs(1.25, headless=False, screen=Screen(max_width=1920, max_height=1200))[PREF] == "1.25"