@rozenite/network-activity-plugin 1.0.0 → 1.2.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 +9 -0
- package/dist/App.html +1 -1
- package/dist/assets/{App-C6wCDVkW.js → App-o_iVtD-5.js} +50 -7
- package/dist/boot-recording.cjs +1092 -0
- package/dist/boot-recording.js +1091 -0
- package/dist/react-native.cjs +3 -0
- package/dist/react-native.d.ts +3 -0
- package/dist/react-native.js +5 -1
- package/dist/rozenite.json +1 -1
- package/dist/src/react-native/boot-recording.d.ts +41 -0
- package/dist/src/react-native/config.d.ts +7 -4
- package/dist/src/react-native/events-listener.d.ts +44 -0
- package/dist/src/react-native/http/http-inspector.d.ts +10 -0
- package/dist/src/react-native/http/http-utils.d.ts +15 -0
- package/dist/src/react-native/inspector.d.ts +7 -0
- package/dist/src/react-native/network-inspector.d.ts +16 -0
- package/dist/src/react-native/sse/sse-inspector.d.ts +4 -7
- package/dist/src/react-native/useHttpInspector.d.ts +3 -0
- package/dist/src/react-native/useSSEInspector.d.ts +3 -0
- package/dist/src/react-native/useWebSocketInspector.d.ts +3 -0
- package/dist/src/react-native/websocket/websocket-inspector.d.ts +4 -7
- package/dist/src/shared/client.d.ts +3 -98
- package/dist/src/shared/http-events.d.ts +106 -0
- package/dist/src/shared/sse-events.d.ts +1 -1
- package/dist/src/ui/state/hooks.d.ts +3 -3
- package/dist/src/ui/state/model.d.ts +10 -0
- package/dist/useNetworkActivityDevTools.cjs +112 -993
- package/dist/useNetworkActivityDevTools.js +110 -989
- package/package.json +4 -4
- package/react-native.ts +8 -0
- package/src/react-native/boot-recording.ts +90 -0
- package/src/react-native/config.ts +9 -4
- package/src/react-native/events-listener.ts +102 -0
- package/src/react-native/http/http-inspector.ts +174 -0
- package/src/react-native/http/http-utils.ts +217 -0
- package/src/react-native/inspector.ts +10 -0
- package/src/react-native/network-inspector.ts +78 -0
- package/src/react-native/sse/sse-inspector.ts +12 -10
- package/src/react-native/useHttpInspector.ts +59 -0
- package/src/react-native/useNetworkActivityDevTools.ts +60 -115
- package/src/react-native/useSSEInspector.ts +35 -0
- package/src/react-native/useWebSocketInspector.ts +35 -0
- package/src/react-native/websocket/websocket-inspector.ts +18 -10
- package/src/shared/client.ts +4 -132
- package/src/shared/http-events.ts +140 -0
- package/src/shared/sse-events.ts +1 -1
- package/src/ui/components/RequestList.tsx +18 -6
- package/src/ui/components/Toolbar.tsx +3 -2
- package/src/ui/state/derived.ts +9 -3
- package/src/ui/state/model.ts +10 -0
- package/src/ui/state/store.ts +34 -3
- package/dist/src/react-native/http/network-inspector.d.ts +0 -8
- package/src/react-native/http/network-inspector.ts +0 -388
|
@@ -1,930 +1,89 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
2
|
import { useRozeniteDevToolsClient } from "@rozenite/plugin-bridge";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
try {
|
|
9
|
-
return typeof data === "string" ? data : JSON.stringify(data);
|
|
10
|
-
} catch {
|
|
11
|
-
return String(data);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
function getHttpHeader(headers, name) {
|
|
15
|
-
const lowerName = name.toLowerCase();
|
|
16
|
-
for (const key in headers) {
|
|
17
|
-
if (key.toLowerCase() === lowerName) {
|
|
18
|
-
return { value: headers[key], originalKey: key };
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return void 0;
|
|
22
|
-
}
|
|
23
|
-
function getContentTypeMime(headers) {
|
|
24
|
-
const contentType = getHttpHeader(headers, "content-type");
|
|
25
|
-
if (!contentType) {
|
|
26
|
-
return void 0;
|
|
27
|
-
}
|
|
28
|
-
const { value } = contentType;
|
|
29
|
-
const actualValue = Array.isArray(value) ? value[0] : value;
|
|
30
|
-
return actualValue.split(";")[0].trim();
|
|
31
|
-
}
|
|
32
|
-
const getContentType = (request) => {
|
|
33
|
-
const responseHeaders = request.responseHeaders;
|
|
34
|
-
const responseType = request.responseType;
|
|
35
|
-
const contentType = getContentTypeMime(responseHeaders || {});
|
|
36
|
-
if (contentType) {
|
|
37
|
-
return contentType;
|
|
38
|
-
}
|
|
39
|
-
switch (responseType) {
|
|
40
|
-
case "arraybuffer":
|
|
41
|
-
case "blob":
|
|
42
|
-
return "application/octet-stream";
|
|
43
|
-
case "text":
|
|
44
|
-
case "":
|
|
45
|
-
return "text/plain";
|
|
46
|
-
case "json":
|
|
47
|
-
return "application/json";
|
|
48
|
-
case "document":
|
|
49
|
-
return "text/html";
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
const REQUEST_TTL = 1e3 * 60 * 5;
|
|
53
|
-
const getNetworkRequestsRegistry = () => {
|
|
54
|
-
const registry = /* @__PURE__ */ new Map();
|
|
55
|
-
const trimRegistry = () => {
|
|
56
|
-
const now = Date.now();
|
|
57
|
-
registry.forEach((entry) => {
|
|
58
|
-
if (now - entry.sentAt < REQUEST_TTL) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
registry.delete(entry.id);
|
|
62
|
-
});
|
|
63
|
-
};
|
|
64
|
-
const addEntry = (id, request) => {
|
|
65
|
-
trimRegistry();
|
|
66
|
-
registry.set(id, {
|
|
67
|
-
id,
|
|
68
|
-
request,
|
|
69
|
-
sentAt: Date.now()
|
|
70
|
-
});
|
|
71
|
-
};
|
|
72
|
-
const getEntry = (id) => {
|
|
73
|
-
var _a;
|
|
74
|
-
return ((_a = registry.get(id)) == null ? void 0 : _a.request) ?? null;
|
|
75
|
-
};
|
|
76
|
-
const clear = () => {
|
|
77
|
-
registry.clear();
|
|
78
|
-
};
|
|
79
|
-
return {
|
|
80
|
-
addEntry,
|
|
81
|
-
getEntry,
|
|
82
|
-
clear
|
|
83
|
-
};
|
|
84
|
-
};
|
|
85
|
-
function getBlobName(blob) {
|
|
86
|
-
if (typeof (blob == null ? void 0 : blob.name) === "string") {
|
|
87
|
-
return blob.name;
|
|
88
|
-
}
|
|
89
|
-
if ((blob == null ? void 0 : blob.data) && typeof blob.data.name === "string") {
|
|
90
|
-
return blob.data.name;
|
|
91
|
-
}
|
|
92
|
-
return void 0;
|
|
93
|
-
}
|
|
94
|
-
function getFormDataEntries(formData) {
|
|
95
|
-
if (!formData || typeof formData !== "object") {
|
|
96
|
-
return [];
|
|
97
|
-
}
|
|
98
|
-
if (typeof formData.entries === "function") {
|
|
99
|
-
return formData.entries();
|
|
100
|
-
}
|
|
101
|
-
if (Array.isArray(formData._parts)) {
|
|
102
|
-
return formData._parts;
|
|
103
|
-
}
|
|
104
|
-
return [];
|
|
105
|
-
}
|
|
106
|
-
const XMLHttpRequest = global.XMLHttpRequest || window.XMLHttpRequest;
|
|
107
|
-
const originalXHROpen = XMLHttpRequest.prototype.open;
|
|
108
|
-
const originalXHRSend = XMLHttpRequest.prototype.send;
|
|
109
|
-
const originalXHRSetRequestHeader = XMLHttpRequest.prototype.setRequestHeader;
|
|
110
|
-
let openCallback;
|
|
111
|
-
let sendCallback;
|
|
112
|
-
let requestHeaderCallback;
|
|
113
|
-
let headerReceivedCallback;
|
|
114
|
-
let responseCallback;
|
|
115
|
-
let overrideCallback;
|
|
116
|
-
let isInterceptorEnabled$1 = false;
|
|
117
|
-
const XHRInterceptor = {
|
|
118
|
-
/**
|
|
119
|
-
* Invoked before XMLHttpRequest.open(...) is called.
|
|
120
|
-
*/
|
|
121
|
-
setOpenCallback(callback) {
|
|
122
|
-
openCallback = callback;
|
|
123
|
-
},
|
|
124
|
-
/**
|
|
125
|
-
* Invoked before XMLHttpRequest.send(...) is called.
|
|
126
|
-
*/
|
|
127
|
-
setSendCallback(callback) {
|
|
128
|
-
sendCallback = callback;
|
|
129
|
-
},
|
|
130
|
-
/**
|
|
131
|
-
* Invoked after xhr's readyState becomes xhr.HEADERS_RECEIVED.
|
|
132
|
-
*/
|
|
133
|
-
setHeaderReceivedCallback(callback) {
|
|
134
|
-
headerReceivedCallback = callback;
|
|
135
|
-
},
|
|
136
|
-
/**
|
|
137
|
-
* Invoked after xhr's readyState becomes xhr.DONE.
|
|
138
|
-
*/
|
|
139
|
-
setResponseCallback(callback) {
|
|
140
|
-
responseCallback = callback;
|
|
141
|
-
},
|
|
142
|
-
/**
|
|
143
|
-
* Invoked before XMLHttpRequest.setRequestHeader(...) is called.
|
|
144
|
-
*/
|
|
145
|
-
setRequestHeaderCallback(callback) {
|
|
146
|
-
requestHeaderCallback = callback;
|
|
147
|
-
},
|
|
148
|
-
/**
|
|
149
|
-
* Invoked before XMLHttpRequest.send(...) is called.
|
|
150
|
-
*/
|
|
151
|
-
setOverrideCallback(callback) {
|
|
152
|
-
overrideCallback = callback;
|
|
153
|
-
},
|
|
154
|
-
isInterceptorEnabled() {
|
|
155
|
-
return isInterceptorEnabled$1;
|
|
156
|
-
},
|
|
157
|
-
enableInterception() {
|
|
158
|
-
if (isInterceptorEnabled$1) {
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
XMLHttpRequest.prototype.open = function(method, url) {
|
|
162
|
-
if (openCallback) {
|
|
163
|
-
openCallback(method, url, this);
|
|
164
|
-
}
|
|
165
|
-
originalXHROpen.apply(this, arguments);
|
|
166
|
-
};
|
|
167
|
-
XMLHttpRequest.prototype.setRequestHeader = function(header, value) {
|
|
168
|
-
if (requestHeaderCallback) {
|
|
169
|
-
requestHeaderCallback(header, value, this);
|
|
170
|
-
}
|
|
171
|
-
originalXHRSetRequestHeader.apply(this, arguments);
|
|
172
|
-
};
|
|
173
|
-
XMLHttpRequest.prototype.send = function(data) {
|
|
174
|
-
if (sendCallback) {
|
|
175
|
-
sendCallback(data, this);
|
|
176
|
-
}
|
|
177
|
-
if (overrideCallback) {
|
|
178
|
-
overrideCallback(this);
|
|
179
|
-
}
|
|
180
|
-
if (this.addEventListener) {
|
|
181
|
-
this.addEventListener(
|
|
182
|
-
"readystatechange",
|
|
183
|
-
() => {
|
|
184
|
-
if (!isInterceptorEnabled$1) {
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
if (this.readyState === this.HEADERS_RECEIVED) {
|
|
188
|
-
const contentTypeString = this.getResponseHeader("Content-Type");
|
|
189
|
-
const contentLengthString = this.getResponseHeader("Content-Length");
|
|
190
|
-
let responseContentType, responseSize;
|
|
191
|
-
if (contentTypeString) {
|
|
192
|
-
responseContentType = contentTypeString.split(";")[0];
|
|
193
|
-
}
|
|
194
|
-
if (contentLengthString) {
|
|
195
|
-
responseSize = parseInt(contentLengthString, 10);
|
|
196
|
-
}
|
|
197
|
-
if (headerReceivedCallback) {
|
|
198
|
-
headerReceivedCallback(
|
|
199
|
-
responseContentType,
|
|
200
|
-
responseSize,
|
|
201
|
-
this.getAllResponseHeaders(),
|
|
202
|
-
this
|
|
203
|
-
);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
if (this.readyState === this.DONE) {
|
|
207
|
-
if (responseCallback) {
|
|
208
|
-
responseCallback(
|
|
209
|
-
this.status,
|
|
210
|
-
this.timeout,
|
|
211
|
-
this.response,
|
|
212
|
-
this.responseURL,
|
|
213
|
-
this.responseType,
|
|
214
|
-
this
|
|
215
|
-
);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
},
|
|
219
|
-
false
|
|
220
|
-
);
|
|
221
|
-
}
|
|
222
|
-
originalXHRSend.apply(this, arguments);
|
|
223
|
-
};
|
|
224
|
-
isInterceptorEnabled$1 = true;
|
|
225
|
-
},
|
|
226
|
-
// Unpatch XMLHttpRequest methods and remove the callbacks.
|
|
227
|
-
disableInterception() {
|
|
228
|
-
if (!isInterceptorEnabled$1) {
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
isInterceptorEnabled$1 = false;
|
|
232
|
-
XMLHttpRequest.prototype.send = originalXHRSend;
|
|
233
|
-
XMLHttpRequest.prototype.open = originalXHROpen;
|
|
234
|
-
XMLHttpRequest.prototype.setRequestHeader = originalXHRSetRequestHeader;
|
|
235
|
-
responseCallback = null;
|
|
236
|
-
openCallback = null;
|
|
237
|
-
sendCallback = null;
|
|
238
|
-
headerReceivedCallback = null;
|
|
239
|
-
requestHeaderCallback = null;
|
|
240
|
-
overrideCallback = null;
|
|
241
|
-
}
|
|
242
|
-
};
|
|
243
|
-
const getStringSizeInBytes = (value) => {
|
|
244
|
-
return new TextEncoder().encode(value).length;
|
|
245
|
-
};
|
|
246
|
-
const splitSetCookieHeaderByComma = (header) => {
|
|
247
|
-
const regex = /(?:^|,\s)([^=;,]+=[^;]+(?:;[^,]*)*)/g;
|
|
248
|
-
const matches = [];
|
|
249
|
-
let match;
|
|
250
|
-
while ((match = regex.exec(header)) !== null) {
|
|
251
|
-
matches.push(match[1].trim());
|
|
252
|
-
}
|
|
253
|
-
return matches;
|
|
254
|
-
};
|
|
255
|
-
const applyReactNativeResponseHeadersLogic = (headers) => {
|
|
256
|
-
const parsedHeaders = { ...headers };
|
|
257
|
-
const setCookieHeader = getHttpHeader(headers, "set-cookie");
|
|
258
|
-
if (setCookieHeader) {
|
|
259
|
-
const { value, originalKey } = setCookieHeader;
|
|
260
|
-
const cookies = splitSetCookieHeaderByComma(value);
|
|
261
|
-
parsedHeaders[originalKey] = cookies.length > 0 ? cookies : value;
|
|
262
|
-
}
|
|
263
|
-
return parsedHeaders;
|
|
264
|
-
};
|
|
265
|
-
const isBlob = (value) => value instanceof Blob;
|
|
266
|
-
const isArrayBuffer = (value) => value instanceof ArrayBuffer || ArrayBuffer.isView(value);
|
|
267
|
-
const isFormData = (value) => value instanceof FormData;
|
|
268
|
-
const isNullOrUndefined = (value) => value === null || value === void 0;
|
|
269
|
-
const createOverridesRegistry = () => {
|
|
270
|
-
let overrides = /* @__PURE__ */ new Map();
|
|
271
|
-
const setOverrides = (newOverrides) => {
|
|
272
|
-
overrides = new Map(newOverrides);
|
|
273
|
-
};
|
|
274
|
-
const getOverrideForUrl = (url) => {
|
|
275
|
-
return overrides.get(url);
|
|
276
|
-
};
|
|
277
|
-
return {
|
|
278
|
-
setOverrides,
|
|
279
|
-
getOverrideForUrl
|
|
280
|
-
};
|
|
281
|
-
};
|
|
282
|
-
let registryInstance = null;
|
|
283
|
-
const getOverridesRegistry = () => {
|
|
284
|
-
if (!registryInstance) {
|
|
285
|
-
registryInstance = createOverridesRegistry();
|
|
286
|
-
}
|
|
287
|
-
return registryInstance;
|
|
288
|
-
};
|
|
289
|
-
const networkRequestsRegistry = getNetworkRequestsRegistry();
|
|
290
|
-
const overridesRegistry$1 = getOverridesRegistry();
|
|
291
|
-
const getBinaryPostData = (body) => ({
|
|
292
|
-
type: "binary",
|
|
293
|
-
value: {
|
|
294
|
-
size: body.size,
|
|
295
|
-
type: body.type,
|
|
296
|
-
name: getBlobName(body)
|
|
297
|
-
}
|
|
298
|
-
});
|
|
299
|
-
const getArrayBufferPostData = (body) => ({
|
|
300
|
-
type: "binary",
|
|
301
|
-
value: {
|
|
302
|
-
size: body.byteLength
|
|
303
|
-
}
|
|
304
|
-
});
|
|
305
|
-
const getTextPostData = (body) => ({
|
|
306
|
-
type: "text",
|
|
307
|
-
value: safeStringify(body)
|
|
308
|
-
});
|
|
309
|
-
const getFormDataPostData = (body) => ({
|
|
310
|
-
type: "form-data",
|
|
311
|
-
value: getFormDataEntries(body).reduce(
|
|
312
|
-
(acc, [key, value]) => {
|
|
313
|
-
if (isBlob(value)) {
|
|
314
|
-
acc[key] = getBinaryPostData(value);
|
|
315
|
-
} else if (isArrayBuffer(value)) {
|
|
316
|
-
acc[key] = getArrayBufferPostData(value);
|
|
317
|
-
} else {
|
|
318
|
-
acc[key] = getTextPostData(value);
|
|
319
|
-
}
|
|
320
|
-
return acc;
|
|
321
|
-
},
|
|
322
|
-
{}
|
|
323
|
-
)
|
|
324
|
-
});
|
|
325
|
-
const getRequestBody = (body) => {
|
|
326
|
-
if (isNullOrUndefined(body)) {
|
|
327
|
-
return body;
|
|
328
|
-
}
|
|
329
|
-
if (isBlob(body)) {
|
|
330
|
-
return getBinaryPostData(body);
|
|
331
|
-
}
|
|
332
|
-
if (isArrayBuffer(body)) {
|
|
333
|
-
return getArrayBufferPostData(body);
|
|
334
|
-
}
|
|
335
|
-
if (isFormData(body)) {
|
|
336
|
-
return getFormDataPostData(body);
|
|
337
|
-
}
|
|
338
|
-
return getTextPostData(body);
|
|
339
|
-
};
|
|
340
|
-
const getResponseSize = (request) => {
|
|
341
|
-
try {
|
|
342
|
-
const { responseType, response } = request;
|
|
343
|
-
if (response === null) {
|
|
344
|
-
return 0;
|
|
345
|
-
}
|
|
346
|
-
if (responseType === "" || responseType === "text") {
|
|
347
|
-
return getStringSizeInBytes(request.responseText);
|
|
348
|
-
}
|
|
349
|
-
if (responseType === "json") {
|
|
350
|
-
return getStringSizeInBytes(safeStringify(response));
|
|
351
|
-
}
|
|
352
|
-
if (responseType === "blob") {
|
|
353
|
-
return response.size;
|
|
354
|
-
}
|
|
355
|
-
if (responseType === "arraybuffer") {
|
|
356
|
-
return response.byteLength;
|
|
357
|
-
}
|
|
358
|
-
return 0;
|
|
359
|
-
} catch {
|
|
360
|
-
return null;
|
|
361
|
-
}
|
|
362
|
-
};
|
|
363
|
-
const getResponseBody = async (request) => {
|
|
364
|
-
const responseType = request.responseType;
|
|
365
|
-
if (responseType === "" || responseType === "text") {
|
|
366
|
-
return request.responseText;
|
|
367
|
-
}
|
|
368
|
-
if (responseType === "blob") {
|
|
369
|
-
const contentType = request.getResponseHeader("Content-Type") || "";
|
|
370
|
-
if (contentType.startsWith("text/") || contentType.startsWith("application/json")) {
|
|
371
|
-
return new Promise((resolve) => {
|
|
372
|
-
const reader = new FileReader();
|
|
373
|
-
reader.onload = () => {
|
|
374
|
-
resolve(reader.result);
|
|
375
|
-
};
|
|
376
|
-
reader.readAsText(request.response);
|
|
377
|
-
});
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
if (responseType === "json") {
|
|
381
|
-
return safeStringify(request.response);
|
|
382
|
-
}
|
|
383
|
-
return null;
|
|
384
|
-
};
|
|
385
|
-
const getInitiatorFromStack = () => {
|
|
386
|
-
try {
|
|
387
|
-
const stack = new Error().stack;
|
|
388
|
-
if (!stack) {
|
|
389
|
-
return { type: "other" };
|
|
390
|
-
}
|
|
391
|
-
const line = stack.split("\n")[9];
|
|
392
|
-
const match = line.match(/at\s+(.+?)\s+\((.+?):(\d+):(\d+)\)/);
|
|
393
|
-
if (match) {
|
|
394
|
-
return {
|
|
395
|
-
type: "script",
|
|
396
|
-
url: match[2],
|
|
397
|
-
lineNumber: parseInt(match[3]),
|
|
398
|
-
columnNumber: parseInt(match[4])
|
|
399
|
-
};
|
|
400
|
-
}
|
|
401
|
-
} catch {
|
|
402
|
-
}
|
|
403
|
-
return { type: "other" };
|
|
404
|
-
};
|
|
405
|
-
const READY_STATE_HEADERS_RECEIVED = 2;
|
|
406
|
-
const getNetworkInspector = (pluginClient) => {
|
|
407
|
-
const generateRequestId = () => {
|
|
408
|
-
return `req_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
409
|
-
};
|
|
410
|
-
const handleRequestSend = (data, request) => {
|
|
411
|
-
const sendTime = Date.now();
|
|
412
|
-
const requestId = generateRequestId();
|
|
413
|
-
request._rozeniteRequestId = requestId;
|
|
414
|
-
const initiator = getInitiatorFromStack();
|
|
415
|
-
networkRequestsRegistry.addEntry(requestId, request);
|
|
416
|
-
let ttfb = 0;
|
|
417
|
-
pluginClient.send("request-sent", {
|
|
418
|
-
requestId,
|
|
419
|
-
timestamp: sendTime,
|
|
420
|
-
request: {
|
|
421
|
-
url: request._url,
|
|
422
|
-
method: request._method,
|
|
423
|
-
headers: request._headers,
|
|
424
|
-
postData: getRequestBody(data)
|
|
425
|
-
},
|
|
426
|
-
type: "XHR",
|
|
427
|
-
initiator
|
|
428
|
-
});
|
|
429
|
-
request.addEventListener("readystatechange", () => {
|
|
430
|
-
if (request.readyState === READY_STATE_HEADERS_RECEIVED) {
|
|
431
|
-
ttfb = Date.now() - sendTime;
|
|
432
|
-
}
|
|
433
|
-
});
|
|
434
|
-
request.addEventListener("load", () => {
|
|
435
|
-
pluginClient.send("response-received", {
|
|
436
|
-
requestId,
|
|
437
|
-
timestamp: Date.now(),
|
|
438
|
-
type: "XHR",
|
|
439
|
-
response: {
|
|
440
|
-
url: request._url,
|
|
441
|
-
status: request.status,
|
|
442
|
-
statusText: request.statusText,
|
|
443
|
-
headers: applyReactNativeResponseHeadersLogic(
|
|
444
|
-
request.responseHeaders || {}
|
|
445
|
-
),
|
|
446
|
-
contentType: getContentType(request),
|
|
447
|
-
size: getResponseSize(request),
|
|
448
|
-
responseTime: Date.now()
|
|
449
|
-
}
|
|
450
|
-
});
|
|
451
|
-
});
|
|
452
|
-
request.addEventListener("loadend", () => {
|
|
453
|
-
pluginClient.send("request-completed", {
|
|
454
|
-
requestId,
|
|
455
|
-
timestamp: Date.now(),
|
|
456
|
-
duration: Date.now() - sendTime,
|
|
457
|
-
size: getResponseSize(request),
|
|
458
|
-
ttfb
|
|
459
|
-
});
|
|
460
|
-
});
|
|
461
|
-
request.addEventListener("error", () => {
|
|
462
|
-
pluginClient.send("request-failed", {
|
|
463
|
-
requestId,
|
|
464
|
-
timestamp: Date.now(),
|
|
465
|
-
type: "XHR",
|
|
466
|
-
error: "Failed",
|
|
467
|
-
canceled: false
|
|
468
|
-
});
|
|
469
|
-
});
|
|
470
|
-
request.addEventListener("abort", () => {
|
|
471
|
-
pluginClient.send("request-failed", {
|
|
472
|
-
requestId,
|
|
473
|
-
timestamp: Date.now(),
|
|
474
|
-
type: "XHR",
|
|
475
|
-
error: "Aborted",
|
|
476
|
-
canceled: true
|
|
477
|
-
});
|
|
478
|
-
});
|
|
479
|
-
};
|
|
480
|
-
const handleRequestOverride = (request) => {
|
|
481
|
-
const override = overridesRegistry$1.getOverrideForUrl(
|
|
482
|
-
request._url
|
|
483
|
-
);
|
|
484
|
-
if (!override) {
|
|
3
|
+
import { g as getOverridesRegistry, a as getResponseBody, c as createNetworkInspectorsConfiguration, D as DEFAULT_CONFIG, v as validateConfig, i as isHttpEvent, b as isWebSocketEvent, d as isSSEEvent } from "./boot-recording.js";
|
|
4
|
+
const overridesRegistry = getOverridesRegistry();
|
|
5
|
+
const useHttpInspector = (client, httpInspector, isEnabled, isRecordingEnabled) => {
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
if (!client || !isEnabled) {
|
|
485
8
|
return;
|
|
486
9
|
}
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
request.responseType = "text";
|
|
10
|
+
const networkRequestsRegistry = httpInspector.getNetworkRequestsRegistry();
|
|
11
|
+
const subscriptions = [
|
|
12
|
+
client.onMessage("network-enable", () => {
|
|
13
|
+
httpInspector.enable();
|
|
14
|
+
}),
|
|
15
|
+
client.onMessage("network-disable", () => {
|
|
16
|
+
httpInspector.disable();
|
|
17
|
+
}),
|
|
18
|
+
client.onMessage("set-overrides", (data) => {
|
|
19
|
+
overridesRegistry.setOverrides(data.overrides);
|
|
20
|
+
}),
|
|
21
|
+
client.onMessage("get-response-body", async ({ requestId }) => {
|
|
22
|
+
const request = networkRequestsRegistry.getEntry(requestId);
|
|
23
|
+
if (!request) {
|
|
24
|
+
return;
|
|
503
25
|
}
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
Object.defineProperty(request, "status", {
|
|
509
|
-
writable: true
|
|
26
|
+
const body = await getResponseBody(request);
|
|
27
|
+
client.send("response-body", {
|
|
28
|
+
requestId,
|
|
29
|
+
body
|
|
510
30
|
});
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
const enable = () => {
|
|
516
|
-
XHRInterceptor.disableInterception();
|
|
517
|
-
XHRInterceptor.setSendCallback(handleRequestSend);
|
|
518
|
-
XHRInterceptor.setOverrideCallback(handleRequestOverride);
|
|
519
|
-
XHRInterceptor.enableInterception();
|
|
520
|
-
};
|
|
521
|
-
const disable = () => {
|
|
522
|
-
XHRInterceptor.disableInterception();
|
|
523
|
-
networkRequestsRegistry.clear();
|
|
524
|
-
};
|
|
525
|
-
const isEnabled = () => {
|
|
526
|
-
return XHRInterceptor.isInterceptorEnabled();
|
|
527
|
-
};
|
|
528
|
-
const enableSubscription = pluginClient.onMessage("network-enable", () => {
|
|
529
|
-
enable();
|
|
530
|
-
});
|
|
531
|
-
const disableSubscription = pluginClient.onMessage("network-disable", () => {
|
|
532
|
-
disable();
|
|
533
|
-
});
|
|
534
|
-
const handleBodySubscription = pluginClient.onMessage(
|
|
535
|
-
"get-response-body",
|
|
536
|
-
async ({ requestId }) => {
|
|
537
|
-
const request = networkRequestsRegistry.getEntry(requestId);
|
|
538
|
-
if (!request) {
|
|
539
|
-
return;
|
|
540
|
-
}
|
|
541
|
-
const body = await getResponseBody(request);
|
|
542
|
-
pluginClient.send("response-body", {
|
|
543
|
-
requestId,
|
|
544
|
-
body
|
|
545
|
-
});
|
|
31
|
+
})
|
|
32
|
+
];
|
|
33
|
+
if (isRecordingEnabled) {
|
|
34
|
+
httpInspector.enable();
|
|
546
35
|
}
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
enableSubscription.remove();
|
|
551
|
-
disableSubscription.remove();
|
|
552
|
-
handleBodySubscription.remove();
|
|
553
|
-
};
|
|
554
|
-
return {
|
|
555
|
-
enable,
|
|
556
|
-
disable,
|
|
557
|
-
isEnabled,
|
|
558
|
-
dispose
|
|
559
|
-
};
|
|
560
|
-
};
|
|
561
|
-
const getWebSocketInterceptor = () => {
|
|
562
|
-
if (Platform.constants.reactNativeVersion.minor >= 79) {
|
|
563
|
-
return WebSocketInterceptor;
|
|
564
|
-
} else {
|
|
565
|
-
const WebSocketInterceptorPreRN079 = WebSocketInterceptor;
|
|
566
|
-
return {
|
|
567
|
-
...WebSocketInterceptorPreRN079,
|
|
568
|
-
setOnMessageCallback: (callback) => {
|
|
569
|
-
WebSocketInterceptorPreRN079.setOnMessageCallback((socketId, data) => {
|
|
570
|
-
callback(data, socketId);
|
|
571
|
-
});
|
|
572
|
-
},
|
|
573
|
-
setOnCloseCallback: (callback) => {
|
|
574
|
-
WebSocketInterceptorPreRN079.setOnCloseCallback((error, socketId) => {
|
|
575
|
-
callback(socketId, error);
|
|
576
|
-
});
|
|
577
|
-
},
|
|
578
|
-
setOnErrorCallback: (callback) => {
|
|
579
|
-
WebSocketInterceptorPreRN079.setOnErrorCallback((error, socketId) => {
|
|
580
|
-
callback(socketId, error);
|
|
581
|
-
});
|
|
582
|
-
}
|
|
36
|
+
return () => {
|
|
37
|
+
subscriptions.forEach((subscription) => subscription.remove());
|
|
38
|
+
httpInspector.dispose();
|
|
583
39
|
};
|
|
584
|
-
}
|
|
40
|
+
}, [client, httpInspector, isEnabled, isRecordingEnabled]);
|
|
585
41
|
};
|
|
586
|
-
const
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
const webSocketInterceptor = getWebSocketInterceptor();
|
|
590
|
-
return {
|
|
591
|
-
enable: () => {
|
|
592
|
-
webSocketInterceptor.setConnectCallback(
|
|
593
|
-
(url, protocols, options, socketId) => {
|
|
594
|
-
socketUrlMap.set(socketId, url);
|
|
595
|
-
const event = {
|
|
596
|
-
type: "websocket-connect",
|
|
597
|
-
url,
|
|
598
|
-
socketId,
|
|
599
|
-
timestamp: Date.now(),
|
|
600
|
-
protocols,
|
|
601
|
-
options
|
|
602
|
-
};
|
|
603
|
-
eventEmitter.emit("websocket-connect", event);
|
|
604
|
-
}
|
|
605
|
-
);
|
|
606
|
-
webSocketInterceptor.setCloseCallback(
|
|
607
|
-
(code, reason, socketId) => {
|
|
608
|
-
const url = socketUrlMap.get(socketId);
|
|
609
|
-
if (!url) {
|
|
610
|
-
return;
|
|
611
|
-
}
|
|
612
|
-
const event = {
|
|
613
|
-
type: "websocket-close",
|
|
614
|
-
url,
|
|
615
|
-
socketId,
|
|
616
|
-
timestamp: Date.now(),
|
|
617
|
-
code: code || 0,
|
|
618
|
-
reason: reason || void 0
|
|
619
|
-
};
|
|
620
|
-
eventEmitter.emit("websocket-close", event);
|
|
621
|
-
socketUrlMap.delete(socketId);
|
|
622
|
-
}
|
|
623
|
-
);
|
|
624
|
-
webSocketInterceptor.setOnMessageCallback(
|
|
625
|
-
(data, socketId) => {
|
|
626
|
-
const url = socketUrlMap.get(socketId);
|
|
627
|
-
if (!url) {
|
|
628
|
-
return;
|
|
629
|
-
}
|
|
630
|
-
const event = {
|
|
631
|
-
type: "websocket-message-received",
|
|
632
|
-
url,
|
|
633
|
-
socketId,
|
|
634
|
-
timestamp: Date.now(),
|
|
635
|
-
data,
|
|
636
|
-
messageType: typeof data === "string" ? "text" : "binary"
|
|
637
|
-
};
|
|
638
|
-
eventEmitter.emit("websocket-message-received", event);
|
|
639
|
-
}
|
|
640
|
-
);
|
|
641
|
-
webSocketInterceptor.setOnErrorCallback(
|
|
642
|
-
(error, socketId) => {
|
|
643
|
-
const url = socketUrlMap.get(socketId);
|
|
644
|
-
if (!url) {
|
|
645
|
-
return;
|
|
646
|
-
}
|
|
647
|
-
const event = {
|
|
648
|
-
type: "websocket-error",
|
|
649
|
-
url,
|
|
650
|
-
socketId,
|
|
651
|
-
timestamp: Date.now(),
|
|
652
|
-
error
|
|
653
|
-
};
|
|
654
|
-
eventEmitter.emit("websocket-error", event);
|
|
655
|
-
}
|
|
656
|
-
);
|
|
657
|
-
webSocketInterceptor.setSendCallback((data, socketId) => {
|
|
658
|
-
const url = socketUrlMap.get(socketId);
|
|
659
|
-
if (!url) {
|
|
660
|
-
return;
|
|
661
|
-
}
|
|
662
|
-
const event = {
|
|
663
|
-
type: "websocket-message-sent",
|
|
664
|
-
url,
|
|
665
|
-
socketId,
|
|
666
|
-
timestamp: Date.now(),
|
|
667
|
-
data,
|
|
668
|
-
messageType: typeof data === "string" ? "text" : "binary"
|
|
669
|
-
};
|
|
670
|
-
eventEmitter.emit("websocket-message-sent", event);
|
|
671
|
-
});
|
|
672
|
-
webSocketInterceptor.setOnOpenCallback((socketId) => {
|
|
673
|
-
const url = socketUrlMap.get(socketId);
|
|
674
|
-
if (!url) {
|
|
675
|
-
return;
|
|
676
|
-
}
|
|
677
|
-
const event = {
|
|
678
|
-
type: "websocket-open",
|
|
679
|
-
url,
|
|
680
|
-
socketId,
|
|
681
|
-
timestamp: Date.now()
|
|
682
|
-
};
|
|
683
|
-
eventEmitter.emit("websocket-open", event);
|
|
684
|
-
});
|
|
685
|
-
webSocketInterceptor.setOnCloseCallback(
|
|
686
|
-
(error, socketId) => {
|
|
687
|
-
const url = socketUrlMap.get(socketId);
|
|
688
|
-
if (!url) {
|
|
689
|
-
return;
|
|
690
|
-
}
|
|
691
|
-
const event = {
|
|
692
|
-
type: "websocket-close",
|
|
693
|
-
url,
|
|
694
|
-
socketId,
|
|
695
|
-
timestamp: Date.now(),
|
|
696
|
-
code: error.code,
|
|
697
|
-
reason: error.reason
|
|
698
|
-
};
|
|
699
|
-
eventEmitter.emit("websocket-close", event);
|
|
700
|
-
socketUrlMap.delete(socketId);
|
|
701
|
-
}
|
|
702
|
-
);
|
|
703
|
-
webSocketInterceptor.enableInterception();
|
|
704
|
-
},
|
|
705
|
-
disable: () => {
|
|
706
|
-
webSocketInterceptor.disableInterception();
|
|
707
|
-
},
|
|
708
|
-
isEnabled: () => webSocketInterceptor.isInterceptorEnabled(),
|
|
709
|
-
dispose: () => {
|
|
710
|
-
eventEmitter.events = {};
|
|
711
|
-
socketUrlMap.clear();
|
|
712
|
-
},
|
|
713
|
-
on: (event, callback) => eventEmitter.on(event, callback)
|
|
714
|
-
};
|
|
715
|
-
};
|
|
716
|
-
let connectCallback;
|
|
717
|
-
let messageCallback;
|
|
718
|
-
let errorCallback;
|
|
719
|
-
let openEventCallback;
|
|
720
|
-
let closeCallback;
|
|
721
|
-
let isInterceptorEnabled = false;
|
|
722
|
-
const eventSourceClass = getEventSource();
|
|
723
|
-
const originalOpen = eventSourceClass.prototype.open;
|
|
724
|
-
const originalDispatch = eventSourceClass.prototype.dispatch;
|
|
725
|
-
const BUILT_IN_EVENT_TYPES = /* @__PURE__ */ new Set(["open", "error", "close", "done"]);
|
|
726
|
-
const SSEInterceptor = {
|
|
727
|
-
/**
|
|
728
|
-
* Invoked when EventSource.open() is called (connection attempt starting).
|
|
729
|
-
*/
|
|
730
|
-
setConnectCallback(callback) {
|
|
731
|
-
connectCallback = callback;
|
|
732
|
-
},
|
|
733
|
-
/**
|
|
734
|
-
* Invoked when a message event is received.
|
|
735
|
-
*/
|
|
736
|
-
setMessageCallback(callback) {
|
|
737
|
-
messageCallback = callback;
|
|
738
|
-
},
|
|
739
|
-
/**
|
|
740
|
-
* Invoked when an error event occurs.
|
|
741
|
-
*/
|
|
742
|
-
setErrorCallback(callback) {
|
|
743
|
-
errorCallback = callback;
|
|
744
|
-
},
|
|
745
|
-
/**
|
|
746
|
-
* Invoked when the connection is successfully opened (open event fired).
|
|
747
|
-
*/
|
|
748
|
-
setOpenEventCallback(callback) {
|
|
749
|
-
openEventCallback = callback;
|
|
750
|
-
},
|
|
751
|
-
/**
|
|
752
|
-
* Invoked when the connection is closed.
|
|
753
|
-
*/
|
|
754
|
-
setCloseCallback(callback) {
|
|
755
|
-
closeCallback = callback;
|
|
756
|
-
},
|
|
757
|
-
isInterceptorEnabled() {
|
|
758
|
-
return isInterceptorEnabled;
|
|
759
|
-
},
|
|
760
|
-
enableInterception() {
|
|
761
|
-
if (isInterceptorEnabled) {
|
|
42
|
+
const useWebSocketInspector = (client, websocketInspector, isEnabled, isRecordingEnabled) => {
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (!client || !isEnabled) {
|
|
762
45
|
return;
|
|
763
46
|
}
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
}
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
);
|
|
781
|
-
this.addEventListener("close", (event) => {
|
|
782
|
-
if (closeCallback) {
|
|
783
|
-
closeCallback(event, this);
|
|
784
|
-
}
|
|
785
|
-
});
|
|
786
|
-
return originalOpen.call(this);
|
|
787
|
-
};
|
|
788
|
-
eventSourceClass.prototype.dispatch = function(eventType, data) {
|
|
789
|
-
if (!BUILT_IN_EVENT_TYPES.has(eventType)) {
|
|
790
|
-
if (messageCallback) {
|
|
791
|
-
messageCallback(data, this);
|
|
792
|
-
}
|
|
793
|
-
}
|
|
794
|
-
return originalDispatch.call(this, eventType, data);
|
|
47
|
+
const subscriptions = [
|
|
48
|
+
client.onMessage("network-enable", () => {
|
|
49
|
+
websocketInspector.enable();
|
|
50
|
+
}),
|
|
51
|
+
client.onMessage("network-disable", () => {
|
|
52
|
+
websocketInspector.disable();
|
|
53
|
+
})
|
|
54
|
+
];
|
|
55
|
+
if (isRecordingEnabled) {
|
|
56
|
+
websocketInspector.enable();
|
|
57
|
+
}
|
|
58
|
+
return () => {
|
|
59
|
+
subscriptions.forEach((subscription) => subscription.remove());
|
|
60
|
+
websocketInspector.dispose();
|
|
795
61
|
};
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
if (!
|
|
62
|
+
}, [client, websocketInspector, isEnabled, isRecordingEnabled]);
|
|
63
|
+
};
|
|
64
|
+
const useSSEInspector = (client, sseInspector, isEnabled, isRecordingEnabled) => {
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
if (!client || !isEnabled) {
|
|
801
67
|
return;
|
|
802
68
|
}
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
const getSSEInspector = () => {
|
|
814
|
-
const eventEmitter = createNanoEvents();
|
|
815
|
-
const getRequestId = (eventSource) => {
|
|
816
|
-
var _a;
|
|
817
|
-
const requestId = (_a = eventSource._xhr) == null ? void 0 : _a._rozeniteRequestId;
|
|
818
|
-
if (!requestId) {
|
|
819
|
-
return null;
|
|
69
|
+
const subscriptions = [
|
|
70
|
+
client.onMessage("network-enable", () => {
|
|
71
|
+
sseInspector.enable();
|
|
72
|
+
}),
|
|
73
|
+
client.onMessage("network-disable", () => {
|
|
74
|
+
sseInspector.disable();
|
|
75
|
+
})
|
|
76
|
+
];
|
|
77
|
+
if (isRecordingEnabled) {
|
|
78
|
+
sseInspector.enable();
|
|
820
79
|
}
|
|
821
|
-
return
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
const sseEventSource = eventSource;
|
|
827
|
-
const requestId = getRequestId(sseEventSource);
|
|
828
|
-
if (!requestId) {
|
|
829
|
-
return;
|
|
830
|
-
}
|
|
831
|
-
const sseXhr = sseEventSource._xhr;
|
|
832
|
-
const event = {
|
|
833
|
-
type: "sse-open",
|
|
834
|
-
requestId,
|
|
835
|
-
timestamp: Date.now(),
|
|
836
|
-
response: {
|
|
837
|
-
url: sseXhr._url,
|
|
838
|
-
status: sseXhr.status,
|
|
839
|
-
statusText: sseXhr.statusText,
|
|
840
|
-
headers: sseXhr.responseHeaders || {},
|
|
841
|
-
contentType: getContentType(sseXhr),
|
|
842
|
-
size: 0,
|
|
843
|
-
responseTime: Date.now()
|
|
844
|
-
}
|
|
845
|
-
};
|
|
846
|
-
eventEmitter.emit("sse-open", event);
|
|
847
|
-
});
|
|
848
|
-
SSEInterceptor.setMessageCallback((messageEvent, eventSource) => {
|
|
849
|
-
const sseEventSource = eventSource;
|
|
850
|
-
const requestId = getRequestId(sseEventSource);
|
|
851
|
-
if (!requestId) {
|
|
852
|
-
return;
|
|
853
|
-
}
|
|
854
|
-
const event = {
|
|
855
|
-
type: "sse-message",
|
|
856
|
-
requestId,
|
|
857
|
-
timestamp: Date.now(),
|
|
858
|
-
payload: {
|
|
859
|
-
type: messageEvent.type,
|
|
860
|
-
data: messageEvent.data || ""
|
|
861
|
-
}
|
|
862
|
-
};
|
|
863
|
-
eventEmitter.emit("sse-message", event);
|
|
864
|
-
});
|
|
865
|
-
SSEInterceptor.setErrorCallback((errorEvent, eventSource) => {
|
|
866
|
-
const sseEventSource = eventSource;
|
|
867
|
-
const requestId = getRequestId(sseEventSource);
|
|
868
|
-
if (!requestId) {
|
|
869
|
-
return;
|
|
870
|
-
}
|
|
871
|
-
const event = {
|
|
872
|
-
type: "sse-error",
|
|
873
|
-
requestId,
|
|
874
|
-
timestamp: Date.now(),
|
|
875
|
-
error: {
|
|
876
|
-
type: errorEvent.type,
|
|
877
|
-
message: errorEvent.type === "timeout" ? "Timeout" : errorEvent.message
|
|
878
|
-
}
|
|
879
|
-
};
|
|
880
|
-
eventEmitter.emit("sse-error", event);
|
|
881
|
-
});
|
|
882
|
-
SSEInterceptor.setCloseCallback((_, eventSource) => {
|
|
883
|
-
const sseEventSource = eventSource;
|
|
884
|
-
const requestId = getRequestId(sseEventSource);
|
|
885
|
-
if (!requestId) {
|
|
886
|
-
return;
|
|
887
|
-
}
|
|
888
|
-
const event = {
|
|
889
|
-
type: "sse-close",
|
|
890
|
-
requestId,
|
|
891
|
-
timestamp: Date.now()
|
|
892
|
-
};
|
|
893
|
-
eventEmitter.emit("sse-close", event);
|
|
894
|
-
});
|
|
895
|
-
SSEInterceptor.enableInterception();
|
|
896
|
-
},
|
|
897
|
-
disable: () => {
|
|
898
|
-
SSEInterceptor.disableInterception();
|
|
899
|
-
},
|
|
900
|
-
isEnabled: () => SSEInterceptor.isInterceptorEnabled(),
|
|
901
|
-
dispose: () => {
|
|
902
|
-
SSEInterceptor.disableInterception();
|
|
903
|
-
eventEmitter.events = {};
|
|
904
|
-
},
|
|
905
|
-
on: (event, callback) => eventEmitter.on(event, callback)
|
|
906
|
-
};
|
|
907
|
-
};
|
|
908
|
-
const DEFAULT_CONFIG = {
|
|
909
|
-
inspectors: {
|
|
910
|
-
http: true,
|
|
911
|
-
websocket: true,
|
|
912
|
-
sse: true
|
|
913
|
-
},
|
|
914
|
-
clientUISettings: {
|
|
915
|
-
showUrlAsName: false
|
|
916
|
-
}
|
|
917
|
-
};
|
|
918
|
-
const validateConfig = (config) => {
|
|
919
|
-
const inspectors = config.inspectors;
|
|
920
|
-
if (!inspectors) {
|
|
921
|
-
return;
|
|
922
|
-
}
|
|
923
|
-
if (inspectors.sse && !inspectors.http) {
|
|
924
|
-
throw new Error("SSE inspector requires HTTP inspector to be enabled.");
|
|
925
|
-
}
|
|
80
|
+
return () => {
|
|
81
|
+
subscriptions.forEach((subscription) => subscription.remove());
|
|
82
|
+
sseInspector.dispose();
|
|
83
|
+
};
|
|
84
|
+
}, [client, sseInspector, isEnabled, isRecordingEnabled]);
|
|
926
85
|
};
|
|
927
|
-
const
|
|
86
|
+
const inspectorsConfig = createNetworkInspectorsConfiguration();
|
|
928
87
|
const useNetworkActivityDevTools = (config = DEFAULT_CONFIG) => {
|
|
929
88
|
var _a, _b, _c, _d;
|
|
930
89
|
const isRecordingEnabledRef = useRef(false);
|
|
@@ -935,6 +94,7 @@ const useNetworkActivityDevTools = (config = DEFAULT_CONFIG) => {
|
|
|
935
94
|
const isWebSocketInspectorEnabled = ((_b = config.inspectors) == null ? void 0 : _b.websocket) ?? true;
|
|
936
95
|
const isSSEInspectorEnabled = ((_c = config.inspectors) == null ? void 0 : _c.sse) ?? true;
|
|
937
96
|
const showUrlAsName = (_d = config.clientUISettings) == null ? void 0 : _d.showUrlAsName;
|
|
97
|
+
const { eventsListener, networkInspector } = inspectorsConfig;
|
|
938
98
|
useEffect(() => {
|
|
939
99
|
if (!client) {
|
|
940
100
|
return;
|
|
@@ -956,13 +116,23 @@ const useNetworkActivityDevTools = (config = DEFAULT_CONFIG) => {
|
|
|
956
116
|
const subscriptions = [
|
|
957
117
|
client.onMessage("network-enable", () => {
|
|
958
118
|
isRecordingEnabledRef.current = true;
|
|
119
|
+
eventsListener.connect(client.send, (message) => {
|
|
120
|
+
const type = message.type;
|
|
121
|
+
if (isHttpEvent(type)) {
|
|
122
|
+
return isHttpInspectorEnabled;
|
|
123
|
+
}
|
|
124
|
+
if (isWebSocketEvent(type)) {
|
|
125
|
+
return isWebSocketInspectorEnabled;
|
|
126
|
+
}
|
|
127
|
+
if (isSSEEvent(type)) {
|
|
128
|
+
return isSSEInspectorEnabled;
|
|
129
|
+
}
|
|
130
|
+
return true;
|
|
131
|
+
});
|
|
959
132
|
}),
|
|
960
133
|
client.onMessage("network-disable", () => {
|
|
961
134
|
isRecordingEnabledRef.current = false;
|
|
962
135
|
}),
|
|
963
|
-
client.onMessage("set-overrides", (data) => {
|
|
964
|
-
overridesRegistry.setOverrides(data.overrides);
|
|
965
|
-
}),
|
|
966
136
|
client.onMessage("get-client-ui-settings", () => {
|
|
967
137
|
sendClientUISettings();
|
|
968
138
|
})
|
|
@@ -971,80 +141,31 @@ const useNetworkActivityDevTools = (config = DEFAULT_CONFIG) => {
|
|
|
971
141
|
return () => {
|
|
972
142
|
subscriptions.forEach((subscription) => subscription.remove());
|
|
973
143
|
};
|
|
974
|
-
}, [
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
];
|
|
1000
|
-
const websocketInspector = getWebSocketInspector();
|
|
1001
|
-
eventsToForward.forEach((event) => {
|
|
1002
|
-
websocketInspector.on(event, (event2) => {
|
|
1003
|
-
client.send(event2.type, event2);
|
|
1004
|
-
});
|
|
1005
|
-
});
|
|
1006
|
-
client.onMessage("network-enable", () => {
|
|
1007
|
-
websocketInspector.enable();
|
|
1008
|
-
});
|
|
1009
|
-
client.onMessage("network-disable", () => {
|
|
1010
|
-
websocketInspector.disable();
|
|
1011
|
-
});
|
|
1012
|
-
if (isRecordingEnabledRef.current) {
|
|
1013
|
-
websocketInspector.enable();
|
|
1014
|
-
}
|
|
1015
|
-
return () => {
|
|
1016
|
-
websocketInspector.dispose();
|
|
1017
|
-
};
|
|
1018
|
-
}, [client, isWebSocketInspectorEnabled]);
|
|
1019
|
-
useEffect(() => {
|
|
1020
|
-
if (!client || !isSSEInspectorEnabled) {
|
|
1021
|
-
return;
|
|
1022
|
-
}
|
|
1023
|
-
const eventsToForward = [
|
|
1024
|
-
"sse-open",
|
|
1025
|
-
"sse-message",
|
|
1026
|
-
"sse-error",
|
|
1027
|
-
"sse-close"
|
|
1028
|
-
];
|
|
1029
|
-
const sseInspector = getSSEInspector();
|
|
1030
|
-
eventsToForward.forEach((event) => {
|
|
1031
|
-
sseInspector.on(event, (event2) => {
|
|
1032
|
-
client.send(event2.type, event2);
|
|
1033
|
-
});
|
|
1034
|
-
});
|
|
1035
|
-
client.onMessage("network-enable", () => {
|
|
1036
|
-
sseInspector.enable();
|
|
1037
|
-
});
|
|
1038
|
-
client.onMessage("network-disable", () => {
|
|
1039
|
-
sseInspector.disable();
|
|
1040
|
-
});
|
|
1041
|
-
if (isRecordingEnabledRef.current) {
|
|
1042
|
-
sseInspector.enable();
|
|
1043
|
-
}
|
|
1044
|
-
return () => {
|
|
1045
|
-
sseInspector.dispose();
|
|
1046
|
-
};
|
|
1047
|
-
}, [client, isSSEInspectorEnabled]);
|
|
144
|
+
}, [
|
|
145
|
+
client,
|
|
146
|
+
showUrlAsName,
|
|
147
|
+
isHttpInspectorEnabled,
|
|
148
|
+
isWebSocketInspectorEnabled,
|
|
149
|
+
isSSEInspectorEnabled
|
|
150
|
+
]);
|
|
151
|
+
useHttpInspector(
|
|
152
|
+
client,
|
|
153
|
+
networkInspector.http,
|
|
154
|
+
isHttpInspectorEnabled,
|
|
155
|
+
isRecordingEnabledRef.current
|
|
156
|
+
);
|
|
157
|
+
useWebSocketInspector(
|
|
158
|
+
client,
|
|
159
|
+
networkInspector.websocket,
|
|
160
|
+
isWebSocketInspectorEnabled,
|
|
161
|
+
isRecordingEnabledRef.current
|
|
162
|
+
);
|
|
163
|
+
useSSEInspector(
|
|
164
|
+
client,
|
|
165
|
+
networkInspector.sse,
|
|
166
|
+
isSSEInspectorEnabled,
|
|
167
|
+
isRecordingEnabledRef.current
|
|
168
|
+
);
|
|
1048
169
|
return client;
|
|
1049
170
|
};
|
|
1050
171
|
export {
|