@rozenite/network-activity-plugin 1.0.0-alpha.1 → 1.0.0-alpha.4
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 +3 -5
- package/dist/assets/panel-C0o5JcM0.js +16664 -0
- package/dist/assets/panel-DXGMsavf.css +555 -0
- package/dist/panel.html +2 -2
- package/dist/react-native.cjs +8 -1
- package/dist/react-native.d.ts +86 -1
- package/dist/react-native.js +6 -171
- package/dist/rozenite.json +1 -1
- package/dist/useNetworkActivityDevTools.js +488 -0
- package/package.json +12 -9
- package/project.json +12 -0
- package/react-native.ts +2 -1
- package/rozenite.config.ts +1 -1
- package/src/css-modules.d.ts +1 -1
- package/src/react-native/network-inspector.ts +391 -0
- package/src/react-native/network-requests-registry.ts +122 -0
- package/src/react-native/useNetworkActivityDevTools.ts +6 -217
- package/src/react-native/xhr-interceptor.ts +211 -0
- package/src/react-native/xml-request.d.ts +23 -0
- package/src/types/client.ts +111 -0
- package/src/types/network.ts +26 -147
- package/src/ui/components.tsx +48 -26
- package/src/ui/network-details.module.css +140 -0
- package/src/ui/network-details.tsx +252 -41
- package/src/ui/network-list.module.css +6 -0
- package/src/ui/network-list.tsx +148 -53
- package/src/ui/network-toolbar.tsx +3 -9
- package/src/ui/panel.module.css +6 -0
- package/src/ui/panel.tsx +158 -40
- package/src/ui/tanstack-query.tsx +83 -76
- package/src/ui/utils.ts +22 -13
- package/tsconfig.json +13 -6
- package/tsconfig.tsbuildinfo +1 -0
- package/vite.config.ts +1 -1
- package/dist/assets/panel-C5YgUUj5.js +0 -54
- package/dist/assets/panel-NCVczPb1.css +0 -1
package/dist/react-native.js
CHANGED
|
@@ -1,174 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
let useNetworkActivityDevTools;
|
|
2
|
+
if (process.env.NODE_ENV !== "production") {
|
|
3
|
+
useNetworkActivityDevTools = require("./useNetworkActivityDevTools.js").useNetworkActivityDevTools;
|
|
4
|
+
} else {
|
|
5
|
+
useNetworkActivityDevTools = () => null;
|
|
6
6
|
}
|
|
7
|
-
function h(t) {
|
|
8
|
-
if (t instanceof Headers) {
|
|
9
|
-
const e = {};
|
|
10
|
-
return t.forEach((r, o) => {
|
|
11
|
-
e[o] = r;
|
|
12
|
-
}), e;
|
|
13
|
-
} else if (Array.isArray(t)) {
|
|
14
|
-
const e = {};
|
|
15
|
-
return t.forEach(([r, o]) => {
|
|
16
|
-
e[r] = o;
|
|
17
|
-
}), e;
|
|
18
|
-
}
|
|
19
|
-
return t;
|
|
20
|
-
}
|
|
21
|
-
function I(t, e) {
|
|
22
|
-
let r, o, n, s;
|
|
23
|
-
return typeof t == "string" ? (r = t, o = (e == null ? void 0 : e.method) || "GET", n = h((e == null ? void 0 : e.headers) || {}), s = (e == null ? void 0 : e.body) || void 0) : t instanceof Request ? (r = t.url, o = t.method, n = h(t.headers), s = t.body || void 0) : (r = t.toString(), o = (e == null ? void 0 : e.method) || "GET", n = h((e == null ? void 0 : e.headers) || {}), s = (e == null ? void 0 : e.body) || void 0), { url: r, method: o, headers: n, body: s };
|
|
24
|
-
}
|
|
25
|
-
const T = () => {
|
|
26
|
-
const t = S({
|
|
27
|
-
pluginId: "@rozenite/network-activity-plugin"
|
|
28
|
-
});
|
|
29
|
-
return v(() => {
|
|
30
|
-
if (!t)
|
|
31
|
-
return;
|
|
32
|
-
const e = window.fetch.bind(window), r = (o, n) => {
|
|
33
|
-
t.send(o, n);
|
|
34
|
-
};
|
|
35
|
-
return window.fetch = async function(o, n) {
|
|
36
|
-
const s = g(), d = I(o, n), c = Date.now() / 1e3, w = c;
|
|
37
|
-
r("Network.requestWillBeSent", {
|
|
38
|
-
requestId: s,
|
|
39
|
-
loaderId: s,
|
|
40
|
-
documentURL: "",
|
|
41
|
-
request: {
|
|
42
|
-
url: d.url,
|
|
43
|
-
method: d.method,
|
|
44
|
-
headers: d.headers,
|
|
45
|
-
postData: d.body,
|
|
46
|
-
hasPostData: !!d.body
|
|
47
|
-
},
|
|
48
|
-
timestamp: c,
|
|
49
|
-
wallTime: w,
|
|
50
|
-
initiator: {
|
|
51
|
-
type: "script",
|
|
52
|
-
stack: {
|
|
53
|
-
callFrames: [
|
|
54
|
-
{
|
|
55
|
-
functionName: "fetch",
|
|
56
|
-
scriptId: "1",
|
|
57
|
-
url: "",
|
|
58
|
-
lineNumber: 1,
|
|
59
|
-
columnNumber: 1
|
|
60
|
-
}
|
|
61
|
-
]
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
redirectHasExtraInfo: !1,
|
|
65
|
-
redirectResponse: null,
|
|
66
|
-
referrerPolicy: "no-referrer",
|
|
67
|
-
type: "Fetch",
|
|
68
|
-
frameId: "1",
|
|
69
|
-
hasUserGesture: !1
|
|
70
|
-
}), r("Network.requestWillBeSentExtraInfo", {
|
|
71
|
-
requestId: s,
|
|
72
|
-
blockedCookies: [],
|
|
73
|
-
headers: d.headers,
|
|
74
|
-
connectTiming: {
|
|
75
|
-
requestTime: c
|
|
76
|
-
},
|
|
77
|
-
clientSecurityState: {
|
|
78
|
-
initiatorIsSecureContext: !1,
|
|
79
|
-
initiatorIPAddressSpace: "Public",
|
|
80
|
-
privateNetworkRequestPolicy: "Allow"
|
|
81
|
-
},
|
|
82
|
-
siteHasCookieInOtherPartition: !1
|
|
83
|
-
});
|
|
84
|
-
let a;
|
|
85
|
-
try {
|
|
86
|
-
a = await e(o, n);
|
|
87
|
-
const l = {};
|
|
88
|
-
a.headers.forEach((m, y) => {
|
|
89
|
-
l[y] = m;
|
|
90
|
-
});
|
|
91
|
-
const k = a.headers.get("content-type") || "", i = a.headers.get("content-length"), u = i ? parseInt(i, 10) : 0;
|
|
92
|
-
let f = u;
|
|
93
|
-
try {
|
|
94
|
-
f = (await a.clone().arrayBuffer()).byteLength;
|
|
95
|
-
} catch {
|
|
96
|
-
f = u;
|
|
97
|
-
}
|
|
98
|
-
return r("Network.responseReceived", {
|
|
99
|
-
requestId: s,
|
|
100
|
-
loaderId: s,
|
|
101
|
-
timestamp: Date.now() / 1e3,
|
|
102
|
-
type: "Fetch",
|
|
103
|
-
response: {
|
|
104
|
-
url: d.url,
|
|
105
|
-
status: a.status,
|
|
106
|
-
statusText: a.statusText,
|
|
107
|
-
headers: l,
|
|
108
|
-
mimeType: k,
|
|
109
|
-
requestHeaders: d.headers,
|
|
110
|
-
requestHeadersText: void 0,
|
|
111
|
-
connectionReused: !1,
|
|
112
|
-
connectionId: 0,
|
|
113
|
-
remoteIPAddress: void 0,
|
|
114
|
-
remotePort: void 0,
|
|
115
|
-
protocol: void 0,
|
|
116
|
-
securityState: "unknown",
|
|
117
|
-
encodedDataLength: u,
|
|
118
|
-
timing: {
|
|
119
|
-
requestTime: c,
|
|
120
|
-
proxyStart: -1,
|
|
121
|
-
proxyEnd: -1,
|
|
122
|
-
dnsStart: -1,
|
|
123
|
-
dnsEnd: -1,
|
|
124
|
-
connectStart: -1,
|
|
125
|
-
connectEnd: -1,
|
|
126
|
-
sslStart: -1,
|
|
127
|
-
sslEnd: -1,
|
|
128
|
-
workerStart: -1,
|
|
129
|
-
workerReadyStart: -1,
|
|
130
|
-
workerReadyEnd: -1,
|
|
131
|
-
sendStart: c,
|
|
132
|
-
sendEnd: c,
|
|
133
|
-
pushStart: -1,
|
|
134
|
-
pushEnd: -1,
|
|
135
|
-
receiveHeadersEnd: Date.now() / 1e3
|
|
136
|
-
},
|
|
137
|
-
responseTime: Date.now() / 1e3,
|
|
138
|
-
fromDiskCache: !1,
|
|
139
|
-
fromServiceWorker: !1,
|
|
140
|
-
fromPrefetchCache: !1,
|
|
141
|
-
encodedBodySize: u,
|
|
142
|
-
decodedBodySize: f,
|
|
143
|
-
headersText: void 0,
|
|
144
|
-
serviceWorkerResponseSource: void 0,
|
|
145
|
-
responseSource: "network",
|
|
146
|
-
statusCode: a.status
|
|
147
|
-
},
|
|
148
|
-
hasExtraInfo: !1
|
|
149
|
-
}), r("Network.loadingFinished", {
|
|
150
|
-
requestId: s,
|
|
151
|
-
timestamp: Date.now() / 1e3,
|
|
152
|
-
encodedDataLength: u,
|
|
153
|
-
shouldReportCorbBlocking: !1
|
|
154
|
-
}), a;
|
|
155
|
-
} catch (l) {
|
|
156
|
-
throw r("Network.loadingFailed", {
|
|
157
|
-
requestId: s,
|
|
158
|
-
timestamp: Date.now() / 1e3,
|
|
159
|
-
type: "Fetch",
|
|
160
|
-
errorText: l instanceof Error ? l.message : "Unknown error",
|
|
161
|
-
canceled: !1,
|
|
162
|
-
blockedReason: void 0
|
|
163
|
-
}), l;
|
|
164
|
-
}
|
|
165
|
-
}, () => {
|
|
166
|
-
window.fetch = e;
|
|
167
|
-
};
|
|
168
|
-
}, [t]), t;
|
|
169
|
-
};
|
|
170
|
-
let p;
|
|
171
|
-
process.env.NODE_ENV !== "production" ? p = T : p = () => null;
|
|
172
7
|
export {
|
|
173
|
-
|
|
8
|
+
useNetworkActivityDevTools
|
|
174
9
|
};
|
package/dist/rozenite.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@rozenite/network-activity-plugin","version":"1.0.0-alpha.
|
|
1
|
+
{"name":"@rozenite/network-activity-plugin","version":"1.0.0-alpha.3","description":"Network Activity for Rozenite.","panels":[{"name":"Network Activity","source":"/panel.html"}]}
|
|
@@ -0,0 +1,488 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const react = require("react");
|
|
4
|
+
const pluginBridge = require("@rozenite/plugin-bridge");
|
|
5
|
+
const REQUEST_TTL = 1e3 * 60 * 5;
|
|
6
|
+
const getNetworkRequestsRegistry = () => {
|
|
7
|
+
const registry = /* @__PURE__ */ new Map();
|
|
8
|
+
const trimRegistry = () => {
|
|
9
|
+
const now = Date.now();
|
|
10
|
+
registry.forEach((entry) => {
|
|
11
|
+
if (now - entry.sentAt < REQUEST_TTL) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
registry.delete(entry.id);
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
const addEntry = (id, request, metadata) => {
|
|
18
|
+
trimRegistry();
|
|
19
|
+
const fullMetadata = {
|
|
20
|
+
id,
|
|
21
|
+
method: metadata.method || "GET",
|
|
22
|
+
url: metadata.url || "",
|
|
23
|
+
headers: metadata.headers || {},
|
|
24
|
+
startTime: metadata.startTime || Date.now(),
|
|
25
|
+
status: metadata.status || "pending",
|
|
26
|
+
...metadata
|
|
27
|
+
};
|
|
28
|
+
registry.set(id, {
|
|
29
|
+
id,
|
|
30
|
+
request,
|
|
31
|
+
metadata: fullMetadata,
|
|
32
|
+
sentAt: Date.now()
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
const getEntry = (id) => {
|
|
36
|
+
return registry.get(id) ?? null;
|
|
37
|
+
};
|
|
38
|
+
const updateEntry = (id, updates) => {
|
|
39
|
+
const entry = registry.get(id);
|
|
40
|
+
if (entry) {
|
|
41
|
+
entry.metadata = { ...entry.metadata, ...updates };
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const getAllEntries = () => {
|
|
45
|
+
return Array.from(registry.values());
|
|
46
|
+
};
|
|
47
|
+
const clear = () => {
|
|
48
|
+
registry.clear();
|
|
49
|
+
};
|
|
50
|
+
return {
|
|
51
|
+
addEntry,
|
|
52
|
+
getEntry,
|
|
53
|
+
updateEntry,
|
|
54
|
+
getAllEntries,
|
|
55
|
+
clear
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
const originalXHROpen = XMLHttpRequest.prototype.open;
|
|
59
|
+
const originalXHRSend = XMLHttpRequest.prototype.send;
|
|
60
|
+
const originalXHRSetRequestHeader = XMLHttpRequest.prototype.setRequestHeader;
|
|
61
|
+
let openCallback;
|
|
62
|
+
let sendCallback;
|
|
63
|
+
let requestHeaderCallback;
|
|
64
|
+
let headerReceivedCallback;
|
|
65
|
+
let responseCallback;
|
|
66
|
+
let isInterceptorEnabled = false;
|
|
67
|
+
const XHRInterceptor = {
|
|
68
|
+
/**
|
|
69
|
+
* Invoked before XMLHttpRequest.open(...) is called.
|
|
70
|
+
*/
|
|
71
|
+
setOpenCallback(callback) {
|
|
72
|
+
openCallback = callback;
|
|
73
|
+
},
|
|
74
|
+
/**
|
|
75
|
+
* Invoked before XMLHttpRequest.send(...) is called.
|
|
76
|
+
*/
|
|
77
|
+
setSendCallback(callback) {
|
|
78
|
+
sendCallback = callback;
|
|
79
|
+
},
|
|
80
|
+
/**
|
|
81
|
+
* Invoked after xhr's readyState becomes xhr.HEADERS_RECEIVED.
|
|
82
|
+
*/
|
|
83
|
+
setHeaderReceivedCallback(callback) {
|
|
84
|
+
headerReceivedCallback = callback;
|
|
85
|
+
},
|
|
86
|
+
/**
|
|
87
|
+
* Invoked after xhr's readyState becomes xhr.DONE.
|
|
88
|
+
*/
|
|
89
|
+
setResponseCallback(callback) {
|
|
90
|
+
responseCallback = callback;
|
|
91
|
+
},
|
|
92
|
+
/**
|
|
93
|
+
* Invoked before XMLHttpRequest.setRequestHeader(...) is called.
|
|
94
|
+
*/
|
|
95
|
+
setRequestHeaderCallback(callback) {
|
|
96
|
+
requestHeaderCallback = callback;
|
|
97
|
+
},
|
|
98
|
+
isInterceptorEnabled() {
|
|
99
|
+
return isInterceptorEnabled;
|
|
100
|
+
},
|
|
101
|
+
enableInterception() {
|
|
102
|
+
if (isInterceptorEnabled) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
XMLHttpRequest.prototype.open = function(method, url) {
|
|
106
|
+
if (openCallback) {
|
|
107
|
+
openCallback(method, url, this);
|
|
108
|
+
}
|
|
109
|
+
originalXHROpen.apply(this, arguments);
|
|
110
|
+
};
|
|
111
|
+
XMLHttpRequest.prototype.setRequestHeader = function(header, value) {
|
|
112
|
+
if (requestHeaderCallback) {
|
|
113
|
+
requestHeaderCallback(header, value, this);
|
|
114
|
+
}
|
|
115
|
+
originalXHRSetRequestHeader.apply(this, arguments);
|
|
116
|
+
};
|
|
117
|
+
XMLHttpRequest.prototype.send = function(data) {
|
|
118
|
+
if (sendCallback) {
|
|
119
|
+
sendCallback(data, this);
|
|
120
|
+
}
|
|
121
|
+
if (this.addEventListener) {
|
|
122
|
+
this.addEventListener(
|
|
123
|
+
"readystatechange",
|
|
124
|
+
() => {
|
|
125
|
+
if (!isInterceptorEnabled) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (this.readyState === this.HEADERS_RECEIVED) {
|
|
129
|
+
const contentTypeString = this.getResponseHeader("Content-Type");
|
|
130
|
+
const contentLengthString = this.getResponseHeader("Content-Length");
|
|
131
|
+
let responseContentType, responseSize;
|
|
132
|
+
if (contentTypeString) {
|
|
133
|
+
responseContentType = contentTypeString.split(";")[0];
|
|
134
|
+
}
|
|
135
|
+
if (contentLengthString) {
|
|
136
|
+
responseSize = parseInt(contentLengthString, 10);
|
|
137
|
+
}
|
|
138
|
+
if (headerReceivedCallback) {
|
|
139
|
+
headerReceivedCallback(
|
|
140
|
+
responseContentType,
|
|
141
|
+
responseSize,
|
|
142
|
+
this.getAllResponseHeaders(),
|
|
143
|
+
this
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (this.readyState === this.DONE) {
|
|
148
|
+
if (responseCallback) {
|
|
149
|
+
responseCallback(
|
|
150
|
+
this.status,
|
|
151
|
+
this.timeout,
|
|
152
|
+
this.response,
|
|
153
|
+
this.responseURL,
|
|
154
|
+
this.responseType,
|
|
155
|
+
this
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
false
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
originalXHRSend.apply(this, arguments);
|
|
164
|
+
};
|
|
165
|
+
isInterceptorEnabled = true;
|
|
166
|
+
},
|
|
167
|
+
// Unpatch XMLHttpRequest methods and remove the callbacks.
|
|
168
|
+
disableInterception() {
|
|
169
|
+
if (!isInterceptorEnabled) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
isInterceptorEnabled = false;
|
|
173
|
+
XMLHttpRequest.prototype.send = originalXHRSend;
|
|
174
|
+
XMLHttpRequest.prototype.open = originalXHROpen;
|
|
175
|
+
XMLHttpRequest.prototype.setRequestHeader = originalXHRSetRequestHeader;
|
|
176
|
+
responseCallback = null;
|
|
177
|
+
openCallback = null;
|
|
178
|
+
sendCallback = null;
|
|
179
|
+
headerReceivedCallback = null;
|
|
180
|
+
requestHeaderCallback = null;
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
const networkRequestsRegistry = getNetworkRequestsRegistry();
|
|
184
|
+
const mimeTypeFromResponseType = (responseType) => {
|
|
185
|
+
switch (responseType) {
|
|
186
|
+
case "arraybuffer":
|
|
187
|
+
case "blob":
|
|
188
|
+
case "base64":
|
|
189
|
+
return "application/octet-stream";
|
|
190
|
+
case "text":
|
|
191
|
+
case "":
|
|
192
|
+
return "text/plain";
|
|
193
|
+
case "json":
|
|
194
|
+
return "application/json";
|
|
195
|
+
case "document":
|
|
196
|
+
return "text/html";
|
|
197
|
+
}
|
|
198
|
+
return void 0;
|
|
199
|
+
};
|
|
200
|
+
const parseHeaders = (headersString) => {
|
|
201
|
+
const headers = {};
|
|
202
|
+
if (!headersString) return headers;
|
|
203
|
+
const lines = headersString.split("\r\n");
|
|
204
|
+
for (const line of lines) {
|
|
205
|
+
const colonIndex = line.indexOf(":");
|
|
206
|
+
if (colonIndex > 0) {
|
|
207
|
+
const key = line.substring(0, colonIndex).trim();
|
|
208
|
+
const value = line.substring(colonIndex + 1).trim();
|
|
209
|
+
headers[key] = value;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return headers;
|
|
213
|
+
};
|
|
214
|
+
const getResponseBody = async (request) => {
|
|
215
|
+
try {
|
|
216
|
+
if (request.responseType === "arraybuffer") {
|
|
217
|
+
const arrayBuffer = request.response;
|
|
218
|
+
return {
|
|
219
|
+
body: btoa(String.fromCharCode(...new Uint8Array(arrayBuffer))),
|
|
220
|
+
base64Encoded: true
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
if (request.responseType === "blob") {
|
|
224
|
+
const contentType = request.getResponseHeader("Content-Type") || "";
|
|
225
|
+
if (contentType.startsWith("text/") || contentType.startsWith("application/json")) {
|
|
226
|
+
return new Promise((resolve) => {
|
|
227
|
+
const reader = new FileReader();
|
|
228
|
+
reader.onload = () => {
|
|
229
|
+
resolve({
|
|
230
|
+
body: reader.result,
|
|
231
|
+
base64Encoded: false
|
|
232
|
+
});
|
|
233
|
+
};
|
|
234
|
+
reader.readAsText(request.response);
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
if (request.responseType === "text") {
|
|
239
|
+
return {
|
|
240
|
+
body: request.responseText || request.response || "",
|
|
241
|
+
base64Encoded: false
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
return {
|
|
245
|
+
body: request.responseText || request.response || "",
|
|
246
|
+
base64Encoded: false
|
|
247
|
+
};
|
|
248
|
+
} catch (error) {
|
|
249
|
+
return {
|
|
250
|
+
body: `[Error reading response: ${error}]`,
|
|
251
|
+
base64Encoded: false
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
const findRequestId = (request) => {
|
|
256
|
+
const allRequests = networkRequestsRegistry.getAllEntries();
|
|
257
|
+
const entry = allRequests.find(({ request: req }) => req === request);
|
|
258
|
+
return (entry == null ? void 0 : entry.id) ?? null;
|
|
259
|
+
};
|
|
260
|
+
const getInitiatorFromStack = () => {
|
|
261
|
+
try {
|
|
262
|
+
const stack = new Error().stack;
|
|
263
|
+
if (!stack) {
|
|
264
|
+
return { type: "other" };
|
|
265
|
+
}
|
|
266
|
+
const line = stack.split("\n")[9];
|
|
267
|
+
const match = line.match(/at\s+(.+?)\s+\((.+?):(\d+):(\d+)\)/);
|
|
268
|
+
if (match) {
|
|
269
|
+
return {
|
|
270
|
+
type: "script",
|
|
271
|
+
url: match[2],
|
|
272
|
+
lineNumber: parseInt(match[3]),
|
|
273
|
+
columnNumber: parseInt(match[4])
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
} catch {
|
|
277
|
+
}
|
|
278
|
+
return { type: "other" };
|
|
279
|
+
};
|
|
280
|
+
const getNetworkInspector = (pluginClient) => {
|
|
281
|
+
const generateRequestId = () => {
|
|
282
|
+
return `req_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
283
|
+
};
|
|
284
|
+
const generateLoaderId = () => {
|
|
285
|
+
return `loader_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
286
|
+
};
|
|
287
|
+
const enable = () => {
|
|
288
|
+
XHRInterceptor.disableInterception();
|
|
289
|
+
XHRInterceptor.setOpenCallback(
|
|
290
|
+
(method, url, request) => {
|
|
291
|
+
const requestId = generateRequestId();
|
|
292
|
+
const loaderId = generateLoaderId();
|
|
293
|
+
const startTime = Date.now();
|
|
294
|
+
const initiator = getInitiatorFromStack();
|
|
295
|
+
networkRequestsRegistry.addEntry(requestId, request, {
|
|
296
|
+
id: requestId,
|
|
297
|
+
loaderId,
|
|
298
|
+
documentURL: typeof document !== "undefined" ? document.URL : void 0,
|
|
299
|
+
method,
|
|
300
|
+
url,
|
|
301
|
+
headers: (request == null ? void 0 : request._headers) || {},
|
|
302
|
+
startTime,
|
|
303
|
+
status: "pending",
|
|
304
|
+
type: "XHR",
|
|
305
|
+
initiator
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
);
|
|
309
|
+
XHRInterceptor.setSendCallback((data, request) => {
|
|
310
|
+
const requestId = findRequestId(request);
|
|
311
|
+
if (!requestId) return;
|
|
312
|
+
const entry = networkRequestsRegistry.getEntry(requestId);
|
|
313
|
+
if (!entry) return;
|
|
314
|
+
const metadata = entry.metadata;
|
|
315
|
+
networkRequestsRegistry.updateEntry(requestId, {
|
|
316
|
+
postData: data,
|
|
317
|
+
hasPostData: !!data,
|
|
318
|
+
headers: (request == null ? void 0 : request._headers) || {}
|
|
319
|
+
});
|
|
320
|
+
pluginClient.send("Network.requestWillBeSent", {
|
|
321
|
+
requestId,
|
|
322
|
+
loaderId: metadata.loaderId || "",
|
|
323
|
+
documentURL: metadata.documentURL || "",
|
|
324
|
+
request: {
|
|
325
|
+
url: metadata.url,
|
|
326
|
+
method: metadata.method,
|
|
327
|
+
headers: metadata.headers,
|
|
328
|
+
postData: data,
|
|
329
|
+
hasPostData: !!data
|
|
330
|
+
},
|
|
331
|
+
timestamp: metadata.startTime,
|
|
332
|
+
wallTime: metadata.startTime,
|
|
333
|
+
initiator: metadata.initiator || { type: "other" },
|
|
334
|
+
type: metadata.type
|
|
335
|
+
});
|
|
336
|
+
});
|
|
337
|
+
XHRInterceptor.setHeaderReceivedCallback(
|
|
338
|
+
(responseContentType, responseSize, allHeaders, request) => {
|
|
339
|
+
const requestId = findRequestId(request);
|
|
340
|
+
if (!requestId) return;
|
|
341
|
+
const entry = networkRequestsRegistry.getEntry(requestId);
|
|
342
|
+
if (!entry) return;
|
|
343
|
+
const metadata = entry.metadata;
|
|
344
|
+
const headers = parseHeaders(allHeaders);
|
|
345
|
+
const mimeType = responseContentType || mimeTypeFromResponseType(request.responseType) || "text/plain";
|
|
346
|
+
networkRequestsRegistry.updateEntry(requestId, {
|
|
347
|
+
status: "loading",
|
|
348
|
+
response: {
|
|
349
|
+
url: metadata.url,
|
|
350
|
+
status: request.status,
|
|
351
|
+
statusText: request.statusText,
|
|
352
|
+
headers,
|
|
353
|
+
mimeType,
|
|
354
|
+
encodedDataLength: responseSize || 0,
|
|
355
|
+
responseTime: Date.now()
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
pluginClient.send("Network.responseReceived", {
|
|
359
|
+
requestId,
|
|
360
|
+
loaderId: metadata.loaderId || "",
|
|
361
|
+
timestamp: Date.now(),
|
|
362
|
+
type: metadata.type || "Other",
|
|
363
|
+
response: {
|
|
364
|
+
url: metadata.url,
|
|
365
|
+
status: request.status,
|
|
366
|
+
statusText: request.statusText,
|
|
367
|
+
headers,
|
|
368
|
+
mimeType,
|
|
369
|
+
encodedDataLength: responseSize || 0,
|
|
370
|
+
responseTime: Date.now()
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
);
|
|
375
|
+
XHRInterceptor.setResponseCallback(
|
|
376
|
+
(status, timeout, response, responseURL, responseType, request) => {
|
|
377
|
+
const requestId = findRequestId(request);
|
|
378
|
+
if (!requestId) return;
|
|
379
|
+
const entry = networkRequestsRegistry.getEntry(requestId);
|
|
380
|
+
if (!entry) return;
|
|
381
|
+
const metadata = entry.metadata;
|
|
382
|
+
if (!metadata) return;
|
|
383
|
+
const endTime = Date.now();
|
|
384
|
+
const duration = endTime - metadata.startTime;
|
|
385
|
+
const dataLength = response ? response.length : 0;
|
|
386
|
+
networkRequestsRegistry.updateEntry(requestId, {
|
|
387
|
+
endTime,
|
|
388
|
+
duration,
|
|
389
|
+
dataLength,
|
|
390
|
+
encodedDataLength: dataLength
|
|
391
|
+
});
|
|
392
|
+
if (status >= 400 || request.readyState === 0) {
|
|
393
|
+
const errorText = request.statusText || "Request failed";
|
|
394
|
+
const canceled = request.readyState === 0;
|
|
395
|
+
networkRequestsRegistry.updateEntry(requestId, {
|
|
396
|
+
status: "failed",
|
|
397
|
+
errorText,
|
|
398
|
+
canceled
|
|
399
|
+
});
|
|
400
|
+
pluginClient.send("Network.loadingFailed", {
|
|
401
|
+
requestId,
|
|
402
|
+
timestamp: endTime,
|
|
403
|
+
type: metadata.type || "Other",
|
|
404
|
+
errorText,
|
|
405
|
+
canceled
|
|
406
|
+
});
|
|
407
|
+
} else {
|
|
408
|
+
networkRequestsRegistry.updateEntry(requestId, {
|
|
409
|
+
status: "finished",
|
|
410
|
+
encodedDataLength: dataLength
|
|
411
|
+
});
|
|
412
|
+
if (dataLength > 0) {
|
|
413
|
+
pluginClient.send("Network.dataReceived", {
|
|
414
|
+
requestId,
|
|
415
|
+
timestamp: endTime,
|
|
416
|
+
dataLength,
|
|
417
|
+
encodedDataLength: dataLength
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
pluginClient.send("Network.loadingFinished", {
|
|
421
|
+
requestId,
|
|
422
|
+
timestamp: endTime,
|
|
423
|
+
encodedDataLength: dataLength
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
);
|
|
428
|
+
XHRInterceptor.enableInterception();
|
|
429
|
+
};
|
|
430
|
+
const disable = () => {
|
|
431
|
+
XHRInterceptor.disableInterception();
|
|
432
|
+
networkRequestsRegistry.clear();
|
|
433
|
+
};
|
|
434
|
+
const isEnabled = () => {
|
|
435
|
+
return XHRInterceptor.isInterceptorEnabled();
|
|
436
|
+
};
|
|
437
|
+
const enableSubscription = pluginClient.onMessage("network-enable", () => {
|
|
438
|
+
enable();
|
|
439
|
+
});
|
|
440
|
+
const disableSubscription = pluginClient.onMessage("network-disable", () => {
|
|
441
|
+
disable();
|
|
442
|
+
});
|
|
443
|
+
const handleBodySubscription = pluginClient.onMessage(
|
|
444
|
+
"Network.getResponseBody",
|
|
445
|
+
async (payload) => {
|
|
446
|
+
const requestId = payload.requestId;
|
|
447
|
+
const entry = networkRequestsRegistry.getEntry(requestId);
|
|
448
|
+
if (!entry) {
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
const { request } = entry;
|
|
452
|
+
const { body, base64Encoded } = await getResponseBody(request);
|
|
453
|
+
pluginClient.send("Network.responseBodyReceived", {
|
|
454
|
+
requestId,
|
|
455
|
+
body,
|
|
456
|
+
base64Encoded
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
);
|
|
460
|
+
const dispose = () => {
|
|
461
|
+
disable();
|
|
462
|
+
enableSubscription.remove();
|
|
463
|
+
disableSubscription.remove();
|
|
464
|
+
handleBodySubscription.remove();
|
|
465
|
+
};
|
|
466
|
+
return {
|
|
467
|
+
enable,
|
|
468
|
+
disable,
|
|
469
|
+
isEnabled,
|
|
470
|
+
dispose
|
|
471
|
+
};
|
|
472
|
+
};
|
|
473
|
+
const useNetworkActivityDevTools = () => {
|
|
474
|
+
const client = pluginBridge.useRozeniteDevToolsClient({
|
|
475
|
+
pluginId: "@rozenite/network-activity-plugin"
|
|
476
|
+
});
|
|
477
|
+
react.useEffect(() => {
|
|
478
|
+
if (!client) {
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
const networkInspector = getNetworkInspector(client);
|
|
482
|
+
return () => {
|
|
483
|
+
networkInspector.dispose();
|
|
484
|
+
};
|
|
485
|
+
}, [client]);
|
|
486
|
+
return client;
|
|
487
|
+
};
|
|
488
|
+
exports.useNetworkActivityDevTools = useNetworkActivityDevTools;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rozenite/network-activity-plugin",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.4",
|
|
4
4
|
"description": "Network Activity for Rozenite.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/react-native.cjs",
|
|
@@ -9,19 +9,22 @@
|
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@tanstack/react-virtual": "^3.0.0",
|
|
11
11
|
"@floating-ui/react": "^0.26.0",
|
|
12
|
-
"@rozenite/plugin-bridge": "1.0.0-alpha.
|
|
12
|
+
"@rozenite/plugin-bridge": "1.0.0-alpha.4"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
|
-
"typescript": "^5.7.3",
|
|
16
15
|
"vite": "^6.0.0",
|
|
17
|
-
"
|
|
18
|
-
"react-native": "
|
|
19
|
-
"
|
|
20
|
-
"
|
|
16
|
+
"typescript": "^5.7.3",
|
|
17
|
+
"react-native-web": "0.21.0",
|
|
18
|
+
"react": "18.3.1",
|
|
19
|
+
"react-dom": "18.3.0",
|
|
20
|
+
"react-native": "0.76.0",
|
|
21
|
+
"@types/react": "~18.3.12",
|
|
22
|
+
"rozenite": "1.0.0-alpha.4",
|
|
23
|
+
"@rozenite/vite-plugin": "1.0.0-alpha.4"
|
|
21
24
|
},
|
|
22
25
|
"peerDependencies": {
|
|
23
|
-
"react": "
|
|
24
|
-
"react-native": "
|
|
26
|
+
"react": "*",
|
|
27
|
+
"react-native": "*"
|
|
25
28
|
},
|
|
26
29
|
"license": "MIT",
|
|
27
30
|
"scripts": {
|