Skip to content

fix(browser): restore zoom scaling for native view bounds - #2022

Merged
benjaminshafii merged 1 commit into
devfrom
fix/browser-view-zoom-bounds
Jun 1, 2026
Merged

fix(browser): restore zoom scaling for native view bounds#2022
benjaminshafii merged 1 commit into
devfrom
fix/browser-view-zoom-bounds

Conversation

@benjaminshafii

Copy link
Copy Markdown
Member

Problem

After #2020, the embedded browser view is misaligned within its panel whenever the app zoom is not 100%. At zoom 1.0 it's pixel-perfect; at any other zoom the native view no longer lines up with the panel chrome.

Root cause

#2020 removed the * zoom multiply from computeBounds, on the assumption that getBoundingClientRect() already reports coordinates in the native view's coordinate space. That assumption is wrong.

Zoom is applied via Electron's webContents.setZoomFactor (see __setZoomFactor in main.mjs). Under setZoomFactor(f), the page is scaled so getBoundingClientRect() / innerWidth report CSS pixels divided by the zoom factor. WebContentsView.setBounds, however, takes window device-independent pixels — a content area whose size does not change with page zoom.

Verified live via a temporary debug IPC (getContentBounds / view getBounds):

zoom 1.0 zoom 1.5
innerWidth 1180 786 (= 1180 / 1.5)
window contentBounds.width 1180 1180 (unchanged)

So renderer rects must be multiplied back by the zoom factor (786 × 1.5 = 1180) to map into native DIP. Removing the multiply under-scaled the view at zoom ≠ 1.

Fix

Restore the zoom multiplication in computeBounds and getNativeMenuPoint (extracted into a small getZoomFactor() helper), while keeping the rounded-edge width/height derivation from #2020 that avoids a 1px seam. At zoom = 1 the output is identical to current dev.

Testing

pnpm --filter @openwork/app typecheck → exit 0.

Verified live via CDP at zoom 1.0 and 1.5 by comparing the panel chrome rect (×zoom) to the actual native WebContentsView bounds:

  • zoom 1.0: view {x:705, y:81, w:431, h:739} — matches placeholder exactly.
  • zoom 1.5: view {x:745, y:122, w:369, h:698}leftAligned: true, rightAligned: true, chrome-bottom→view-top gap: 0. Right edge (1114) leaves exactly the 66 DIP (44 CSS × 1.5) rail.
  • Bounds auto-resync on a live zoom change (ResizeObserver fires, no manual nudge needed): autoSynced: true.

Reproduce

  1. pnpm dev, open a session.
  2. Zoom the app (Cmd +) to e.g. 150%.
  3. Click the Globe rail button → browser opens on Google and the web view fills the panel flush with the chrome (no offset/gap).

Notes

PR #2020 removed the `* zoom` factor from computeBounds on the incorrect
assumption that getBoundingClientRect() already reflects the page zoom in
the native coordinate space. It does not.

The renderer applies zoom via Electron's webContents.setZoomFactor, which
scales the page so getBoundingClientRect()/innerWidth report CSS pixels
DIVIDED by the zoom factor (verified live: at zoom 1.5 a 1180 DIP window
measures innerWidth 786). WebContentsView.setBounds, however, expects
window device-independent pixels — a fixed 1180-wide content area that
does not change with zoom. So renderer rects must be multiplied back by
the zoom factor to map into the native space.

Restore the multiplication (keeping the rounded-edge width/height that
avoids a 1px seam). At zoom = 1 the result is identical to before.

Verified live via CDP at zoom 1.0 and 1.5: the native view's left/right
edges and top exactly match the panel chrome (leftAligned/rightAligned
true, chrome-bottom-to-view-top gap 0), and bounds auto-resync on zoom
change.
@vercel

vercel Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
openwork-app Ready Ready Preview, Comment Jun 1, 2026 9:02pm
openwork-den Ready Ready Preview, Comment Jun 1, 2026 9:02pm
openwork-den-worker-proxy Ready Ready Preview, Comment Jun 1, 2026 9:02pm
openwork-landing Ready Ready Preview, Comment, Open in v0 Jun 1, 2026 9:02pm

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Re-trigger cubic

@benjaminshafii
benjaminshafii merged commit 4415271 into dev Jun 1, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant