@rozenite/network-activity-plugin 1.0.0-alpha.8 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/App.html +2 -2
- package/dist/assets/{App-R2ZMH9wJ.css → App-BrSkOkws.css} +269 -2
- package/dist/assets/{App-lNMijPJ4.js → App-C6wCDVkW.js} +17485 -10814
- package/dist/event-source.cjs +22 -0
- package/dist/event-source.js +23 -0
- package/dist/react-native.cjs +4 -1
- package/dist/react-native.js +4 -1
- package/dist/rozenite.json +1 -1
- package/dist/src/react-native/config.d.ts +20 -0
- package/dist/src/react-native/{network-inspector.d.ts → http/network-inspector.d.ts} +1 -1
- package/dist/src/react-native/http/overrides-registry.d.ts +6 -0
- package/dist/src/react-native/{xhr-interceptor.d.ts → http/xhr-interceptor.d.ts} +7 -1
- package/dist/src/react-native/sse/event-source.d.ts +2 -0
- package/dist/src/react-native/sse/sse-inspector.d.ts +9 -0
- package/dist/src/react-native/sse/sse-interceptor.d.ts +36 -0
- package/dist/src/react-native/sse/types.d.ts +6 -0
- package/dist/src/react-native/useNetworkActivityDevTools.d.ts +2 -1
- package/dist/src/react-native/utils/getBlobName.d.ts +35 -0
- package/dist/src/react-native/utils/getFormDataEntries.d.ts +18 -0
- package/dist/src/react-native/utils.d.ts +6 -0
- package/dist/src/react-native/websocket/websocket-inspector.d.ts +9 -0
- package/dist/src/react-native/websocket/websocket-interceptor.d.ts +74 -0
- package/dist/src/shared/client.d.ts +53 -6
- package/dist/src/shared/sse-events.d.ts +38 -0
- package/dist/src/shared/websocket-events.d.ts +60 -0
- package/dist/src/ui/components/Badge.d.ts +1 -1
- package/dist/src/ui/components/Button.d.ts +2 -2
- package/dist/src/ui/components/CodeBlock.d.ts +3 -0
- package/dist/src/ui/components/CodeEditor.d.ts +5 -0
- package/dist/src/ui/components/CookieCard.d.ts +7 -0
- package/dist/src/ui/components/CopyRequestDropdown.d.ts +7 -0
- package/dist/src/ui/components/DropdownMenu.d.ts +27 -0
- package/dist/src/ui/components/FilterBar.d.ts +10 -0
- package/dist/src/ui/components/JsonTreeCopyableItem.d.ts +7 -0
- package/dist/src/ui/components/KeyValueGrid.d.ts +13 -0
- package/dist/src/ui/components/OverrideResponse.d.ts +8 -0
- package/dist/src/ui/components/RequestBody.d.ts +6 -0
- package/dist/src/ui/components/RequestList.d.ts +13 -28
- package/dist/src/ui/components/ScrollArea.d.ts +3 -2
- package/dist/src/ui/components/Section.d.ts +8 -0
- package/dist/src/ui/components/Separator.d.ts +2 -1
- package/dist/src/ui/components/SidePanel.d.ts +1 -0
- package/dist/src/ui/components/Tabs.d.ts +7 -0
- package/dist/src/ui/components/Toolbar.d.ts +1 -0
- package/dist/src/ui/hooks/useCopyToClipboard.d.ts +4 -0
- package/dist/src/ui/state/derived.d.ts +5 -0
- package/dist/src/ui/state/hooks.d.ts +21 -0
- package/dist/src/ui/state/model.d.ts +103 -0
- package/dist/src/ui/state/store.d.ts +48 -0
- package/dist/src/ui/tabs/CookiesTab.d.ts +3 -6
- package/dist/src/ui/tabs/HeadersTab.d.ts +3 -15
- package/dist/src/ui/tabs/MessagesTab.d.ts +5 -0
- package/dist/src/ui/tabs/RequestTab.d.ts +2 -7
- package/dist/src/ui/tabs/ResponseTab.d.ts +2 -8
- package/dist/src/ui/tabs/SSEMessagesTab.d.ts +5 -0
- package/dist/src/ui/tabs/TimingTab.d.ts +3 -5
- package/dist/src/ui/types.d.ts +4 -1
- package/dist/src/ui/utils/assert.d.ts +1 -0
- package/dist/src/ui/utils/checkRequestBodyBinary.d.ts +2 -0
- package/dist/src/ui/utils/copyToClipboard.d.ts +1 -0
- package/dist/src/ui/utils/escapeShellArg.d.ts +1 -0
- package/dist/src/ui/utils/generateCurlCommand.d.ts +2 -0
- package/dist/src/ui/utils/generateFetchCall.d.ts +2 -0
- package/dist/src/ui/utils/generateMultipartBody.d.ts +4 -0
- package/dist/src/ui/utils/getId.d.ts +1 -0
- package/dist/src/ui/utils/getStatusColor.d.ts +1 -0
- package/dist/src/utils/applyReactNativeRequestHeadersLogic.d.ts +7 -0
- package/dist/src/utils/applyReactNativeResponseHeadersLogic.d.ts +9 -0
- package/dist/src/utils/cookieParser.d.ts +6 -0
- package/dist/src/utils/getContentTypeMimeType.d.ts +2 -0
- package/dist/src/utils/getHttpHeader.d.ts +5 -0
- package/dist/src/utils/getHttpHeaderValueAsString.d.ts +11 -0
- package/dist/src/utils/getStringSizeInBytes.d.ts +1 -0
- package/dist/src/utils/inferContentTypeFromPostData.d.ts +2 -0
- package/dist/src/utils/safeStringify.d.ts +1 -0
- package/dist/src/utils/typeChecks.d.ts +9 -0
- package/dist/useNetworkActivityDevTools.cjs +724 -40
- package/dist/useNetworkActivityDevTools.js +723 -41
- package/package.json +22 -8
- package/react-native.ts +6 -1
- package/src/react-native/config.ts +43 -0
- package/src/react-native/http/network-inspector.ts +388 -0
- package/src/react-native/http/overrides-registry.ts +32 -0
- package/src/react-native/{xhr-interceptor.ts → http/xhr-interceptor.ts} +19 -2
- package/src/react-native/{xml-request.d.ts → http/xml-request.d.ts} +1 -0
- package/src/react-native/sse/event-source.ts +25 -0
- package/src/react-native/sse/sse-inspector.ts +139 -0
- package/src/react-native/sse/sse-interceptor.ts +180 -0
- package/src/react-native/sse/types.ts +9 -0
- package/src/react-native/useNetworkActivityDevTools.ts +156 -4
- package/src/react-native/utils/getBlobName.ts +45 -0
- package/src/react-native/utils/getFormDataEntries.ts +32 -0
- package/src/react-native/utils.ts +43 -0
- package/src/react-native/websocket/websocket-inspector.ts +180 -0
- package/src/react-native/websocket/websocket-interceptor.d.ts +4 -0
- package/src/react-native/websocket/websocket-interceptor.ts +166 -0
- package/src/shared/client.ts +79 -6
- package/src/shared/sse-events.ts +47 -0
- package/src/shared/websocket-events.ts +79 -0
- package/src/ui/components/Button.tsx +1 -0
- package/src/ui/components/CodeBlock.tsx +19 -0
- package/src/ui/components/CodeEditor.tsx +26 -0
- package/src/ui/components/CookieCard.tsx +64 -0
- package/src/ui/components/CopyRequestDropdown.tsx +95 -0
- package/src/ui/components/DropdownMenu.tsx +206 -0
- package/src/ui/components/FilterBar.tsx +117 -0
- package/src/ui/components/Input.tsx +1 -1
- package/src/ui/components/JsonTree.tsx +20 -0
- package/src/ui/components/JsonTreeCopyableItem.tsx +37 -0
- package/src/ui/components/KeyValueGrid.tsx +51 -0
- package/src/ui/components/OverrideResponse.tsx +132 -0
- package/src/ui/components/RequestBody.tsx +86 -0
- package/src/ui/components/RequestList.tsx +101 -131
- package/src/ui/components/ScrollArea.tsx +1 -0
- package/src/ui/components/Section.tsx +46 -0
- package/src/ui/components/SidePanel.tsx +333 -0
- package/src/ui/components/Tabs.tsx +1 -1
- package/src/ui/components/Toolbar.tsx +45 -0
- package/src/ui/globals.css +4 -0
- package/src/ui/hooks/useCopyToClipboard.ts +28 -0
- package/src/ui/state/derived.ts +112 -0
- package/src/ui/state/hooks.ts +52 -0
- package/src/ui/state/model.ts +140 -0
- package/src/ui/state/store.ts +669 -0
- package/src/ui/tabs/CookiesTab.tsx +61 -278
- package/src/ui/tabs/HeadersTab.tsx +85 -103
- package/src/ui/tabs/MessagesTab.tsx +276 -0
- package/src/ui/tabs/RequestTab.tsx +58 -51
- package/src/ui/tabs/ResponseTab.tsx +101 -74
- package/src/ui/tabs/SSEMessagesTab.tsx +224 -0
- package/src/ui/tabs/TimingTab.tsx +30 -43
- package/src/ui/types.ts +4 -1
- package/src/ui/utils/assert.ts +5 -0
- package/src/ui/utils/checkRequestBodyBinary.ts +7 -0
- package/src/ui/utils/copyToClipboard.ts +3 -0
- package/src/ui/utils/escapeShellArg.ts +12 -0
- package/src/ui/utils/generateCurlCommand.ts +83 -0
- package/src/ui/utils/generateFetchCall.ts +64 -0
- package/src/ui/utils/generateMultipartBody.ts +19 -0
- package/src/ui/utils/getId.ts +10 -0
- package/src/ui/utils/getStatusColor.ts +15 -0
- package/src/ui/views/InspectorView.tsx +35 -319
- package/src/utils/applyReactNativeRequestHeadersLogic.ts +30 -0
- package/src/utils/applyReactNativeResponseHeadersLogic.ts +28 -0
- package/src/utils/cookieParser.ts +126 -0
- package/src/utils/getContentTypeMimeType.ts +17 -0
- package/src/utils/getHttpHeader.ts +17 -0
- package/src/utils/getHttpHeaderValueAsString.ts +13 -0
- package/src/utils/getStringSizeInBytes.ts +3 -0
- package/src/utils/inferContentTypeFromPostData.ts +9 -0
- package/src/utils/safeStringify.ts +7 -0
- package/src/utils/typeChecks.ts +27 -0
- package/tailwind.config.ts +3 -0
- package/vite.config.ts +12 -0
- package/dist/src/ui/utils/getHttpHeaderValue.d.ts +0 -2
- package/src/react-native/network-inspector.ts +0 -247
- package/src/ui/utils/getHttpHeaderValue.ts +0 -14
- /package/dist/src/react-native/{network-requests-registry.d.ts → http/network-requests-registry.d.ts} +0 -0
- /package/src/react-native/{network-requests-registry.ts → http/network-requests-registry.ts} +0 -0
package/vite.config.ts
CHANGED
|
@@ -12,6 +12,18 @@ export default defineConfig({
|
|
|
12
12
|
reportCompressedSize: false,
|
|
13
13
|
minify: false,
|
|
14
14
|
sourcemap: false,
|
|
15
|
+
rollupOptions: {
|
|
16
|
+
output: {
|
|
17
|
+
manualChunks: (id) => {
|
|
18
|
+
// Mitigate https://github.com/facebook/metro/issues/836
|
|
19
|
+
if (id.includes('event-source.ts')) {
|
|
20
|
+
return 'event-source';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return undefined;
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
},
|
|
15
27
|
},
|
|
16
28
|
server: {
|
|
17
29
|
port: 3000,
|
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
import { NetworkActivityDevToolsClient } from '../shared/client';
|
|
2
|
-
import { getHttpHeaderValue } from '../ui/utils/getHttpHeaderValue';
|
|
3
|
-
import { getNetworkRequestsRegistry } from './network-requests-registry';
|
|
4
|
-
import { XHRInterceptor } from './xhr-interceptor';
|
|
5
|
-
|
|
6
|
-
const networkRequestsRegistry = getNetworkRequestsRegistry();
|
|
7
|
-
|
|
8
|
-
const getContentType = (request: XMLHttpRequest): string => {
|
|
9
|
-
const responseHeaders = request.responseHeaders;
|
|
10
|
-
const responseType = request.responseType;
|
|
11
|
-
|
|
12
|
-
const contentType = getHttpHeaderValue(responseHeaders || {}, 'content-type');
|
|
13
|
-
|
|
14
|
-
if (contentType) {
|
|
15
|
-
return contentType.split(';')[0].trim();
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
switch (responseType) {
|
|
19
|
-
case 'arraybuffer':
|
|
20
|
-
case 'blob':
|
|
21
|
-
return 'application/octet-stream';
|
|
22
|
-
case 'text':
|
|
23
|
-
case '':
|
|
24
|
-
return 'text/plain';
|
|
25
|
-
case 'json':
|
|
26
|
-
return 'application/json';
|
|
27
|
-
case 'document':
|
|
28
|
-
return 'text/html';
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const getResponseSize = (request: XMLHttpRequest): number => {
|
|
33
|
-
if (typeof request.response === 'object') {
|
|
34
|
-
return request.response.size;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return request.response.length || 0;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const getResponseBody = async (
|
|
41
|
-
request: XMLHttpRequest
|
|
42
|
-
): Promise<string | null> => {
|
|
43
|
-
const responseType = request.responseType;
|
|
44
|
-
|
|
45
|
-
if (responseType === 'text') {
|
|
46
|
-
return request.responseText as string;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (responseType === 'blob') {
|
|
50
|
-
// This may be a text blob.
|
|
51
|
-
const contentType = request.getResponseHeader('Content-Type') || '';
|
|
52
|
-
|
|
53
|
-
if (
|
|
54
|
-
contentType.startsWith('text/') ||
|
|
55
|
-
contentType.startsWith('application/json')
|
|
56
|
-
) {
|
|
57
|
-
// It looks like a text blob, let's read it and forward it to the client.
|
|
58
|
-
return new Promise((resolve) => {
|
|
59
|
-
const reader = new FileReader();
|
|
60
|
-
reader.onload = () => {
|
|
61
|
-
resolve(reader.result as string);
|
|
62
|
-
};
|
|
63
|
-
reader.readAsText(request.response);
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return null;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const getInitiatorFromStack = (): {
|
|
72
|
-
type: string;
|
|
73
|
-
url?: string;
|
|
74
|
-
lineNumber?: number;
|
|
75
|
-
columnNumber?: number;
|
|
76
|
-
} => {
|
|
77
|
-
try {
|
|
78
|
-
const stack = new Error().stack;
|
|
79
|
-
if (!stack) {
|
|
80
|
-
return { type: 'other' };
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const line = stack.split('\n')[9];
|
|
84
|
-
const match = line.match(/at\s+(.+?)\s+\((.+?):(\d+):(\d+)\)/);
|
|
85
|
-
if (match) {
|
|
86
|
-
return {
|
|
87
|
-
type: 'script',
|
|
88
|
-
url: match[2],
|
|
89
|
-
lineNumber: parseInt(match[3]),
|
|
90
|
-
columnNumber: parseInt(match[4]),
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
} catch {
|
|
94
|
-
// Ignore stack parsing errors
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return { type: 'other' };
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
export type NetworkInspector = {
|
|
101
|
-
enable: () => void;
|
|
102
|
-
disable: () => void;
|
|
103
|
-
isEnabled: () => boolean;
|
|
104
|
-
dispose: () => void;
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
const READY_STATE_HEADERS_RECEIVED = 2;
|
|
108
|
-
|
|
109
|
-
export const getNetworkInspector = (
|
|
110
|
-
pluginClient: NetworkActivityDevToolsClient
|
|
111
|
-
): NetworkInspector => {
|
|
112
|
-
const generateRequestId = (): string => {
|
|
113
|
-
return `req_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
const handleRequestSend = (data: string, request: XMLHttpRequest): void => {
|
|
117
|
-
const sendTime = Date.now();
|
|
118
|
-
|
|
119
|
-
const requestId = generateRequestId();
|
|
120
|
-
const initiator = getInitiatorFromStack();
|
|
121
|
-
|
|
122
|
-
networkRequestsRegistry.addEntry(requestId, request);
|
|
123
|
-
|
|
124
|
-
let ttfb = 0;
|
|
125
|
-
|
|
126
|
-
pluginClient.send('request-sent', {
|
|
127
|
-
requestId: requestId,
|
|
128
|
-
timestamp: sendTime / 1000,
|
|
129
|
-
request: {
|
|
130
|
-
url: request._url as string,
|
|
131
|
-
method: request._method as string,
|
|
132
|
-
headers: request._headers,
|
|
133
|
-
postData: data,
|
|
134
|
-
},
|
|
135
|
-
type: 'XHR',
|
|
136
|
-
initiator,
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
request.addEventListener('readystatechange', () => {
|
|
140
|
-
if (request.readyState === READY_STATE_HEADERS_RECEIVED) {
|
|
141
|
-
ttfb = Date.now() - sendTime;
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
request.addEventListener('load', () => {
|
|
146
|
-
pluginClient.send('response-received', {
|
|
147
|
-
requestId: requestId,
|
|
148
|
-
timestamp: Date.now() / 1000,
|
|
149
|
-
type: 'XHR',
|
|
150
|
-
response: {
|
|
151
|
-
url: request._url as string,
|
|
152
|
-
status: request.status,
|
|
153
|
-
statusText: request.statusText,
|
|
154
|
-
headers: request.responseHeaders || {},
|
|
155
|
-
contentType: getContentType(request),
|
|
156
|
-
size: getResponseSize(request),
|
|
157
|
-
responseTime: Date.now() / 1000,
|
|
158
|
-
},
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
request.addEventListener('loadend', () => {
|
|
163
|
-
pluginClient.send('request-completed', {
|
|
164
|
-
requestId: requestId,
|
|
165
|
-
timestamp: Date.now() / 1000,
|
|
166
|
-
duration: Date.now() - sendTime,
|
|
167
|
-
size: getResponseSize(request),
|
|
168
|
-
ttfb,
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
request.addEventListener('error', () => {
|
|
173
|
-
pluginClient.send('request-failed', {
|
|
174
|
-
requestId: requestId,
|
|
175
|
-
timestamp: Date.now() / 1000,
|
|
176
|
-
type: 'XHR',
|
|
177
|
-
error: 'Failed',
|
|
178
|
-
canceled: false,
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
request.addEventListener('abort', () => {
|
|
183
|
-
pluginClient.send('request-failed', {
|
|
184
|
-
requestId: requestId,
|
|
185
|
-
timestamp: Date.now() / 1000,
|
|
186
|
-
type: 'XHR',
|
|
187
|
-
error: 'Aborted',
|
|
188
|
-
canceled: true,
|
|
189
|
-
});
|
|
190
|
-
});
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
const enable = () => {
|
|
194
|
-
XHRInterceptor.disableInterception();
|
|
195
|
-
XHRInterceptor.setSendCallback(handleRequestSend);
|
|
196
|
-
XHRInterceptor.enableInterception();
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
const disable = () => {
|
|
200
|
-
XHRInterceptor.disableInterception();
|
|
201
|
-
networkRequestsRegistry.clear();
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
const isEnabled = () => {
|
|
205
|
-
return XHRInterceptor.isInterceptorEnabled();
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
const enableSubscription = pluginClient.onMessage('network-enable', () => {
|
|
209
|
-
enable();
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
const disableSubscription = pluginClient.onMessage('network-disable', () => {
|
|
213
|
-
disable();
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
const handleBodySubscription = pluginClient.onMessage(
|
|
217
|
-
'get-response-body',
|
|
218
|
-
async ({ requestId }) => {
|
|
219
|
-
const request = networkRequestsRegistry.getEntry(requestId);
|
|
220
|
-
|
|
221
|
-
if (!request) {
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
const body = await getResponseBody(request);
|
|
226
|
-
|
|
227
|
-
pluginClient.send('response-body', {
|
|
228
|
-
requestId,
|
|
229
|
-
body,
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
);
|
|
233
|
-
|
|
234
|
-
const dispose = () => {
|
|
235
|
-
disable();
|
|
236
|
-
enableSubscription.remove();
|
|
237
|
-
disableSubscription.remove();
|
|
238
|
-
handleBodySubscription.remove();
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
return {
|
|
242
|
-
enable,
|
|
243
|
-
disable,
|
|
244
|
-
isEnabled,
|
|
245
|
-
dispose,
|
|
246
|
-
};
|
|
247
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { HttpHeaders } from "../../shared/client";
|
|
2
|
-
|
|
3
|
-
// Utility to get header value case-insensitively
|
|
4
|
-
export function getHttpHeaderValue(headers: HttpHeaders, name: string) {
|
|
5
|
-
const lowerName = name.toLowerCase();
|
|
6
|
-
|
|
7
|
-
for (const key in headers) {
|
|
8
|
-
if (key.toLowerCase() === lowerName) {
|
|
9
|
-
return headers[key];
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
return undefined;
|
|
14
|
-
}
|
|
File without changes
|
/package/src/react-native/{network-requests-registry.ts → http/network-requests-registry.ts}
RENAMED
|
File without changes
|