Skip to content

Add Page.captureScreenshot CDP support#56307

Open
huntie wants to merge 1 commit intofacebook:mainfrom
huntie:export-D99099930
Open

Add Page.captureScreenshot CDP support#56307
huntie wants to merge 1 commit intofacebook:mainfrom
huntie:export-D99099930

Conversation

@huntie
Copy link
Copy Markdown
Member

@huntie huntie commented Apr 1, 2026

Summary:
Implement the Page.captureScreenshot CDP command in the inspector backend, allowing DevTools to capture an on-demand screenshot of the current app view. This is a minimal implementation supporting only the format (jpeg/png/webp) and quality (0-100, jpeg only) parameters, returning base64-encoded image data.

The feature is gated behind a new fuseboxCaptureScreenshotEnabled React Native feature flag, wired through InspectorFlags following the same pattern as frame recording.

Motivation

Improve agent verification / user feedback during AI sessions. We've proven that screenshots (in performance traces) are useful for understanding how components render on screen, and exposing this as an on-demand CDP method is relatively cheap today vs the larger task of modelling the DOM (Elements panel).

Changes

  • New fuseboxCaptureScreenshotEnabled feature flag + InspectorFlags wiring (C++, Android JNI, Kotlin)
  • HostTargetDelegate::captureScreenshot() virtual method with async callback
  • C++ CDP handler in HostAgent — parses format/quality, delegates to platform, sends async CDP response (gated by flag)
  • iOS (RCTHost.mm): Captures key window via UIGraphicsImageRenderer + drawViewHierarchyInRect, encodes to PNG/JPEG
  • Android (ReactHostImpl.kt): Captures decor view via Bitmap + Canvas + View.draw(), encodes to PNG/JPEG/WebP
  • 4 C++ tests: success, failure, param forwarding, flag-disabled rejection

Changelog: [Internal]

Differential Revision: D99099930

Summary:
Implement the `Page.captureScreenshot` CDP command in the inspector backend, allowing DevTools to capture an on-demand screenshot of the current app view. This is a minimal implementation supporting only the `format` (jpeg/png/webp) and `quality` (0-100, jpeg only) parameters, returning base64-encoded image data.

The feature is gated behind a new `fuseboxCaptureScreenshotEnabled` React Native feature flag, wired through `InspectorFlags` following the same pattern as frame recording.

**Motivation**

Improve agent verification / user feedback during AI sessions. We've proven that screenshots (in performance traces) are useful for understanding how components render on screen, and exposing this as an on-demand CDP method is relatively cheap today vs the larger task of modelling the DOM (Elements panel).

**Changes**

- New `fuseboxCaptureScreenshotEnabled` feature flag + `InspectorFlags` wiring (C++, Android JNI, Kotlin)
- `HostTargetDelegate::captureScreenshot()` virtual method with async callback
- C++ CDP handler in `HostAgent` — parses `format`/`quality`, delegates to platform, sends async CDP response (gated by flag)
- iOS (`RCTHost.mm`): Captures key window via `UIGraphicsImageRenderer` + `drawViewHierarchyInRect`, encodes to PNG/JPEG
- Android (`ReactHostImpl.kt`): Captures decor view via `Bitmap` + `Canvas` + `View.draw()`, encodes to PNG/JPEG/WebP
- 4 C++ tests: success, failure, param forwarding, flag-disabled rejection

Changelog: [Internal]

Differential Revision: D99099930
@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 1, 2026
@facebook-github-tools facebook-github-tools bot added p: Facebook Partner: Facebook Partner labels Apr 1, 2026
@meta-codesync
Copy link
Copy Markdown

meta-codesync bot commented Apr 1, 2026

@huntie has exported this pull request. If you are a Meta employee, you can view the originating Diff in D99099930.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant