3 days ago
It's been about 3 months since I joined Wrtn as a React Native developer, and I've successfully completed my probationary period. Although it was technically a probationary period, it felt nothing like one since I had to single-handedly develop a new Japanese market app called Kyarapu within 2 months. Fortunately, the web and backend developers were also experienced new hires, so we quickly bonded through shared challenges and built strong trust relationships while assessing each other's capabilities.
Now that the project is completed and we're in the service stabilization phase handling operational tasks, the network debugging issues that were constantly frustrating during development remain unresolved. Since there's no viable solution across our company's entire app chapter, I decided to create a new React Native network debugger for common use within the company.
The legacy Flipper debugger has been deprecated and React Native DevTools has been adopted as the official debugger, but one of the most crucial features - network debugging - was missing.
We propose implementing a network panel in React Native DevTools using Chrome DevTools Protocol (CDP). This approach collects network data through Inspector Proxy and forwards it to DevTools via CDP events.
React Native DevTools operates based on Chrome DevTools Protocol (CDP). To implement a network panel, we need to utilize CDP's Network domain to collect network events and forward them to DevTools.
CDP is the protocol used by Chrome DevTools to communicate with browsers. It exchanges JSON-RPC 2.0 messages over WebSocket connections and is organized into various domains (Network, Runtime, Debugger, etc.).
Methods (DevTools → Runtime)
Network.enable
: Start tracking network eventsNetwork.getResponseBody
: Get Response Body for a specific RequestEvents (Runtime → DevTools)
Network.requestWillBeSent
: Fired when a network request is about to be sentNetwork.responseReceived
: Fired when HTTP response headers are receivedNetwork.loadingFinished
: Fired when a request completes successfullyNetwork.loadingFailed
: Fired when a request fails// DevTools to Runtime (Method Call)
{
"id": 1,
"method": "Network.enable",
"params": {}
}
// Runtime to DevTools (Event)
{
"method": "Network.requestWillBeSent",
"params": {
"requestId": "1234.1",
"loaderId": "1234.1",
"documentURL": "https://example.com",
"request": {
"url": "https://api.example.com/users",
"method": "GET",
"headers": {
"Accept": "application/json"
}
},
"timestamp": 1736686200.123456,
"wallTime": 1736686200.123456
}
}
React Native's Inspector Proxy is a core module provided by the @react-native/dev-middleware
package. It runs alongside the Metro server and acts as a mediator for communication between DevTools and devices.
DevTools (Chrome)
↕ (debuggerSocket)
Inspector Proxy (Metro Server)
↕ (deviceSocket)
React Native App (Device/Simulator)
Directly utilizing the existing Inspector Proxy's debuggerSocket and deviceSocket has several limitations. To solve stability issues in multi-connection environments, we added a separate WebSocket within the Inspector Proxy.
DevTools (Chrome)
↕ (debuggerSocket)
Inspector Proxy (Metro Server)
↕ (wrtnDebuggerSocket)
Native Network Interceptor (Custom Native below)
Since I heavily referenced Toss's approach for the native interceptor structure, I recommend referring to Toss's implementation for the native interceptor details.
The React Native team is officially developing a DevTools Network panel. Meta developer Huntie is leading the effort, and significant progress is being made.
The main reasons for the delayed development of the official Network panel are related to React Native's network architecture changes.
URLSession
, Android uses OkHttp3
Starting from React Native v0.80.0, network processing has been unified into the C++ layer.
The absence of a Network panel in React Native DevTools is a common problem faced by many developers. To solve this issue, we can implement a custom network debugger using Chrome DevTools Protocol, with the key implementation points as follows:
When Meta's official Network panel is completed, it's expected to provide a better debugging experience. However, custom implementation is currently the only alternative, and it provided an opportunity to gain deeper understanding of DevTools operation and internal structure in React Native.