Skip to content

Commit 409558a

Browse files
committed
docs: update README with WebSocket debugging documentation
- Add WebSocket debugging features to features list - Document DebuggerOverlay component with HTTP + WebSocket support - Add WebSocket logger configuration and methods - Add WebSocketLog and WebSocketMessage type definitions - Add WebSocketLoggerConfig options table - Add troubleshooting section for WebSocket issues - Update quick setup examples with WebSocket integration
1 parent d792631 commit 409558a

1 file changed

Lines changed: 190 additions & 13 deletions

File tree

README.md

Lines changed: 190 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# React Native API Debugger
22

3-
A network request debugging tool for React Native applications. Monitor, inspect, and debug HTTP requests with a draggable overlay interface.
3+
A comprehensive network debugging tool for React Native applications. Monitor, inspect, and debug HTTP requests and WebSocket connections with a unified tabbed overlay interface.
44

55
[![npm version](https://img.shields.io/npm/v/react-native-api-debugger)](https://www.npmjs.com/package/react-native-api-debugger)
66
[![downloads](https://img.shields.io/npm/dm/react-native-api-debugger)](https://www.npmjs.com/package/react-native-api-debugger)
@@ -10,16 +10,29 @@ A network request debugging tool for React Native applications. Monitor, inspect
1010

1111
## Features
1212

13+
### HTTP Debugging
1314
- **Network Interception** - Automatically captures all `fetch()` and `XMLHttpRequest` calls
14-
- **Draggable Overlay** - Floating button that can be positioned anywhere on screen
1515
- **Request Details** - View headers, body, response, timing, and status codes
1616
- **cURL Export** - Copy requests as cURL commands
1717
- **Advanced Filtering** - Filter by status code (2xx, 3xx, 4xx, 5xx), search by URL/method/body
1818
- **Export Logs** - Export to HAR, Postman Collection, or JSON formats
1919
- **Request Replay** - Re-execute captured requests with optional modifications
20-
- **Dark/Light Theme** - Toggle between themes
2120
- **Slow Request Detection** - Visual indicator for requests exceeding threshold
2221
- **Sensitive Data Redaction** - Detect and mask sensitive headers and body fields
22+
23+
### WebSocket Debugging
24+
- **WebSocket Interception** - Automatically captures all WebSocket connections
25+
- **Connection Monitoring** - Track connection state (connecting, open, closing, closed)
26+
- **Message Logging** - View sent and received messages with timestamps
27+
- **Message Filtering** - Filter by direction (sent/received) or search by content
28+
- **Binary Support** - Handles text and binary message types
29+
- **Connection Metrics** - Track message counts, bytes transferred, and connection duration
30+
- **Live Indicators** - Visual indicators for active connections
31+
32+
### General
33+
- **Unified Interface** - Tabbed modal with HTTP and WebSocket views
34+
- **Draggable Overlay** - Floating button that can be positioned anywhere on screen
35+
- **Dark/Light Theme** - Toggle between themes
2336
- **Individual Log Deletion** - Remove specific entries without clearing all logs
2437
- **Device Shake Support** - Shake to show/hide the debugger
2538
- **TypeScript Support** - Full type definitions included
@@ -67,7 +80,7 @@ npm install react-native-svg
6780

6881
## Quick Setup
6982

70-
### 1. Basic Usage (No Dependencies)
83+
### 1. Basic Usage (HTTP Only)
7184

7285
```tsx
7386
import React, { useEffect } from 'react';
@@ -94,43 +107,86 @@ export default function App() {
94107
}
95108
```
96109

97-
### 2. With Draggable Button
110+
### 2. Full Setup (HTTP + WebSocket)
111+
112+
Use `DebuggerOverlay` for the unified tabbed interface with both HTTP and WebSocket support.
113+
114+
```tsx
115+
import React, { useEffect } from 'react';
116+
import { View } from 'react-native';
117+
import {
118+
networkLogger,
119+
webSocketLogger,
120+
DebuggerOverlay
121+
} from 'react-native-api-debugger';
122+
123+
export default function App() {
124+
useEffect(() => {
125+
// Setup HTTP interceptor
126+
networkLogger.setupInterceptor();
127+
128+
// Setup WebSocket interceptor
129+
webSocketLogger.setupInterceptor();
130+
}, []);
131+
132+
return (
133+
<View style={{ flex: 1 }}>
134+
{/* Your app content */}
135+
136+
<DebuggerOverlay
137+
networkLogger={networkLogger}
138+
webSocketLogger={webSocketLogger}
139+
draggable={false}
140+
/>
141+
</View>
142+
);
143+
}
144+
```
145+
146+
### 3. With Draggable Button
98147

99148
Requires `react-native-gesture-handler` and `react-native-reanimated`.
100149

101150
```tsx
102151
import { GestureHandlerRootView } from 'react-native-gesture-handler';
103-
import { networkLogger, NetworkLoggerOverlay } from 'react-native-api-debugger';
152+
import {
153+
networkLogger,
154+
webSocketLogger,
155+
DebuggerOverlay
156+
} from 'react-native-api-debugger';
104157

105158
export default function App() {
106159
useEffect(() => {
107160
networkLogger.setupInterceptor();
161+
webSocketLogger.setupInterceptor();
108162
}, []);
109163

110164
return (
111165
<GestureHandlerRootView style={{ flex: 1 }}>
112166
{/* Your app content */}
113167

114-
<NetworkLoggerOverlay
168+
<DebuggerOverlay
115169
networkLogger={networkLogger}
170+
webSocketLogger={webSocketLogger}
116171
draggable={true}
117172
/>
118173
</GestureHandlerRootView>
119174
);
120175
}
121176
```
122177

123-
### 3. Full Featured Setup
178+
### 4. Full Featured Setup
124179

125180
```tsx
126-
<NetworkLoggerOverlay
181+
<DebuggerOverlay
127182
networkLogger={networkLogger}
183+
webSocketLogger={webSocketLogger}
128184
draggable={true}
129185
enableDeviceShake={true}
130186
useCopyToClipboard={true}
131187
showRequestHeader={true}
132188
showResponseHeader={true}
133-
theme="light"
189+
theme="dark"
134190
onThemeChange={(theme) => console.log('Theme:', theme)}
135191
/>
136192
```
@@ -197,11 +253,18 @@ const config = networkLogger.getConfig();
197253

198254
```tsx
199255
useEffect(() => {
200-
const unsubscribe = networkLogger.subscribe((logs) => {
201-
console.log('Logs updated:', logs.length);
256+
const unsubscribeHttp = networkLogger.subscribe((logs) => {
257+
console.log('HTTP logs updated:', logs.length);
258+
});
259+
260+
const unsubscribeWs = webSocketLogger.subscribe((logs) => {
261+
console.log('WebSocket logs updated:', logs.length);
202262
});
203263

204-
return () => unsubscribe();
264+
return () => {
265+
unsubscribeHttp();
266+
unsubscribeWs();
267+
};
205268
}, []);
206269
```
207270

@@ -273,12 +336,73 @@ const curlCommand = generateCurl(log);
273336
// curl -X POST 'https://api.example.com/users' -H 'Content-Type: application/json' -d '{"name":"John"}'
274337
```
275338

339+
### WebSocket Logger Methods
340+
341+
```tsx
342+
import { webSocketLogger } from 'react-native-api-debugger';
343+
344+
// Initialize interception
345+
webSocketLogger.setupInterceptor();
346+
347+
// Configure options
348+
webSocketLogger.configure({
349+
maxConnections: 50, // Maximum connections to store
350+
captureMessages: true, // Log individual messages
351+
maxMessagesPerConnection: 100, // Max messages per connection
352+
ignoredUrls: ['*/health'], // URL patterns to ignore
353+
});
354+
355+
// Get all logs
356+
const logs = webSocketLogger.getLogs();
357+
358+
// Get log count
359+
const count = webSocketLogger.getLogCount();
360+
361+
// Clear all logs
362+
webSocketLogger.clearLogs();
363+
364+
// Delete a specific log
365+
webSocketLogger.deleteLog(logId);
366+
367+
// Close an active connection
368+
webSocketLogger.closeConnection(logId);
369+
370+
// Enable/disable logging
371+
webSocketLogger.enable();
372+
webSocketLogger.disable();
373+
374+
// Get active connections count
375+
const activeCount = webSocketLogger.getActiveConnectionsCount();
376+
377+
// Restore original WebSocket (remove interception)
378+
webSocketLogger.restoreInterceptor();
379+
```
380+
276381
---
277382

278383
## API Reference
279384

385+
### DebuggerOverlay Props
386+
387+
The unified overlay component with HTTP and WebSocket tabs.
388+
389+
| Prop | Type | Default | Description |
390+
|------|------|---------|-------------|
391+
| `networkLogger` | `NetworkLogger` | Required | HTTP logger instance |
392+
| `webSocketLogger` | `WebSocketLogger` | Optional | WebSocket logger instance |
393+
| `enabled` | `boolean` | `__DEV__` | Enable/disable the overlay |
394+
| `draggable` | `boolean` | `false` | Enable draggable button |
395+
| `enableDeviceShake` | `boolean` | `false` | Show on device shake |
396+
| `useCopyToClipboard` | `boolean` | `false` | Enable clipboard copy |
397+
| `showRequestHeader` | `boolean` | `false` | Show request headers |
398+
| `showResponseHeader` | `boolean` | `false` | Show response headers |
399+
| `theme` | `'light' \| 'dark'` | `'dark'` | Color theme |
400+
| `onThemeChange` | `(theme) => void` | - | Theme change callback |
401+
280402
### NetworkLoggerOverlay Props
281403

404+
HTTP-only overlay component (legacy, use `DebuggerOverlay` for new projects).
405+
282406
| Prop | Type | Default | Description |
283407
|------|------|---------|-------------|
284408
| `networkLogger` | `NetworkLogger` | Required | The logger instance |
@@ -328,6 +452,46 @@ interface NetworkLog {
328452
}
329453
```
330454

455+
### WebSocketLog Type
456+
457+
```typescript
458+
interface WebSocketLog {
459+
id: number;
460+
url: string;
461+
state: 'connecting' | 'open' | 'closing' | 'closed';
462+
protocols?: string[];
463+
connectTime: string;
464+
openTime?: string;
465+
closeTime?: string;
466+
closeCode?: number;
467+
closeReason?: string;
468+
error?: string;
469+
handshakeDuration?: number;
470+
messages: WebSocketMessage[];
471+
messageCount: { sent: number; received: number };
472+
bytesReceived: number;
473+
bytesSent: number;
474+
}
475+
476+
interface WebSocketMessage {
477+
id: number;
478+
direction: 'sent' | 'received';
479+
data: string;
480+
dataType: 'text' | 'binary';
481+
timestamp: string;
482+
size: number;
483+
}
484+
```
485+
486+
### WebSocketLoggerConfig
487+
488+
| Option | Type | Default | Description |
489+
|--------|------|---------|-------------|
490+
| `maxConnections` | `number` | `100` | Maximum connections to store |
491+
| `captureMessages` | `boolean` | `true` | Log individual messages |
492+
| `maxMessagesPerConnection` | `number` | `100` | Max messages per connection |
493+
| `ignoredUrls` | `string[]` | `[]` | URL patterns to ignore |
494+
331495
---
332496

333497
## Production Safety
@@ -383,9 +547,22 @@ Make sure `setupInterceptor()` is called before any network requests:
383547
```tsx
384548
useEffect(() => {
385549
networkLogger.setupInterceptor();
550+
webSocketLogger.setupInterceptor();
386551
}, []); // Empty dependency array - runs once on mount
387552
```
388553

554+
### WebSocket connections not appearing
555+
556+
Ensure the WebSocket interceptor is set up before any WebSocket connections are created, and pass the `webSocketLogger` to `DebuggerOverlay`:
557+
558+
```tsx
559+
<DebuggerOverlay
560+
networkLogger={networkLogger}
561+
webSocketLogger={webSocketLogger} // Don't forget this!
562+
draggable={true}
563+
/>
564+
```
565+
389566
---
390567

391568
## Contributing

0 commit comments

Comments
 (0)