[Bug]: preview_snapshot of a desktop-drawn tab is sized by the display DPR (960×600 at 150% scaling) #16690
Before submitting#
- I searched existing issues and did not find a duplicate.
- 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.
juliusmarminge added labelsbug
juliusmarminge added labelsvia-triage
Also on the 0.1.0 release (
81493efb71e8), Windows 11 at 175% scaling (DPI 168):preview_snapshotof 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:1994passesrenderScale: RENDER_SCALE, andServerBrowserPage.ts:187picks 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.)
juliusmarminge closed this
Sign in to join this conversation.
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).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.deviceScaleFactor: 2(ServerBrowserContexts.ts), so1280 × 2 × 0.5 = 1280.applyZoomearly-returns whentab.desktopis set (ServerBrowser.ts), so the page keeps the display DPR (e.g. 1.5) →1280 × 1.5 × 0.5 = 960.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)
Next step
Stop assuming page DPR is always
RENDER_SCALEfor the clip. For desktop-drawn tabs, either (a) read the page’s realdevicePixelRatioand use that in the scale / reported-size math, or (b) temporarily applyEmulation.setDeviceMetricsOverridewithdeviceScaleFactor: RENDER_SCALEfor 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.