[Bug]: preview_snapshot of a desktop-drawn tab is sized by the display DPR (960×600 at 150% scaling)
Before submitting
- [x] I searched existing issues and did not find a duplicate.
- [x] I included enough detail to reproduce or investigate the problem.
Area
apps/server
Steps to reproduce
- Windows 11 at 150% display scaling. Run the desktop app (
0.0.46-nightly.20261006.2735) on its bundled local server. - Show the preview panel and have the agent call
preview_openon any page, so the tab is drawn in the desktop<webview>. Maximize the panel. The page reportsinnerWidth1280,innerHeight800,devicePixelRatio1.5. - Call
preview_snapshotwithsave: trueand check the saved PNG's pixel size.
Expected behavior
The PNG is 1280×800, the viewport size, as it is for a headless tab.
Actual behavior
The PNG is 960×600, while the tool result reports screenshot.width 1280 and height 800. A tab opened while the panel was hidden ran headless and captured at 1280×800, sharp.
Cause, from main at bfec2387b: ServerBrowser.ts:1657 passes renderScale: 2, and ServerBrowserPage.ts:187 picks scale = 1280 / (1280 × 2) = 0.5 for the CDP clip in captureViewport. The clip scale multiplies the page's actual device pixels. Headless tabs run at deviceScaleFactor: 2 (ServerBrowserContexts.ts:106), so 1280 × 2 × 0.5 = 1280. The server attaches to a desktop-drawn tab without that override (ServerBrowser.ts:587), and this page reported DPR 1.5, so 1280 × 1.5 × 0.5 = 960. The same math gives 640×400 at 100% and 1600×1000 at 250% (not measured). On 2x displays the factors cancel.
This is separate from #9872, where detail follows the panel's on-screen size and the PNG stays the viewport size, and from #16578, which is about the JPEG viewer stream. Here the saved PNG and its reported size disagree even with the panel maximized. This capture code came with #15328.
Impact
Major degradation or frequent failure
Version or commit
0.0.46-nightly.20261006.2735; line references at main bfec2387b.
Environment
Windows 11, desktop app on its bundled server, 150% display scaling. Captures were taken by an agent; nothing else was tested.
Logs or stack traces
No response
Screenshots, recordings, or supporting files
Fixture: 12/14/16 px text and 1 px line patterns, viewport 1280×800.
Headless tab, 1280×800:
Desktop-drawn tab, panel maximized, 960×600:
Workaround
A tab opened while the panel was hidden ran headless and captured at full size. Hiding the panel for a tab the desktop already draws was not tested.
Written by Claude Fable 5.1 and Claude Opus 5.5 on behalf of ScottN-PV.
[!NOTE] Grok responding on behalf of Julius.
Confirmed on main (bfec2387b): this is a real sizing mismatch for desktop-drawn tabs when display DPR ≠ 2.
Mechanism (matches the report)
preview_snapshotalways passesrenderScale: RENDER_SCALE(RENDER_SCALE = 2) intoServerBrowserPage.snapshot(ServerBrowser.ts, L1657).- Snapshot picks CDP clip scale as
MAX_SCREENSHOT_WIDTH / (viewport.width * renderScale)→1280 / (1280 × 2) = 0.5(ServerBrowserPage.ts), and that scale multiplies the page’s actual device pixels inPage.captureScreenshot. - Headless contexts are created with
deviceScaleFactor: 2(ServerBrowserContexts.ts), so1280 × 2 × 0.5 = 1280. - Desktop-drawn tabs connect over CDP to the existing webview page with no DSF override (connectDesktopPage), and
applyZoomearly-returns whentab.desktopis set (ServerBrowser.ts), so the page keeps the display DPR (e.g. 1.5) →1280 × 1.5 × 0.5 = 960. - Reported
screenshot.width/heightare computed fromviewport × renderScale × scale(ServerBrowserPage.ts), not from the PNG, which is why the tool result can say 1280×800 while the file is 960×600.
On 2× displays the factors cancel; at 100%/250% the same math would undersize/oversize as described.
Related (different bugs)
- #9872 / open #9916 — CSS-scaled desktop capture loses detail; PNG dimensions stay at viewport size. Does not address this server-side clip/DPR assumption.
- #16578 — JPEG viewer/screencast stream quality, not saved PNG sizing.
- Capture path landed with merged #15328. No open PR found that fixes this desktop DPR mismatch.
Next step
Stop assuming page DPR is always RENDER_SCALE for the clip. For desktop-drawn tabs, either (a) read the page’s real devicePixelRatio and use that in the scale / reported-size math, or (b) temporarily apply Emulation.setDeviceMetricsOverride with deviceScaleFactor: RENDER_SCALE for the capture (as headless already runs), then restore. Prefer (a) if we want the bitmap to match the on-screen webview; (b) if we want every snapshot normalized to the headless 2× path. Also derive reported width/height from the captured bitmap (or the same actual DPR) so tool result and PNG stay consistent.
Thanks for the clear repro and the line-level write-up — very helpful.
Also on the 0.1.0 release (81493efb71e8), Windows 11 at 175% scaling (DPI 168): preview_snapshot of a desktop-drawn tab with a 1280×800 viewport saved a 1120×700 PNG, as the formula above predicts (1280 × 1.75 × 0.5). Same path there: ServerBrowser.ts:1994 passes renderScale: RENDER_SCALE, and ServerBrowserPage.ts:187 picks the 0.5 clip scale. A headless Chromium capture forced to DPR 1.75 with the same 0.5 clip gives 1120×700 too, and stays sharp, so the size and the blur in #9872 are separate.
(Investigated with an AI agent on the account owner's machine.)