Skip to content

fix(desktop): fit browser previews at any window zoom - #833

Merged
incognitojam merged 3 commits into
mainfrom
styal/fix-preview-browser-scaling
Oct 15, 2026
Merged

incognitojam merged 3 commits into
mainfrom
styal/fix-preview-browser-scaling

Conversation

@incognitojam

@incognitojam incognitojam commented Oct 15, 2026 •

Copy link
Copy Markdown
Owner

Note

Fixes cropping and wrong click locations in fitted desktop browser previews across independent window and page zoom.

Fitted browser previews crop the page when the desktop window or preview page is zoomed out and leave unused space when zoomed in. The page can also measure a different CSS viewport from the requested size. Screenshots capture the same incorrect surface, and agent clicks miss their targets because their logical coordinates are sent directly to the scaled surface.

Convert requested CSS dimensions to CDP device-independent dimensions using page zoom, and account for host window zoom in presentation scaling. Map agent click coordinates into the fitted surface while preserving logical cursor coordinates. Clicks use the scale successfully applied to their CDP session while a resize or window-zoom update waits. Restore every tab's independent page zoom before refreshing fitted presentations concurrently, so a busy tab cannot delay restoration for the others. Refreshes read the latest requested viewport without rewriting it and check session ownership, preserving queued resizes and preventing a detached session from changing its replacement.

Validation

  • Reproduced the cropping in the built-in Browser panel. Exercised the real preview manager in an isolated Electron window using resolveBrowserViewportLayout to derive presentation. All nine combinations of window zoom 80%/100%/120% and page zoom 90%/100%/110% preserve the requested 1280×800 CSS viewport, fill the captured surface to all four edges, and deliver locator clicks to the button. Window-zoom changes in this matrix exercise reapplyZoom without a renderer presentation resend.
  • Exercised a 375×667 viewport, a mini-player-sized surface, restoration to panel size, saved screenshot artifacts, and clearing viewport emulation. Full packaged-app verification requires a desktop rebuild.
  • Deterministic concurrency regressions cover fill-to-fitted and fitted-to-fill resizes queued during a click, window zoom changing during a click, a busy fitted tab while another tab's page zoom is restored, and a resize queued during recording startup followed by a zoom refresh.
  • Queued-action tests verify input coordinates, ordering, and the final native presentation. A second fitted tab refreshes while the first is busy, then the first refreshes when released. A detached-session regression fails when its session-ownership guard is removed.
  • All 168 focused tests pass across Manager.test.ts, DesktopWindow.test.ts, and hostedBrowserWebviewStyle.test.ts. Desktop typecheck, targeted lint, and formatting checks pass.

Known limitation: presets rendered at fit scale 1 still inherit window zoom in their measured CSS size. This pre-existing natural-size path is tracked for upstream intake; its guest-zoom composition needs adaptation to the fork's CDP presentation path.

Before / after

The same synthetic 1280×800 page in a fitted surface at 80% window zoom, captured through the real manager on main and this branch:

Before After
Before: right and bottom viewport corners are cropped After: all four viewport corners fit the surface

The page-zoom correction at 80% window zoom and 90% page zoom, using renderer-derived presentation. Before, the requested 1280×800 viewport measures 1422×888 and crops the bottom-right edge; after, it measures 1280×800 and fills the surface:

Before page-zoom correction After page-zoom correction
Before: 90 percent page zoom crops the viewport After: renderer-derived page zoom preserves the viewport and its full surface

Written by an agent (Codex, gpt-6.1-sol).

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Upstream divergence

Both sides are compared with upstream at the in-order tip 33b7d7b3ae. Excludes .repos/ and pnpm-lock.yaml.

Measure Base This PR Change
Upstream files the fork changes 1,368 1,368 0
Lines changed in them 62,408 62,897 +489
Upstream files the fork removes 41 41 0
Fork-only files 435 435 0
Fork-only lines 74,632 74,636 +4
Upstream files whose difference changes (2)
File Change Now differs by
apps/desktop/src/preview/Manager.test.ts +429 1,065 lines
apps/desktop/src/preview/Manager.ts +60 578 lines

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

Provider Metric Main baseline This PR Impact PR ceiling
Codex Total thread wire 4.9 KiB 5.0 KiB +139 B (+2.8%) 6.8 KiB ✅
Codex Thread snapshot wire 3.7 KiB 3.8 KiB +81 B (+2.1%) 4.9 KiB ✅
Codex Live turn WebSocket wire 1.1 KiB 1.2 KiB +58 B (+5.0%) 2.0 KiB ✅
Codex Live turn WebSocket decoded 20.4 KiB 20.9 KiB +482 B (+2.3%) 29.3 KiB ✅
Codex Live turn messages 1 2 +1 (+100.0%) 8 ✅
Claude Total thread wire 4.9 KiB 5.0 KiB +100 B (+2.0%) 6.8 KiB ✅
Claude Thread snapshot wire 3.7 KiB 3.8 KiB +82 B (+2.2%) 4.9 KiB ✅
Claude Live turn WebSocket wire 1.2 KiB 1.2 KiB +18 B (+1.5%) 2.0 KiB ✅
Claude Live turn WebSocket decoded 20.8 KiB 21.2 KiB +441 B (+2.1%) 29.3 KiB ✅
Claude Live turn messages 2 2 0 (0.0%) 8 ✅

Baseline: a1861e2 · PR result: 60856bb · Source CI: success

Scenario and decoded snapshot size

10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

  • Codex decoded thread snapshot: 108.5 KiB
  • Claude decoded thread snapshot: 108.8 KiB

Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

@github-actions github-actions Bot added size:L and removed size:M labels Oct 15, 2026
@incognitojam
incognitojam merged commit 2c68e22 into main Oct 15, 2026
32 of 33 checks passed
@incognitojam
incognitojam deleted the styal/fix-preview-browser-scaling branch October 15, 2026 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant