Clamp headful window geometry to the real display - #674
Open
pratyush618 wants to merge 2 commits into
Open
Conversation
get_screen_cons() bounds the generated fingerprint to the monitor, but BrowserForge honours a Screen constraint only when its pool has a match: FingerprintGenerator.partial_csp catches the filtering failure and deletes the constraint unless strict=True. So a 1366x768 laptop routinely gets a 2560x1440 fingerprint with window.outerWidth 1920, and browser-init resizes the real chrome window to it -- rendering past the edge of the monitor. Re-apply the bound after generation instead of trusting BrowserForge with it, and pull screenX/screenY back inside the shrunken screen. Headful only. headless has no window to overflow, and headless='virtual' runs a 1x1 Xvfb whose "monitor" would otherwise shrink the fingerprint to 1x1. Fixes daijro#499
headless='virtual' reaches launch_options as headless=False with virtual_display set (async_api rewrites it), so the headful gate fired and clamped the fingerprint to Xvfb's 1x1 stub. fix_screen_no_taskbar then drove availHeight to -39 and validate_config rejected the launch outright.
Contributor
Author
|
Follow-up pushed: Under the 1x1 Xvfb the clamp shrank Gate now also excludes #694 is stacked on this branch. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #499.
Problem
In headful mode the browser window is sometimes larger than the monitor, with rendering artifacts along the right and bottom margins. Reported on a 1366x768 laptop.
Cause
get_screen_cons()already computes the right bound —Screen(max_width=1366, max_height=768)— and hands it to BrowserForge. BrowserForge then throws it away.FingerprintGenerator.partial_cspfilters the fingerprint pool by the screen constraint, and when that filtering fails it swallows the error and drops the constraint entirely unlessstrict=True:Camoufox doesn't pass
strict, so the bound is silently discarded and a 1366x768 laptop gets a 2560x1440 fingerprint withwindow.outerWidth1920.browser-init.patchthen callswindow.resizeTo(outerWidth, outerHeight)on the real chrome window, so the oversized value becomes a real oversized window.Measured on an Xvfb sized to the reporter's 1366x768, the real X window reached 2225x1238.
Change
Re-apply the bound after generation rather than trusting BrowserForge with it:
clamp_screen_to_display()— shrinksscreen.width/heightto the display, preserving the taskbar delta sofix_screen_no_taskbar'savail < heightinvariant still holds. The existingclamp_window_dimensions()then cascades the new bounds down to avail/outer/inner.clamp_window_position()— pullsscreenX/screenYback inside the screen. Shrinking the screen invalidates the positions BrowserForge generated against the original one, which would otherwise leave the window box partly outside its own reported screen.Headful only
The clamp is gated on
headless is False, which matters more than it looks:headless='virtual'launches Xvfb with-screen 0 1x1x24(virtdisplay.py), andenvisos.environ, soenv['DISPLAY'] = virtual_displaymutates the caller's environment. Under that displayget_screen_cons(True)returnsScreen(max_width=1, max_height=1)— verified. An unconditional clamp would shrink those fingerprints to a 1x1 screen. It is harmless today only because BrowserForge discards the constraint.Verification
Against the released binary on an Xvfb at 1366x768:
Invariants checked:
inner <= outer <= avail <= screen,screen <= display,avail < screen(noTaskbar tell), all dimensions positive, and0 <= screenX/Y <= screen - outer.Real window after the fix: visible chrome 1366x720 at +5+5, inside the display. The toplevel X window reads 1376x730 because Firefox carries a 5px invisible shadow border on each side (there is no window manager under Xvfb, and no
_GTK_FRAME_EXTENTS); the child window matcheswindow.outerWidthexactly.Headless and
headless='virtual'are unaffected — sampled under the 1x1 Xvfb they still produce 3072x1728 and 3440x1440, so no fingerprint diversity is lost.Tests
pythonlib/tests/test_fingerprint_fixes.py, 12 -> 20 passing. Covers the shrink, no-op when already within the display, unset bounds, the avail floor, composition withclamp_window_dimensions(the ordering is load-bearing), the position clamp, and the negative guard.Full pythonlib suite: 53 passed. The 2
test_virtdisplay.pyfailures are pre-existing and reproduce unchanged on a clean tree.Not addressed
BrowserForge silently dropping non-strict constraints is an upstream bug. This change defends against it rather than depending on it being fixed.