Skip to content

Add CDP support for WebSocket events (Android)#57541

Open
huntie wants to merge 2 commits into
react:mainfrom
huntie:export-D111561994
Open

Add CDP support for WebSocket events (Android)#57541
huntie wants to merge 2 commits into
react:mainfrom
huntie:export-D111561994

Conversation

@huntie

@huntie huntie commented Jul 14, 2026

Copy link
Copy Markdown
Member

Summary:
Context

This stack implements WebSocket event debugging for the Network panel in React Native DevTools.

This diff

Follows the iOS implementation: reports the same six Network.webSocket* CDP events through the shared NetworkReporter C++ core, gated behind the same fuseboxWebSocketEventsEnabled feature flag.

Changes

  • InspectorNetworkReporter + JInspectorNetworkReporter: New JNI-backed reportWebSocket* methods bridging to the shared NetworkReporter C++ core. Payload conversion costs (base64) are deferred until a debugger is attached.
  • WebSocketModule: Reports connection lifecycle, real handshake headers (from the OkHttp Request/Response), and sent/received messages, gated behind the same feature flags as iOS.

Changelog: [Internal]

Differential Revision: D111561994

huntie added 2 commits July 14, 2026 02:51
Summary:
**Motivation**

React Native DevTools' Network panel records fetch, XHR, and Image traffic, but WebSocket connections are invisible — neither the core CDP backend nor any existing inspector integration implements the CDP `Network.webSocket*` events.

TODO: **Goal (as of this diff)**: Parity with Expo's current WS event coverage. Network Initiator is added down the stack.

**This diff**

Adds first-party reporting for six of the seven WebSocket CDP events (`webSocketCreated`, `webSocketWillSendHandshakeRequest`, `webSocketHandshakeResponseReceived`, `webSocketFrameSent`, `webSocketFrameReceived`, `webSocketClosed`), following the layering of the existing HTTP pipeline:

- `CdpNetwork` (jsinspector-modern/network): new WebSocket CDP types and event params with `folly::dynamic` serialization.
- `NetworkHandler`: new `onWebSocket*` emitters, active only while the Network domain is enabled.
- `NetworkReporter` (react/networking): new `reportWebSocket*` platform-facing methods, compiled to no-ops unless `REACT_NATIVE_DEBUGGER_ENABLED`.
- iOS: new `RCTInspectorWebSocketReporter` wrapper in React-CoreModules, with call sites in `RCTWebSocketModule`. Each connection gets a UUID request ID (associated object on `SRWebSocket`); the real handshake response is read from `SRWebSocket.receivedHTTPHeaders`. React-CoreModules gains a dependency on React-networking (no cycle: React-networking's transitive closure never reaches React-CoreModules).
- Reporting is gated behind a new `fuseboxWebSocketEventsEnabled` feature flag (experimentation, default false), checked alongside `enableNetworkEventReporting` and a connected debugger at the call-site wrapper.

**Notes**

`webSocketFrameError` is intentionally omitted for now. Android integration follows separately.

Changelog: [Internal]

Differential Revision: D111561998
Summary:
**Context**

This stack implements WebSocket event debugging for the Network panel in React Native DevTools.

**This diff**

Follows the iOS implementation: reports the same six `Network.webSocket*` CDP events through the shared `NetworkReporter` C++ core, gated behind the same `fuseboxWebSocketEventsEnabled` feature flag.

**Changes**

- `InspectorNetworkReporter` (Kotlin): six new JNI-backed `reportWebSocket*` methods. Binary message payloads take a `ByteString` overload that defers base64 encoding behind `isDebuggingEnabled()`, matching the existing `reportDataReceived` pattern.
- `JInspectorNetworkReporter` (JNI): bridges the new methods to `NetworkReporter::reportWebSocket*`.
- `WebSocketModule`: each connection gets a UUID CDP request ID. `connect()` reports `webSocketCreated` and the handshake request headers; `onOpen` reports the real handshake response (OkHttp `Response` code and headers); `send`/`sendBinary`/`onMessage` report frames; `onClosed`/`onFailure` report `webSocketClosed`. All call sites funnel through a private `reportToInspector` helper that checks both feature flags, per the `NetworkEventUtil` convention of gating at the call-site layer.

Changelog: [Internal]

Differential Revision: D111561994
@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 Jul 14, 2026
@meta-codesync

meta-codesync Bot commented Jul 14, 2026

Copy link
Copy Markdown

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

@huntie huntie changed the title Add WebSocket CDP network reporting (Android) Add CDP support for WebSocket events (Android) Jul 14, 2026
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. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant