# Native page bounds in the built-in browser

The Electron shell's DOM and each native `WebContentsView` keep the same page bounds at any shell zoom. `setBounds` takes DIP; the renderer measures CSS px.

## Unit conversion

| Part | Behaviour |
| --- | --- |
| Renderer | Sends fractional CSS px from `getBoundingClientRect()` |
| IPC boundary | Main reads `event.sender.getZoomFactor()` on every call, converts to DIP, then rounds to integers and keeps sizes nonnegative. An invalid or nonpositive zoom counts as `1`. |
| Entry points | `webtab:sync-visible` and the compatibility `webtab:set-bounds` convert alike. Internal show, hide and transfer paths already use DIP and are not scaled again. |
| Zoom change | The renderer's `resize` listener remeasures and sends current bounds |
| Example, zoom about 1.095 | `x=812.63, width=518.64` CSS px becomes about `x=890, width=568` DIP. Unconverted, the page covers the chat pane and leaves a blank strip on the right. |
| Left alone | User zoom, split ratios, DOM layout, preload APIs, site zoom, Browser Agent, dependencies, configuration |

## Overlays

A DOM overlay hides a native page only when its visible rectangle intersects that page's body. Each `WebTabPane` tests its own body against the current overlays; there is no shared visible flag.

| Overlay | Detected by | Native page |
| --- | --- | --- |
| Popover, dropdown, listbox, tab and split menus | `role=dialog/menu/listbox` | Only intersecting panes hide. Working-directory, project and permission menus inside the chat pane hide nothing next door. |
| Full-screen modals, confirmation backdrops, attachment previews | `data-native-view-occluder=true` or the merge backdrop | Every covered pane hides |
| Tooltips, toasts, drag cues, ordinary portaled content | Excluded from the selector | Stays visible |
| Desktop main, context and bookmark native menus | Own overlay owner in main | Native-menu lifecycle, not renderer DOM |

Zero area or edge-only contact hides nothing. MutationObserver, ResizeObserver and scroll and resize listeners republish bounds when an overlay closes, moves or resizes; global flush batches microtasks in one tick.

## Floating preview

Agent picture-in-picture previews use the same `registerVisibleWebTabBounds` / `syncVisible` path and publish only the small window's body, so toolbar buttons and the lower-right resize handle stay outside the native view. Two layers: a still picture below, the live native page on top. The page shows only with no hold active (`PipHoldReason`, `apps/web/components/center-tabs/pip/web-tab-pip-surface.tsx`).

| Hold | While |
| --- | --- |
| `gesture` | Dragged or resized |
| `clip` | The scrolled dock column hides part of it |
| `cover` | A menu, dialog or popover overlaps it; the page goes down at once under its last picture |
| `motion` | It folds into or unfolds from the composer's web page chip |

**Timing and layout**

| Aspect | Behaviour |
| --- | --- |
| First hold | Captures a frame and shows it. A capture slower than 150 ms (`PIP_PICTURE_WAIT_MS`) shows the last cached picture until it arrives. Native bounds are withdrawn within those 150 ms either way. |
| Last release | Final bounds are published; the picture goes once the page has painted there |
| Layout | `setPipZoom` lays the page out 1920 wide and as tall as the preview's shape makes it, scaled to fill edge to edge |
| First show or new size | Laid out out of sight, then waits for a paint, 250 ms (`PIP_RELAYOUT_MS`) and another paint for script-driven pages. Never shows at standard size or half laid out. |
| Folded | Keeps that layout, so it unfolds as it went. A pane that shows the page resets the user's zoom. |
| Pictures | Cached per tab; the next unfold starts from one |
| Motion | Closing from the chip or ✕ folds over 240 ms, showing unfolds over 280 ms (`apps/web/lib/browser/web-tab/web-tab-pip-motion.ts`). With Reduce Motion it appears and goes at once. |
| Background pages | Untouched: the native view stays alive, only its bounds are withheld |

