@kush_hemant/react-api-monitor 1.0.31 → 1.0.32
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/dist/index.js +5 -33
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -33,15 +33,15 @@ function getMetadata() {
|
|
|
33
33
|
|
|
34
34
|
// src/network/fetchMonitor.js
|
|
35
35
|
function monitorFetch() {
|
|
36
|
-
const originalFetch =
|
|
37
|
-
|
|
36
|
+
const originalFetch = window.fetch;
|
|
37
|
+
window.fetch = async function(input, init = {}) {
|
|
38
|
+
const start = Date.now();
|
|
38
39
|
const request = input instanceof Request ? input : new Request(input, init);
|
|
39
40
|
const url = request.url;
|
|
40
41
|
const method = request.method || "GET";
|
|
41
42
|
if (LOG_ENDPOINT && url.startsWith(LOG_ENDPOINT)) {
|
|
42
|
-
return originalFetch(
|
|
43
|
+
return originalFetch.apply(this, arguments);
|
|
43
44
|
}
|
|
44
|
-
const start = Date.now();
|
|
45
45
|
let requestBody = null;
|
|
46
46
|
try {
|
|
47
47
|
requestBody = await request.clone().text();
|
|
@@ -52,7 +52,7 @@ function monitorFetch() {
|
|
|
52
52
|
requestHeaders[k] = v;
|
|
53
53
|
});
|
|
54
54
|
try {
|
|
55
|
-
const response = await originalFetch(
|
|
55
|
+
const response = await originalFetch.apply(this, arguments);
|
|
56
56
|
let responseBody = null;
|
|
57
57
|
try {
|
|
58
58
|
responseBody = await response.clone().text();
|
|
@@ -91,8 +91,6 @@ function monitorFetch() {
|
|
|
91
91
|
throw err;
|
|
92
92
|
}
|
|
93
93
|
};
|
|
94
|
-
globalThis.fetch = patchedFetch;
|
|
95
|
-
if (typeof window !== "undefined") window.fetch = patchedFetch;
|
|
96
94
|
}
|
|
97
95
|
|
|
98
96
|
// src/network/xhrMonitor.js
|
|
@@ -134,31 +132,6 @@ function monitorXHR() {
|
|
|
134
132
|
};
|
|
135
133
|
}
|
|
136
134
|
|
|
137
|
-
// src/network/resourceMonitor.js
|
|
138
|
-
function monitorResources() {
|
|
139
|
-
if (!window.PerformanceObserver) return;
|
|
140
|
-
const observer = new PerformanceObserver((list) => {
|
|
141
|
-
list.getEntries().forEach((entry) => {
|
|
142
|
-
if (entry.initiatorType === "fetch" || entry.initiatorType === "xmlhttprequest" || entry.initiatorType === "beacon") {
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
if (LOG_ENDPOINT && entry.name.includes(LOG_ENDPOINT)) {
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
sendLog({
|
|
149
|
-
type: "resource",
|
|
150
|
-
transport: "resource",
|
|
151
|
-
url: entry.name,
|
|
152
|
-
method: "GET",
|
|
153
|
-
duration: Math.round(entry.duration),
|
|
154
|
-
statusCode: 0,
|
|
155
|
-
...getMetadata()
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
observer.observe({ entryTypes: ["resource"] });
|
|
160
|
-
}
|
|
161
|
-
|
|
162
135
|
// src/network/monitorAxios.js
|
|
163
136
|
function monitorAxios() {
|
|
164
137
|
if (!window.axios) return;
|
|
@@ -209,7 +182,6 @@ function startNetworkMonitoring() {
|
|
|
209
182
|
monitorXHR();
|
|
210
183
|
monitorAxios();
|
|
211
184
|
monitorBeacon();
|
|
212
|
-
monitorResources();
|
|
213
185
|
}
|
|
214
186
|
|
|
215
187
|
// src/index.js
|