Skip to content

Resolve initiator for WebSocket CDP events#57542

Closed
huntie wants to merge 3 commits into
react:mainfrom
huntie:export-D111561995
Closed

Resolve initiator for WebSocket CDP events#57542
huntie wants to merge 3 commits into
react:mainfrom
huntie:export-D111561995

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

Wire up request initiator logic for WebSocket on the JS side, completing functionality for WebSocket network debugging.

Mirrors the HTTP pipeline's unstable_devToolsRequestId plumbing.

Changes

  • Wire up unstable_devToolsRequestId plumbing through Libraries/WebSocket/WebSocket.js and NativeWebSocketModule.
  • Adds testWebSocketCreatedWithInitiator, asserting the initiator stack (function name, line number, source URL) resolves through Network.webSocketCreated.

Changelog: [Internal]

Differential Revision: D111561995

huntie added 3 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**

Companion to the iOS implementation earlier in this stack: reports the same six `Network.webSocket*` CDP events through the shared `NetworkReporter` C++ core, gated behind the same `fuseboxWebSocketEventsEnabled` + `enableNetworkEventReporting` feature flags.

**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
Summary:
**Context**

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

**This diff**

Wire up request initiator logic for `WebSocket` on the JS side, completing functionality for WebSocket network debugging.

Mirrors the HTTP pipeline's `unstable_devToolsRequestId` plumbing.

**Changes**

- Wire up `unstable_devToolsRequestId` plumbing through `Libraries/WebSocket/WebSocket.js` and `NativeWebSocketModule`.
- Adds `testWebSocketCreatedWithInitiator`, asserting the initiator stack (function name, line number, source URL) resolves through `Network.webSocketCreated`.

Changelog: [Internal]

Differential Revision: D111561995
@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 D111561995.

@meta-codesync meta-codesync Bot closed this in 1475725 Jul 15, 2026
@meta-codesync meta-codesync Bot added the Merged This PR has been merged. label Jul 15, 2026
@meta-codesync

meta-codesync Bot commented Jul 15, 2026

Copy link
Copy Markdown

This pull request has been merged in 1475725.

@huntie huntie deleted the export-D111561995 branch July 15, 2026 15:48
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. Merged This PR has been merged. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant