feat: enhance screenshot functionality to restore viewport size and support CDP overrides - #123
Merged
beubax merged 2 commits intoJul 23, 2026
Conversation
…upport CDP overrides
Contributor
🟢 No documentation gap found — medium confidenceThe automated review found no documentation gap in the supplied changes. This review is advisory and does not block merging. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes a screenshot viewport leak: --width/--height overrides were permanently pinning the viewport on real-window (stealth) sessions.
applyScreenshotViewport returned page.viewportSize() as the value to restore, but that is null when the Cloak context uses the real OS window (viewport: null). The finally guard if (previousViewport) then treated null as "nothing to restore" and skipped it, so the override (e.g. 375×812) stuck for every subsequent command in that session.
Replaced the helper with captureScreenshot(page, context, command) that restores in both cases:
Added a regression test for the previously-uncovered null-viewport path (asserts setViewportSize is never called, the CDP override is applied and then cleared/detached).
Related issue: #120
Type of Change
Checklist
Adapter Notes
N/A — runtime fix, no adapter or command-discoverability changes.
Screenshots / Output
$ npx vitest run src/browser/runtime/local-cloak/provider.test.ts
Test
Test Files 1 passed (1)
Tests 25 passed (25)