## Residual: a split page ahead of its frame

The native page and the App's DOM reach the display as two compositor clients, so a split pane's page can show away from its frame during a move. The floating preview covers this with a hold; a split pane has none.

- **Measured**: Dev App, 24 split-sidebar moves at load 4.6 to 6.2: 112 of 979 draws away, by up to 13 px

**Why per-frame reports cannot fix it**

The renderer measures while laying out a frame and sends bounds in a microtask; main moves the view at once, and its frame reaches the display compositor about 1 ms later. The App's own frame still needs main frame, commit and raster.

Both land together only while the App's frame meets the deadline: at 120 Hz good rounds have no slack, and a bad round arrives 0.3 to 0.7 ms late.

Every frame of a move costs about the same, so one late frame leaves the page ahead for the whole move (16 to 18 draws, up to 14 px), in one move in twelve to one in four at load 4 to 8.

| Attempt | Why not |
| --- | --- |
| Renderer | Cannot know its frame will be late |
| Main replays the move on its own schedule | Late against a late DOM frame in the same way |
| `beginFrameSubscription` | Arrives after the draw, leaving the page a frame behind every time |

The display compositor keeps surfaces in step only when one compositor frame embeds the other, as for a `<webview>` guest or an out-of-process iframe.

## Why pages are not guests of the App's frame

A `<webview>` guest moves, clips and folds with the DOM and takes no bounds. In 48 split-panel moves at load 6 to 12 on the Dev App and Electron 45, no draw showed it away from its frame, and move frames were slightly cheaper (median 3.2 to 3.4 ms against 3.7 to 3.9). Agent input decides against it:

| Agent input | Guest | Native view |
| --- | --- | --- |
| Typed text and keys over CDP | Go to the App window's focused frame: into the composer, where Enter could send the user's message | Reach the page, App focus untouched |
| `webContents.insertText` | Reaches the focused element without touching App focus | Not needed |
| `sendInputEvent` keys | Arrive only after the widget has held focus once; no editing commands, so Command+A does nothing | Shortcut commands work over CDP |
| Clicks | Move the App's keyboard focus into the guest every time. Giving it back runs on the renderer thread; with it busy for 150 ms, the user's next keystroke landed in the page. | Never touch App focus |

The floating preview is where the Agent's page shows while the user types, so guests are no safer there. Switching a page between native and guest also reloads it: history, scroll and form values can be restored (`navigationHistory.restore`), script state, connections, `sessionStorage` and editors outside form fields cannot.

**Code and verification**

| Item | Detail |
| --- | --- |
| Code | `apps/desktop/main.js`, `apps/web/components/center-tabs/browser/web-tab-pane.tsx`, `apps/web/lib/browser/web-tab/web-tab-bounds.ts` |
| `apps/desktop/tests/web-views/check-webtab-zoom-bounds.js` | 100% and about 109.5% zoom, invalid zoom, both IPC entries, desktop regressions |
| `check:web-split` | Rectangle intersection per Web body: a left menu leaves a right page visible; dialog, menu, listbox and full-screen backdrops judged per pane; zero area and edge contact hide nothing. General `DialogOverlay`, permission confirmations, context click-catchers and scoped drop overlays enter through `data-native-view-occluder`. |
| Installed App, about 109.5% zoom | DOM body and native viewport both `568×763` DIP; after resizing the window to `1350×800`, both `526×712` DIP. Also check splits and split-ratio changes. |

## Implementation status

| Status | Items |
| --- | --- |
| Implemented | Unit conversion, overlay rules, preview holds, automated gates |
| Not built | Guests: no switch, `<webview>` wiring, adoption, preview surface or Agent relay exists |
| Known residual | Split panes can show a page ahead of its frame |

[Built-in browser](https://fzkuji.github.io/OpenProgram/docs/reference/design/ui/browser/built-in-browser.html)
