Skip to content

Use captureBeyondViewport for full-page screenshots instead of window resize#580

Merged
route merged 2 commits intorubycdp:mainfrom
mickeytgl:fix-full-page-screenshot-focus-steal
Apr 22, 2026
Merged

Use captureBeyondViewport for full-page screenshots instead of window resize#580
route merged 2 commits intorubycdp:mainfrom
mickeytgl:fix-full-page-screenshot-focus-steal

Conversation

@mickeytgl
Copy link
Copy Markdown
Contributor

@mickeytgl mickeytgl commented Apr 21, 2026

Problem

Page#screenshot(full: true) resizes the window to fullscreen and back (maybe_resize_fullscreen). On macOS Chrome this triggers native fullscreen so the window steals focus from whatever app you're in if you're working while letting an agent run a task on your browser (this is how I found the issue).

Fix

Pass captureBeyondViewport: true to Page.captureScreenshot and drop the resize. CDP-native since Chrome 81; same flag Playwright and puppeteer use for full-page screenshots. Output is the same, one CDP round-trip instead of three, no window-state mutation.

Replaces the window-resize hack in capture_screenshot with CDP's
native captureBeyondViewport: true flag on Page.captureScreenshot.

The previous approach called Browser.setWindowBounds to put the
window into windowState: "fullscreen" before capture and back to
"normal" in an ensure block. On macOS Chrome this triggers *native*
fullscreen, moving the window to its own Space and stealing focus
from the user's foreground app on every full-page screenshot.

captureBeyondViewport has been stable in Chrome since v81 and is the
same flag Playwright and puppeteer use for their fullPage path.
Output is pixel-identical, one CDP round-trip instead of three, no
window-state mutation.

Also implicitly fixes rubycdp#178 — huge pages that returned blank under the
resize approach (because the window can't grow past the display size)
now render correctly, since the native path has no viewport ceiling.
@route
Copy link
Copy Markdown
Member

route commented Apr 22, 2026

Very nice! Mind adding changelog entry? And we are good to go!

@mickeytgl
Copy link
Copy Markdown
Contributor Author

No problem! Done ✅

@route route merged commit 25367b5 into rubycdp:main Apr 22, 2026
7 checks passed
@route
Copy link
Copy Markdown
Member

route commented Apr 22, 2026

Thank you so much!

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.

2 participants