[PR #5621] [MERGED] fix(browser): capture the full visual viewport #7000

Closed
opened 2026-11-01 21:44:37 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/5621
Author: @STDquantum
Created: 10/20/2026
Status: ✅ Merged
Merged: 10/22/2026
Merged by: @morluto

Base: main ← Head: fix/browser-visual-viewport-screenshot


📝 Commits (4)

  • c6fc256 fix(browser): capture the full visual viewport
  • 530f2f5 fix(browser): preserve surface geometry and high-DPI screenshot bounds
  • 1b9f87f chore: merge upstream screenshot identity fixes
  • 6c989e1 fix(browser): reject stale screenshot captures

📊 Changes

6 files changed (+946 additions, -17 deletions)

View changed files

📝 scripts/fixtures/browser-verifier-site.mjs (+7 -0)
➕ scripts/lib/browser-viewport-screenshot-e2e.mjs (+195 -0)
📝 scripts/verify-real-browser.mjs (+7 -0)
📝 src/browser/CdpScreenshot.ts (+153 -17)
📝 tests/boundary/browser/cdpScreenshotDocumentIdentity.test.ts (+567 -0)
📝 tests/fixtures/fakeCdpBrowserResults.ts (+17 -0)

📄 Description

Summary

Fixes #5610.

REA could return a cropped screenshot and still describe it as the complete visible viewport. Capture now checks the image against the measured viewport and recovers a truncated surface with an explicit clip. Normal surface captures keep their scrollbars and pixel density.

Problem and expected behavior

On Windows Chrome, a 1280×720 emulated viewport produced a 1264×569 PNG, losing a marker at CSS row 650 despite reporting complete viewport coverage. A screenshot should cover the measured viewport or report why it could not. It must not return an old page region after the viewport changes.

Change and scope

Keep the normal surface PNG when it covers the visual viewport, preserving scrollbars and pixel density. Otherwise, retry once using a fresh CSS viewport clip. Device-pixel metrics supply the coverage lower bound; CSS metrics supply clip coordinates.

Read and validate geometry before and after each capture. If position, dimensions, scale, or pixel density change, return target_changed. Check observed document identity, navigation, and allowed origins after awaits, before issuing another capture. Invalid metrics or insufficient recovery return protocol_error.

This stays within the existing screenshot workflow; no new provider or target authority is introduced.

Contract and boundary impact

  • Semantic owner: CdpScreenshot, at the CDP capture boundary.
  • CLI/MCP inputs, output schema, generated catalog, package metadata, and installation: unchanged.
  • Provider/platform: Chrome-family CDP; tested locally on Windows Chrome.
  • Evidence: retain the existing PNG identity and document/origin checks, while capturing the requested visible area.
  • Authority and cleanup: the existing browser attachment owns the extra metrics query. No scrolling, target script evaluation, or emulation override is added.

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

The network effect is the existing connection to the caller-selected CDP endpoint.

Evidence and regression coverage

Boundary tests cover stable recovery, CSS/device-pixel units, scrollbar preservation, malformed metrics, and document identity. New cases deliver scope-loss events while metrics are pending and assert that no subsequent screenshot is issued. Scroll, resize, zoom, density changes, and invalid refreshed metrics are also covered.

The real Chrome regression records actual production commands and PNG responses. It asserts that the first image really is undersized and that a clipped retry occurs. Chrome restores the capture session's own metrics during recovery in this external-session fixture; the operation now correctly returns target_changed. The internal recovery PNG is compared pixel-for-pixel with a direct CSS-clip control. A separate stable-viewport capture must succeed with matching dimensions and pixels. Both page scales (1 and 2) pass, including a separate physical-DPR-2 run at 2560×1440.

The real success case does not prove stable cropped recovery; that behavior is covered by wire boundary tests. Existing large-PNG CLI/MCP parity and export checks remain intact.

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • Five focused screenshot, browser lifecycle/document, CLI, and MCP files: 98 tests passed, including 38 screenshot tests.
  • npm run check: passed.
  • npm run verify:browser: passed on Windows Chrome 155.0.8059.85, including large-PNG CLI/MCP/export checks and the strengthened viewport regression. Whole-verifier Windows process lineage is unavailable; provider-owned cleanup is checked separately.
  • Separate physical-DPR-2 production-boundary run: both page scales passed.
  • An independent agent with no inherited conversation reviewed the production changes and final real-browser helper. It found no demonstrated actionable defect. This was source review, not an independent rerun of the suite.

Compatibility, safety, and release

No schema change or migration is required. macOS/Linux, Edge, mobile viewports, and older Chromium were not tested. Geometry sampling is not atomic: changes after a sample or changes that return to the same values can still escape detection. Rejecting a result cannot undo a capture already in flight.

Normal screenshots add two metrics requests; a cropped surface needs three and at most one extra screenshot. Timing, CPU, and peak process-family memory costs were not measured.

Author readiness

Human owner: @STDquantum

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/5621 **Author:** [@STDquantum](https://github.com/STDquantum) **Created:** 10/20/2026 **Status:** ✅ Merged **Merged:** 10/22/2026 **Merged by:** [@morluto](https://github.com/morluto) **Base:** `main` ← **Head:** `fix/browser-visual-viewport-screenshot` --- ### 📝 Commits (4) - [`c6fc256`](https://github.com/morluto/rea/commit/c6fc2564d7288d71ad49bec066c3cd840b132031) fix(browser): capture the full visual viewport - [`530f2f5`](https://github.com/morluto/rea/commit/530f2f53687ed21cfd2fb65ce6ec0b1c63a56c56) fix(browser): preserve surface geometry and high-DPI screenshot bounds - [`1b9f87f`](https://github.com/morluto/rea/commit/1b9f87f8c44bf684e083e5d4fac04ef09912cc2a) chore: merge upstream screenshot identity fixes - [`6c989e1`](https://github.com/morluto/rea/commit/6c989e15912c659ba9e0f74da2d3433553993c66) fix(browser): reject stale screenshot captures ### 📊 Changes **6 files changed** (+946 additions, -17 deletions) <details> <summary>View changed files</summary> 📝 `scripts/fixtures/browser-verifier-site.mjs` (+7 -0) ➕ `scripts/lib/browser-viewport-screenshot-e2e.mjs` (+195 -0) 📝 `scripts/verify-real-browser.mjs` (+7 -0) 📝 `src/browser/CdpScreenshot.ts` (+153 -17) 📝 `tests/boundary/browser/cdpScreenshotDocumentIdentity.test.ts` (+567 -0) 📝 `tests/fixtures/fakeCdpBrowserResults.ts` (+17 -0) </details> ### 📄 Description ## Summary Fixes #5610. REA could return a cropped screenshot and still describe it as the complete visible viewport. Capture now checks the image against the measured viewport and recovers a truncated surface with an explicit clip. Normal surface captures keep their scrollbars and pixel density. ## Problem and expected behavior On Windows Chrome, a 1280×720 emulated viewport produced a 1264×569 PNG, losing a marker at CSS row 650 despite reporting complete viewport coverage. A screenshot should cover the measured viewport or report why it could not. It must not return an old page region after the viewport changes. ## Change and scope Keep the normal surface PNG when it covers the visual viewport, preserving scrollbars and pixel density. Otherwise, retry once using a fresh CSS viewport clip. Device-pixel metrics supply the coverage lower bound; CSS metrics supply clip coordinates. Read and validate geometry before and after each capture. If position, dimensions, scale, or pixel density change, return `target_changed`. Check observed document identity, navigation, and allowed origins after awaits, before issuing another capture. Invalid metrics or insufficient recovery return `protocol_error`. This stays within the existing screenshot workflow; no new provider or target authority is introduced. ## Contract and boundary impact - Semantic owner: `CdpScreenshot`, at the CDP capture boundary. - CLI/MCP inputs, output schema, generated catalog, package metadata, and installation: unchanged. - Provider/platform: Chrome-family CDP; tested locally on Windows Chrome. - Evidence: retain the existing PNG identity and document/origin checks, while capturing the requested visible area. - Authority and cleanup: the existing browser attachment owns the extra metrics query. No scrolling, target script evaluation, or emulation override is added. Expected effects: - [x] Read existing files or captured data. - [x] Launch or attach to a process. - [ ] Inject instrumentation or run scripts/code. - [ ] Change process memory, registers, files, or configuration. - [x] Contact network services. - [ ] Recover protected code or work around protections. - [ ] Documentation or usability only; no target interaction. - [ ] Not sure yet; investigation or maintainer guidance needed. The network effect is the existing connection to the caller-selected CDP endpoint. ## Evidence and regression coverage Boundary tests cover stable recovery, CSS/device-pixel units, scrollbar preservation, malformed metrics, and document identity. New cases deliver scope-loss events while metrics are pending and assert that no subsequent screenshot is issued. Scroll, resize, zoom, density changes, and invalid refreshed metrics are also covered. The real Chrome regression records actual production commands and PNG responses. It asserts that the first image really is undersized and that a clipped retry occurs. Chrome restores the capture session's own metrics during recovery in this external-session fixture; the operation now correctly returns `target_changed`. The internal recovery PNG is compared pixel-for-pixel with a direct CSS-clip control. A separate stable-viewport capture must succeed with matching dimensions and pixels. Both page scales (1 and 2) pass, including a separate physical-DPR-2 run at 2560×1440. The real success case does not prove stable cropped recovery; that behavior is covered by wire boundary tests. Existing large-PNG CLI/MCP parity and export checks remain intact. - [x] Observed, derived, and inferred claims remain distinguishable. - [x] Artifact identity, source provenance, and failed attempts remain preserved. - [x] Unsupported, incomplete, unavailable, or uncertain outcomes remain visible. ## Validation performed - Five focused screenshot, browser lifecycle/document, CLI, and MCP files: 98 tests passed, including 38 screenshot tests. - `npm run check`: passed. - `npm run verify:browser`: passed on Windows Chrome 155.0.8059.85, including large-PNG CLI/MCP/export checks and the strengthened viewport regression. Whole-verifier Windows process lineage is unavailable; provider-owned cleanup is checked separately. - Separate physical-DPR-2 production-boundary run: both page scales passed. - An independent agent with no inherited conversation reviewed the production changes and final real-browser helper. It found no demonstrated actionable defect. This was source review, not an independent rerun of the suite. ## Compatibility, safety, and release No schema change or migration is required. macOS/Linux, Edge, mobile viewports, and older Chromium were not tested. Geometry sampling is not atomic: changes after a sample or changes that return to the same values can still escape detection. Rejecting a result cannot undo a capture already in flight. Normal screenshots add two metrics requests; a cropped surface needs three and at most one extra screenshot. Timing, CPU, and peak process-family memory costs were not measured. ## Author readiness Human owner: @STDquantum - [x] I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work. - [x] I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps. - [x] I declare this PR ready for initial maintainer review. ## Before merge - [ ] This PR addresses a concrete problem or an agreed enhancement. - [ ] Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff. - [ ] The PR has one focused outcome and the title follows `type(scope): outcome`. - [ ] Related issue is linked, or the reason for not linking one is stated above. - [ ] Tests cover changed observable behavior and meaningful failure paths. - [ ] Owning docs, contracts, and generated metadata are updated where needed. - [ ] User-visible CLI/MCP changes include representative output. - [ ] I checked the final diff for secrets, unrelated cleanup, and unsupported claims. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-01 21:44:37 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#7000
No description provided.