fix(desktop): picture-in-picture stays sharp when the preview is scaled down #31568
main fromrefs/pull/31568/head·opened View on GitHubProblem#
Picture-in-picture on desktop is blurry when its source preview is shown scaled down, in a narrow panel or in the mini preview. The frames keep the full viewport size (for example 1280×800), but small text and 1px lines are smeared, so enlarging the picture-in-picture window only shows a stretched low-detail image. With the panel hidden, the same tab gives sharp frames.
Reproduce on the desktop app:
- Open a page with 12 to 16px text in the preview and set a device viewport such as 1280×800, so the panel shows it scaled to fit.
- Choose Float preview over chat, then Pop into separate window.
- Enlarge the picture-in-picture window. Text stays unreadable.
Change#
Cause: Chromium rasters an embedded frame at the scale it is drawn on screen (RemoteFrameView::UpdateCompositingScaleFactor), and picture-in-picture frames are capturePage() copies of that surface (capturePreviewFrame in apps/desktop/src/preview/Manager.ts). JPEG quality is not the cause: a lossless PNG of a guest scaled to 0.6 showed the same loss.
While picture-in-picture is open, a scaled guest gets a matrix3d instead of scale(). The x and y columns keep the on-screen scale and get an extra z term so each column has length 1. Chromium counts those z terms when it computes the raster scale (TryComputeTransform2dScaleComponents in ui/gfx/geometry/transform_util.cc; its comment notes that x/y-to-z terms have no visible effect). The screen drops z, so the guest draws at the same size and position. A small preserve-3d wrapper around the <webview> keeps the z terms until Blink computes the scale. The wrapper now holds the guest's position, so it only contains the guest and the toolbar, resize handles and size label paint as before.
browserViewportLayout.ts:resolveBrowserViewportTransform(scale, fullDetail)returns no transform at scale 1,scale()normally, and thematrix3dfor full detail.HostedBrowserWebview.tsx: uses it withfullDetail = pictureInPictureand wraps the<webview>in the positioned wrapper.
No capture code changes. Closing picture-in-picture returns the guest to scale().
Cost: while picture-in-picture is open, the guest rasters at full resolution, as it already does when the panel is hidden. The transform is set once when picture-in-picture opens and once when it closes; the capture loop does not toggle anything per frame.
Trade-off: at strong downscales the panel shows a full-resolution raster scaled down by the compositor, which can look more aliased than the low-resolution raster. At 0.6 the panel looks the same (mean pixel difference 0.41/255 over the whole window). At 0.33 small text in the panel has harder, more aliased edges (crops below). This applies only while picture-in-picture is open.
Scope and approval#
Bug: #9872 (Refs, not Fixes). The maintainer triage on #21129 closed picture-in-picture blur as a duplicate of #9872 and pointed at capturePage() on the source tab as the frame source. This PR fixes that picture-in-picture case: the same frame size, with full detail when the source is scaled.
Relation to #9916: #9916 fixes saved screenshots, annotation crops and desktop CDP captures. It freezes the displayed preview, removes the host transform, captures, and restores the preview. That fits a single capture, but picture-in-picture captures about 12 times per second, so it would freeze the panel or make it flicker continuously. This PR uses a different mechanism for the picture-in-picture path only and does not touch the capture code that #9916 changes. The two do not conflict.
Not in scope: agent preview_snapshot, the Screenshot button and recordings keep their current behavior when picture-in-picture is closed. The same transform could serve them later, but that would raise raster cost whenever a preview is scaled, which needs its own decision.
Verification#
Environment: Linux (Omarchy, Hyprland), display scale 1. Desktop dev build of this branch (Electron 44.10.1, Chromium 152.0.7977.169), with an isolated T3 home, user data dir and ports. The final runs used Xvfb with X11, so the app had a visible, unthrottled window. Fixture: a local page with 12/14/16px text and a 1px black-and-white stripe band, served from 127.0.0.1. No real websites.
Steps per build (main, then this branch): set the preview to 1280×800 in the right panel, open the mini preview, choose Pop into separate window, wait, then read the newest frame that Manager.ts sent to the picture-in-picture page. Then open the preview in the panel again and read the frame. During the measured windows the desktop log showed 0 capture failures.
Metrics on the delivered JPEG frame: "stripe contrast" is the mean difference between neighbouring pixels across the 1px stripes (255 means fully resolved). "Text edge" is the same measure over the text rows.
| Source state | Guest scale | Frame size | Stripe contrast, main → this PR | Text edge, main → this PR |
|---|---|---|---|---|
| Mini preview | 0.25 | 1280×800 → 1280×800 | 1.1 → 255 | 2.31 → 20.37 |
| Narrow panel | 0.33 | 1280×800 → 1280×800 | 68.8 → 255 | 3.52 → 20.37 |
| Panel, 700×450 viewport | 0.60 | 700×450 → 700×450 | 53.1 → 255 | 8.82 → 20.38 |
Picture-in-picture window enlarged to 1280×800, mini preview source (top-left crop, 100%):
| main | this PR |
|---|---|
Same, narrow panel source:
| main | this PR |
|---|---|
Panel display while picture-in-picture is open (crop scaled up 3×):
| Scale | main | this PR |
|---|---|---|
| 0.60 | ||
| 0.33 |
Other checks:
- Closing picture-in-picture: the guest transform returns to
scale(0.25), and the 3D wrapper style is removed. - Standalone Electron 44.10.1 page with a
<webview>:scale(0.6)gave an 800×600 capture with stripe contrast 51. Thematrix3din apreserve-3dwrapper gave 255 at the same size. A CDP mouse click at host point (320, 270) reached the guest at (500, 400) in both cases.elementFromPointreturned the<webview>. A later sibling that overlaps the guest still painted on top. vp test run src/browser/browserViewportLayout.test.ts(apps/web): 3 passed. The new case checks the matrix layout, so a revert toscale()or a wrong column order fails.vp run check:changed: format, lint, knip, typecheck (2 packages), tests and react compiler pass.
Not checked:
- Clicks and scrolls in the panel inside the dev app. Synthetic CDP clicks did not reach the guest there on main either, so that run proves nothing. Input mapping was checked only in the standalone Electron page.
- macOS, Windows, display scales other than 1, and a Wayland run with the final code. An earlier Wayland run reproduced the blur and showed sharp frames from the narrow panel, but frames went stale when the dev window was on a hidden workspace.
- Long sessions, GPU memory use at very small scales, and pages with their own 3D transforms.
Reviewed with sol-loop: 2 rounds with GPT 6.1 Sol on high. Code: approved. PR text: requested changes applied.
Written by Claude Opus 5.5 in Claude Code.
🤖 Generated with Claude Code
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
Approvability#
Verdict: Approved at
713e130Macroscope's review found this PR approvable — The change preserves sharp picture-in-picture captures when the desktop preview is scaled down. Its effects are confined to preview rendering, with existing webview configuration and product defaults unchanged.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).No actionable comments were generated in the recent review.
Walkthrough
-
The change adds a helper that selects a viewport transform based on scale and full-detail mode. The hosted browser webview uses the resolved transform and positions the webview inside a viewport wrapper.
Changes: Viewport scaling
Layer / File(s) Summary Transform calculation and tests
apps/web/src/browser/browserViewportLayout.ts,apps/web/src/browser/browserViewportLayout.test.tsresolveBrowserViewportTransformreturns no transform at scale 1 or above. Below 1, it returnsscale()or, in full-detail mode, amatrix3d()transform. Tests check these outputs.Hosted webview rendering
apps/web/src/browser/HostedBrowserWebview.tsxThe webview resolves its transform from viewport scale and picture-in-picture state. A positioned wrapper holds the webview and uses preserve-3dwhen picture-in-picture is active and a transform exists.Estimated code review effort: 2 (Simple) | ~12 minutes
Change: Bug fix
Possibly related issues
- pingdotgg/t3code#9872: The issue reports detail loss in narrow and mini previews. This change applies a full-detail transform when picture-in-picture is active.
Possibly related PRs
- pingdotgg/t3code#24818: Both PRs change viewport scaling in
HostedBrowserWebview.
Suggested labels:
bugfix,size:MSuggested reviewers:
maria-rcks,macroscopeapp,juliusmarminge
Merge Risk:
Minimal · up to713e1-
No merge-blocking issue was established. Guest input behavior should receive normal platform testing.
Pre-merge checks:
4-
Check name Status Explanation Title check The title names the main change: picture-in-picture frames stay sharp when the source preview is scaled down. The changeset adds resolveBrowserViewportTransform, which uses a matrix3d transform with a… Description check The description follows the template sections (Problem, Change, Scope and approval, Verification). The Problem section gives the symptom, expected behavior and reproduction steps. The Change section e… Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request. Full details: Title check
-
Explanation
The title names the main change: picture-in-picture frames stay sharp when the source preview is scaled down. The changeset adds resolveBrowserViewportTransform, which uses a matrix3d transform with a preserve-3d wrapper while picture-in-picture is open. The title is specific, and the author's description and objectives state the same goal. The title is a single conventional-commit style sentence and it stays on the main change.
Full details: Description check
-
Explanation
The description follows the template sections (Problem, Change, Scope and approval, Verification). The Problem section gives the symptom, expected behavior and reproduction steps. The Change section explains the cause and the fix, and it names the modified files. The Scope section links bug
#9872and the maintainer triage on#21129, and it explains how the change relates to#9916. The Verification section lists the environment, the measured metrics, before and after images, the tests run, and what was not checked. The description is thorough. The template's comment block at the top of the description was not kept, which does not affect the check.
-
Finishing Touches
-
Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Tip
🎯 Customize your risk assessments
-
Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.
✅ Automatic approvals, with your rules
-
Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.
Recent review info-
Run configuration-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: main
- File: .coderabbit.config.ts
- Commit: 337c585
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Advanced
- Run ID:
bf77841e-7a11-4307-b0c7-128bd04c3294
Commits-
Reviewing files that changed from the base of the PR and between 337c5858c33bc7f8f6dfd391a2c279fa0f7e4d17 and 713e1304d3ca3c10335db92c62106e8e6c5b459f.
Files selected for processing: 3-
apps/web/src/browser/HostedBrowserWebview.tsxapps/web/src/browser/browserViewportLayout.test.tsapps/web/src/browser/browserViewportLayout.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
-
-
Wladefant(GitHub profile, opens in a new tab) approved these changes
APPROVED — exact-head source review#
Reviewer: GPT-6 (ChatGPT GitHub integration). Source author identifies Claude Opus 5.5 / Claude Code. This is a separate reviewer and not author self-review.
Reviewed exact candidate
713e1304d3ca3c10335db92c62106e8e6c5b459fagainstmain@337c5858c33bc7f8f6dfd391a2c279fa0f7e4d17, all three changed files:apps/web/src/browser/HostedBrowserWebview.tsxapps/web/src/browser/browserViewportLayout.tsapps/web/src/browser/browserViewportLayout.test.ts
The source change is narrowly gated by
pictureInPicture. The layout helper guarantees the input scale is positive and at most 1; the full-detail matrix keeps the projected x/y screen scale and top-left placement while making each transformed basis vector unit length for Chromium raster-scale calculation. The wrapper preserves the prior viewport origin and visible bounds; webview identity, partition, preload, popup permission, ref, and data attributes remain on the same guest. Exiting picture-in-picture returns to the ordinaryscale()transform; scale 1 remains untransformed. The helper's regression checks both ordinary and full-detail transforms, including unit-length basis vectors.I found no scoped P1/P2 source-correctness defect in this exact diff. The PR contains before/after captures and measured frame detail, plus a standalone Electron hit-test check. Exact-head normal Actions #42066380601 succeeded:
browserViewportLayout.test.ts3/3; Web suite 5,486/5,486 across 515 files; Test job 246/246 across 35 files; Lint, Build/Typecheck and Check succeeded. Test Server shards, Rust, Release Smoke and Mobile Native Static Analysis were skipped.Acceptance boundary: packaged macOS/Windows, final-code Wayland, non-1× display scales, in-app click/scroll behavior, and long-session/GPU soak remain NOT RUN. These are integration/platform follow-ups, not a blanket source-merge veto; this review does not claim live host or physical acceptance.
Integration note: OPEN PRs #27879 and #28669 also touch
HostedBrowserWebview.tsxon their own author branches. Their inspected hunks are adjacent/disjoint, but neither delta is in this candidate's main-based tree. This approval covers only #31568's isolated diff; the landing owner must preserve/reconcile those independent changes when composing current main.No source/branch writes, CI dispatch, merge, install, device action, or landing custody were performed by this reviewer.
tanstack-source added labelsbug
A data point for this one: the same
matrix3dplacement also fixes blurred agent captures. Turned on while the desktop host paints a guest forpreview_snapshotor a recording, it made agent snapshots of the default panel and the mini player sharp on macOS, with the T3 window in front, covered or minimized (stripe score 0.19 and 0.00 on main, 1.00 with it). Setup and numbers: https://github.com/pingdotgg/t3code/issues/9872#issuecomment-6813114747I have that change on a branch that uses your commit unchanged.
Thanks for this. Main has the change since #36944.
Main now preserves full raster detail while picture-in-picture is open, including narrow-panel and mini-preview sources, and restores ordinary scaling afterward. I compared all three changed files: the transform helper and its test are byte-identical on main, and HostedBrowserWebview includes the same positioned preserve-3d wrapper and transform activation for picture-in-picture.
Closing as superseded.
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes