Skip to content

feat: enhance screenshot functionality to restore viewport size and support CDP overrides - #123

Merged
beubax merged 2 commits into
agentrhq:mainfrom
rajarshidattapy:fix/screenshot-viewport-restore-120
Jul 23, 2026
Merged

feat: enhance screenshot functionality to restore viewport size and support CDP overrides#123
beubax merged 2 commits into
agentrhq:mainfrom
rajarshidattapy:fix/screenshot-viewport-restore-120

Conversation

@rajarshidattapy

Copy link
Copy Markdown
Contributor

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:

  • Emulated viewport (non-null): override via setViewportSize, restore the prior size in finally — unchanged behavior.
  • Real-window context (viewportSize() === null): setViewportSize can't return to a windowed state, so it overrides reversibly via CDP Emulation.setDeviceMetricsOverride and clears it with Emulation.clearDeviceMetricsOverride in finally — fully restoring the real window. Reuses the existing context.newCDPSession pattern.

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

  • 🐛 Bug fix
  • ✨ New feature
  • 🌐 New site adapter
  • 📝 Documentation
  • ♻️ Refactor
  • 🔧 CI / build / tooling

Checklist

  • I ran the checks relevant to this PR
  • I updated tests or docs if needed
  • I included output or screenshots when useful

Adapter Notes

N/A — runtime fix, no adapter or command-discoverability changes.

  • Updated generated or lean docs when command discoverability changed
  • Used positional args for the command's primary subject unless a named flag is clearly better
  • Normalized expected adapter failures to CliError subclasses instead of raw Error

Screenshots / Output

$ npx vitest run src/browser/runtime/local-cloak/provider.test.ts

Test

Test Files 1 passed (1)
Tests 25 passed (25)

  • npx tsc --noEmit clean on src.

@github-actions

Copy link
Copy Markdown
Contributor

🟢 No documentation gap found — medium confidence

The automated review found no documentation gap in the supplied changes.

This review is advisory and does not block merging.

@beubax
beubax merged commit 0ba71d6 into agentrhq:main Jul 23, 2026
15 checks passed
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