@wutiange/log-listener-plugin 2.0.1-alpha.3 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. package/LICENSE +201 -201
  2. package/README.md +163 -163
  3. package/dist/src/HTTPInterceptor.js +2 -1
  4. package/dist/src/HTTPInterceptor.js.map +1 -1
  5. package/dist/src/__tests__/Server.test.js +4 -4
  6. package/dist/src/__tests__/Server.test.js.map +1 -1
  7. package/dist/src/__tests__/console.test.d.ts +1 -0
  8. package/dist/src/__tests__/console.test.js +29 -0
  9. package/dist/src/__tests__/console.test.js.map +1 -0
  10. package/dist/src/__tests__/utils.test.js +5 -1
  11. package/dist/src/__tests__/utils.test.js.map +1 -1
  12. package/dist/src/common.d.ts +1 -7
  13. package/dist/src/common.js +2 -14
  14. package/dist/src/common.js.map +1 -1
  15. package/dist/src/logPlugin.js +22 -17
  16. package/dist/src/logPlugin.js.map +1 -1
  17. package/dist/src/server.d.ts +21 -0
  18. package/dist/src/{Server.js → server.js} +47 -31
  19. package/dist/src/server.js.map +1 -0
  20. package/dist/src/utils.js +4 -4
  21. package/dist/src/utils.js.map +1 -1
  22. package/index.ts +3 -3
  23. package/package.json +59 -59
  24. package/src/HTTPInterceptor.ts +340 -339
  25. package/src/Server.ts +178 -167
  26. package/src/__mocks__/react-native/Libraries/Blob/FileReader.js +44 -44
  27. package/src/__mocks__/react-native/Libraries/Network/XHRInterceptor.js +39 -39
  28. package/src/__tests__/HTTPInterceptor.test.ts +322 -322
  29. package/src/__tests__/Server.test.ts +149 -149
  30. package/src/__tests__/utils.test.ts +113 -112
  31. package/src/common.ts +57 -70
  32. package/src/logPlugin.ts +231 -224
  33. package/src/logger.ts +14 -14
  34. package/src/utils.ts +112 -112
  35. package/tsconfig.json +26 -26
  36. package/dist/src/Server.d.ts +0 -20
  37. package/dist/src/Server.js.map +0 -1
@@ -1,339 +1,340 @@
1
- import XHRInterceptor from 'react-native/Libraries/Network/XHRInterceptor';
2
- import BlobFileReader from 'react-native/Libraries/Blob/FileReader';
3
- import {Blob} from 'buffer';
4
- import { createClassWithErrorHandling, formDataToString } from './utils';
5
-
6
- type StartNetworkLoggingOptions = {
7
- /** List of hosts to ignore, e.g. `services.test.com` */
8
- ignoredHosts?: string[];
9
- /** List of urls to ignore, e.g. `https://services.test.com/test` */
10
- ignoredUrls?: string[];
11
- /**
12
- * List of url patterns to ignore, e.g. `/^GET https://test.com\/pages\/.*$/`
13
- *
14
- * Url to match with is in the format: `${method} ${url}`, e.g. `GET https://test.com/pages/123`
15
- */
16
- ignoredPatterns?: RegExp[];
17
- /**
18
- * Force the network logger to start even if another program is using the network interceptor
19
- * e.g. a dev/debuging program
20
- */
21
- forceEnable?: boolean;
22
- };
23
-
24
- interface HttpRequestInfo {
25
- id: string;
26
- method: RequestMethod;
27
- url: string;
28
- timeout: number;
29
- requestHeaders: Record<string, string>;
30
- requestData: any | null;
31
- startTime: number;
32
- endTime: number;
33
- responseHeaders: Headers;
34
- responseData: any | null;
35
- status: number;
36
- duration: number;
37
- responseContentType: string;
38
- responseSize: number;
39
- responseURL: string;
40
- responseType: string;
41
- }
42
-
43
- type RequestMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
44
-
45
- type XHR = {
46
- uniqueId: string;
47
- responseHeaders?: Headers;
48
- };
49
-
50
- type EventName =
51
- | 'open'
52
- | 'requestHeader'
53
- | 'headerReceived'
54
- | 'send'
55
- | 'response';
56
-
57
- const extractHost = (url: string) => {
58
- const host = url.split('//')[1]?.split(':')[0]?.split('/')[0] || undefined;
59
-
60
- return host;
61
- };
62
-
63
- const generateUniqueId = () => {
64
- return Date.now().toString(36) + Math.random().toString(36).substr(2);
65
- };
66
-
67
- const parseResponseBlob = async (response: Blob) => {
68
- const blobReader = new BlobFileReader();
69
- blobReader.readAsText(response);
70
-
71
- return await new Promise<string>((resolve, reject) => {
72
- const handleError = () => reject(blobReader.error);
73
-
74
- blobReader.addEventListener('load', () => {
75
- resolve(blobReader.result);
76
- });
77
- blobReader.addEventListener('error', handleError);
78
- blobReader.addEventListener('abort', handleError);
79
- });
80
- };
81
-
82
- const getResponseBody = async (responseType: string, response: any) => {
83
- try {
84
- if (responseType === 'blob' && response) {
85
- return await parseResponseBlob(response as unknown as Blob);
86
- }
87
- return response ?? null;
88
- } catch (error) {
89
- console.warn("getResponseBody---error---", error)
90
- return null;
91
- }
92
- };
93
-
94
- class HTTPInterceptor {
95
- private static _index = 0;
96
- private ignoredHosts: Set<string> | undefined;
97
- private ignoredUrls: Set<string> | undefined;
98
- private ignoredPatterns: RegExp[] | undefined;
99
- // 只保存正在请求中的
100
- private allRequests = new Map<string, Partial<HttpRequestInfo>>();
101
-
102
- private userListeners: [
103
- EventName,
104
- (data: Partial<HttpRequestInfo>) => Promise<void> | void,
105
- ][] = [];
106
-
107
- private enabled = false;
108
-
109
- addListener = (
110
- eventName: EventName,
111
- listener: (data: Partial<HttpRequestInfo>) => Promise<void> | void,
112
- ) => {
113
- // 如果之前已经订阅过了就过滤掉
114
- if (
115
- this.userListeners.find(
116
- ([name, tempListener]) =>
117
- name === eventName && tempListener === listener,
118
- )
119
- ) {
120
- return;
121
- }
122
- this.userListeners.push([eventName, listener]);
123
-
124
- return () => {
125
- this.userListeners = this.userListeners.filter(
126
- ([name, tempListener]) =>
127
- name !== eventName || tempListener !== listener,
128
- );
129
- };
130
- };
131
-
132
- removeListener = (
133
- eventName: EventName,
134
- listener: (data: Partial<HttpRequestInfo>) => Promise<void> | void,
135
- ) => {
136
- this.userListeners = this.userListeners.filter(
137
- ([name, tempListener]) => name !== eventName || tempListener !== listener,
138
- );
139
- };
140
-
141
- removeAllListener() {
142
- this.userListeners = [];
143
- }
144
-
145
- private listenerHandle = (
146
- eventName: EventName,
147
- data: Partial<HttpRequestInfo>,
148
- ) => {
149
- this.userListeners.forEach(async ([name, listener]) => {
150
- try {
151
- if (name === eventName) {
152
- await listener(data);
153
- }
154
- } catch (error: any) {
155
- console.warn(`eventName=${eventName}, error=${error?.message}`)
156
- }
157
- });
158
- };
159
-
160
- private openHandle = (method: RequestMethod, url: string, xhr: XHR) => {
161
- if (this.ignoredHosts) {
162
- const host = extractHost(url);
163
- if (host && this.ignoredHosts.has(host)) {
164
- return;
165
- }
166
- }
167
- if (this.ignoredUrls && this.ignoredUrls.has(url)) {
168
- return;
169
- }
170
-
171
- if (this.ignoredPatterns) {
172
- if (
173
- this.ignoredPatterns.some(pattern => pattern.test(`${method} ${url}`))
174
- ) {
175
- return;
176
- }
177
- }
178
- xhr.uniqueId = HTTPInterceptor._index + generateUniqueId();
179
- const newRequest = {
180
- id: xhr.uniqueId,
181
- method,
182
- url,
183
- };
184
- this.allRequests.set(xhr.uniqueId, newRequest);
185
- this.listenerHandle('open', newRequest);
186
- };
187
-
188
- private requestHeaderHandle = (header: string, value: string, xhr: XHR) => {
189
- const currentRequest = this.allRequests.get(xhr.uniqueId);
190
- if (!currentRequest) {
191
- return;
192
- }
193
- if (!currentRequest.requestHeaders) {
194
- currentRequest.requestHeaders = {};
195
- }
196
- currentRequest.requestHeaders[header] = value;
197
- this.listenerHandle('requestHeader', currentRequest);
198
- };
199
-
200
- private headerReceivedHandle = (
201
- responseContentType: string,
202
- responseSize: number,
203
- responseHeaders: Headers,
204
- xhr: XHR,
205
- ) => {
206
- const currentRequest = this.allRequests.get(xhr.uniqueId);
207
- if (!currentRequest) {
208
- return;
209
- }
210
- currentRequest.responseContentType = responseContentType;
211
- currentRequest.responseSize = responseSize;
212
- currentRequest.responseHeaders = xhr.responseHeaders;
213
- this.listenerHandle('headerReceived', currentRequest);
214
- };
215
-
216
- private responseHandle = async (
217
- status: number,
218
- timeout: number,
219
- response: any,
220
- responseURL: string,
221
- responseType: string,
222
- xhr: XHR,
223
- ) => {
224
- const currentRequest = this.allRequests.get(xhr.uniqueId);
225
- if (!currentRequest) {
226
- return;
227
- }
228
- currentRequest.endTime = Date.now();
229
- currentRequest.status = status;
230
- currentRequest.timeout = timeout;
231
- currentRequest.responseData = await getResponseBody(responseType, response);
232
- currentRequest.responseURL = responseURL;
233
- currentRequest.responseType = responseType;
234
- currentRequest.duration =
235
- currentRequest.endTime - (currentRequest.startTime ?? 0);
236
- this.listenerHandle('response', currentRequest);
237
- this.allRequests.delete(xhr.uniqueId);
238
- };
239
-
240
- private sendHandle = (data: any, xhr: XHR) => {
241
- const currentRequest = this.allRequests.get(xhr.uniqueId);
242
- if (!currentRequest) {
243
- return;
244
- }
245
- try {
246
- if (data && typeof data === 'object' && data instanceof FormData) {
247
- currentRequest.requestData = formDataToString(data);
248
- } else {
249
- currentRequest.requestData = JSON.parse(data);
250
- }
251
- } catch (error) {
252
- currentRequest.requestData = null;
253
- }
254
- currentRequest.startTime = Date.now();
255
- this.listenerHandle('send', currentRequest);
256
- };
257
-
258
- setIgnoredUrls = (ignoredUrls: string[]) => {
259
- if (ignoredUrls?.length) {
260
- if (
261
- !Array.isArray(ignoredUrls) ||
262
- typeof ignoredUrls[0] !== 'string'
263
- ) {
264
- console.warn(
265
- 'ignoredUrls must be an array of strings. The logger has not been started.',
266
- );
267
- return;
268
- }
269
- this.ignoredUrls = new Set(ignoredUrls);
270
- }
271
- }
272
-
273
- enable = (options?: StartNetworkLoggingOptions) => {
274
- try {
275
- if (
276
- this.enabled ||
277
- (XHRInterceptor.isInterceptorEnabled() && !options?.forceEnable)
278
- ) {
279
- if (!this.enabled) {
280
- console.warn(
281
- 'network interceptor has not been enabled as another interceptor is already running (e.g. another debugging program). Use option `forceEnable: true` to override this behaviour.',
282
- );
283
- }
284
- return;
285
- }
286
-
287
- if (options?.ignoredHosts) {
288
- if (
289
- !Array.isArray(options.ignoredHosts) ||
290
- typeof options.ignoredHosts[0] !== 'string'
291
- ) {
292
- console.warn(
293
- 'ignoredHosts must be an array of strings. The logger has not been started.',
294
- );
295
- return;
296
- }
297
- this.ignoredHosts = new Set(options.ignoredHosts);
298
- }
299
-
300
- if (options?.ignoredPatterns) {
301
- this.ignoredPatterns = options.ignoredPatterns;
302
- }
303
- this.setIgnoredUrls(options?.ignoredUrls)
304
- XHRInterceptor.setOpenCallback(this.openHandle);
305
- XHRInterceptor.setRequestHeaderCallback(this.requestHeaderHandle);
306
- XHRInterceptor.setHeaderReceivedCallback(this.headerReceivedHandle);
307
- XHRInterceptor.setSendCallback(this.sendHandle);
308
- XHRInterceptor.setResponseCallback(this.responseHandle);
309
- XHRInterceptor.enableInterception();
310
- this.enabled = true;
311
- } catch (error) {}
312
- };
313
-
314
- disable = () => {
315
- if (!this.enabled) {
316
- return;
317
- }
318
- XHRInterceptor.disableInterception();
319
- this.enabled = false;
320
- };
321
-
322
- reset = () => {
323
- this.disable();
324
- this.removeAllListener();
325
- this.ignoredHosts = undefined;
326
- this.ignoredUrls = undefined;
327
- this.ignoredPatterns = undefined;
328
- this.allRequests.clear();
329
- };
330
- }
331
-
332
- const SafeHTTPInterceptor = createClassWithErrorHandling(HTTPInterceptor)
333
- const httpInterceptor = new SafeHTTPInterceptor();
334
- export {
335
- type StartNetworkLoggingOptions,
336
- httpInterceptor,
337
- type EventName,
338
- type RequestMethod,
339
- };
1
+ import XHRInterceptor from 'react-native/Libraries/Network/XHRInterceptor';
2
+ import BlobFileReader from 'react-native/Libraries/Blob/FileReader';
3
+ import {Blob} from 'buffer';
4
+ import { createClassWithErrorHandling, formDataToString } from './utils';
5
+ import logger from './logger';
6
+
7
+ type StartNetworkLoggingOptions = {
8
+ /** List of hosts to ignore, e.g. `services.test.com` */
9
+ ignoredHosts?: string[];
10
+ /** List of urls to ignore, e.g. `https://services.test.com/test` */
11
+ ignoredUrls?: string[];
12
+ /**
13
+ * List of url patterns to ignore, e.g. `/^GET https://test.com\/pages\/.*$/`
14
+ *
15
+ * Url to match with is in the format: `${method} ${url}`, e.g. `GET https://test.com/pages/123`
16
+ */
17
+ ignoredPatterns?: RegExp[];
18
+ /**
19
+ * Force the network logger to start even if another program is using the network interceptor
20
+ * e.g. a dev/debuging program
21
+ */
22
+ forceEnable?: boolean;
23
+ };
24
+
25
+ interface HttpRequestInfo {
26
+ id: string;
27
+ method: RequestMethod;
28
+ url: string;
29
+ timeout: number;
30
+ requestHeaders: Record<string, string>;
31
+ requestData: any | null;
32
+ startTime: number;
33
+ endTime: number;
34
+ responseHeaders: Headers;
35
+ responseData: any | null;
36
+ status: number;
37
+ duration: number;
38
+ responseContentType: string;
39
+ responseSize: number;
40
+ responseURL: string;
41
+ responseType: string;
42
+ }
43
+
44
+ type RequestMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
45
+
46
+ type XHR = {
47
+ uniqueId: string;
48
+ responseHeaders?: Headers;
49
+ };
50
+
51
+ type EventName =
52
+ | 'open'
53
+ | 'requestHeader'
54
+ | 'headerReceived'
55
+ | 'send'
56
+ | 'response';
57
+
58
+ const extractHost = (url: string) => {
59
+ const host = url.split('//')[1]?.split(':')[0]?.split('/')[0] || undefined;
60
+
61
+ return host;
62
+ };
63
+
64
+ const generateUniqueId = () => {
65
+ return Date.now().toString(36) + Math.random().toString(36).substr(2);
66
+ };
67
+
68
+ const parseResponseBlob = async (response: Blob) => {
69
+ const blobReader = new BlobFileReader();
70
+ blobReader.readAsText(response);
71
+
72
+ return await new Promise<string>((resolve, reject) => {
73
+ const handleError = () => reject(blobReader.error);
74
+
75
+ blobReader.addEventListener('load', () => {
76
+ resolve(blobReader.result);
77
+ });
78
+ blobReader.addEventListener('error', handleError);
79
+ blobReader.addEventListener('abort', handleError);
80
+ });
81
+ };
82
+
83
+ const getResponseBody = async (responseType: string, response: any) => {
84
+ try {
85
+ if (responseType === 'blob' && response) {
86
+ return await parseResponseBlob(response as unknown as Blob);
87
+ }
88
+ return response ?? null;
89
+ } catch (error) {
90
+ logger.warn("getResponseBody---error---", error)
91
+ return null;
92
+ }
93
+ };
94
+
95
+ class HTTPInterceptor {
96
+ private static _index = 0;
97
+ private ignoredHosts: Set<string> | undefined;
98
+ private ignoredUrls: Set<string> | undefined;
99
+ private ignoredPatterns: RegExp[] | undefined;
100
+ // 只保存正在请求中的
101
+ private allRequests = new Map<string, Partial<HttpRequestInfo>>();
102
+
103
+ private userListeners: [
104
+ EventName,
105
+ (data: Partial<HttpRequestInfo>) => Promise<void> | void,
106
+ ][] = [];
107
+
108
+ private enabled = false;
109
+
110
+ addListener = (
111
+ eventName: EventName,
112
+ listener: (data: Partial<HttpRequestInfo>) => Promise<void> | void,
113
+ ) => {
114
+ // 如果之前已经订阅过了就过滤掉
115
+ if (
116
+ this.userListeners.find(
117
+ ([name, tempListener]) =>
118
+ name === eventName && tempListener === listener,
119
+ )
120
+ ) {
121
+ return;
122
+ }
123
+ this.userListeners.push([eventName, listener]);
124
+
125
+ return () => {
126
+ this.userListeners = this.userListeners.filter(
127
+ ([name, tempListener]) =>
128
+ name !== eventName || tempListener !== listener,
129
+ );
130
+ };
131
+ };
132
+
133
+ removeListener = (
134
+ eventName: EventName,
135
+ listener: (data: Partial<HttpRequestInfo>) => Promise<void> | void,
136
+ ) => {
137
+ this.userListeners = this.userListeners.filter(
138
+ ([name, tempListener]) => name !== eventName || tempListener !== listener,
139
+ );
140
+ };
141
+
142
+ removeAllListener() {
143
+ this.userListeners = [];
144
+ }
145
+
146
+ private listenerHandle = (
147
+ eventName: EventName,
148
+ data: Partial<HttpRequestInfo>,
149
+ ) => {
150
+ this.userListeners.forEach(async ([name, listener]) => {
151
+ try {
152
+ if (name === eventName) {
153
+ await listener(data);
154
+ }
155
+ } catch (error: any) {
156
+ console.warn(`eventName=${eventName}, error=${error?.message}`)
157
+ }
158
+ });
159
+ };
160
+
161
+ private openHandle = (method: RequestMethod, url: string, xhr: XHR) => {
162
+ if (this.ignoredHosts) {
163
+ const host = extractHost(url);
164
+ if (host && this.ignoredHosts.has(host)) {
165
+ return;
166
+ }
167
+ }
168
+ if (this.ignoredUrls && this.ignoredUrls.has(url)) {
169
+ return;
170
+ }
171
+
172
+ if (this.ignoredPatterns) {
173
+ if (
174
+ this.ignoredPatterns.some(pattern => pattern.test(`${method} ${url}`))
175
+ ) {
176
+ return;
177
+ }
178
+ }
179
+ xhr.uniqueId = HTTPInterceptor._index + generateUniqueId();
180
+ const newRequest = {
181
+ id: xhr.uniqueId,
182
+ method,
183
+ url,
184
+ };
185
+ this.allRequests.set(xhr.uniqueId, newRequest);
186
+ this.listenerHandle('open', newRequest);
187
+ };
188
+
189
+ private requestHeaderHandle = (header: string, value: string, xhr: XHR) => {
190
+ const currentRequest = this.allRequests.get(xhr.uniqueId);
191
+ if (!currentRequest) {
192
+ return;
193
+ }
194
+ if (!currentRequest.requestHeaders) {
195
+ currentRequest.requestHeaders = {};
196
+ }
197
+ currentRequest.requestHeaders[header] = value;
198
+ this.listenerHandle('requestHeader', currentRequest);
199
+ };
200
+
201
+ private headerReceivedHandle = (
202
+ responseContentType: string,
203
+ responseSize: number,
204
+ responseHeaders: Headers,
205
+ xhr: XHR,
206
+ ) => {
207
+ const currentRequest = this.allRequests.get(xhr.uniqueId);
208
+ if (!currentRequest) {
209
+ return;
210
+ }
211
+ currentRequest.responseContentType = responseContentType;
212
+ currentRequest.responseSize = responseSize;
213
+ currentRequest.responseHeaders = xhr.responseHeaders;
214
+ this.listenerHandle('headerReceived', currentRequest);
215
+ };
216
+
217
+ private responseHandle = async (
218
+ status: number,
219
+ timeout: number,
220
+ response: any,
221
+ responseURL: string,
222
+ responseType: string,
223
+ xhr: XHR,
224
+ ) => {
225
+ const currentRequest = this.allRequests.get(xhr.uniqueId);
226
+ if (!currentRequest) {
227
+ return;
228
+ }
229
+ currentRequest.endTime = Date.now();
230
+ currentRequest.status = status;
231
+ currentRequest.timeout = timeout;
232
+ currentRequest.responseData = await getResponseBody(responseType, response);
233
+ currentRequest.responseURL = responseURL;
234
+ currentRequest.responseType = responseType;
235
+ currentRequest.duration =
236
+ currentRequest.endTime - (currentRequest.startTime ?? 0);
237
+ this.listenerHandle('response', currentRequest);
238
+ this.allRequests.delete(xhr.uniqueId);
239
+ };
240
+
241
+ private sendHandle = (data: any, xhr: XHR) => {
242
+ const currentRequest = this.allRequests.get(xhr.uniqueId);
243
+ if (!currentRequest) {
244
+ return;
245
+ }
246
+ try {
247
+ if (data && typeof data === 'object' && data instanceof FormData) {
248
+ currentRequest.requestData = formDataToString(data);
249
+ } else {
250
+ currentRequest.requestData = JSON.parse(data);
251
+ }
252
+ } catch (error) {
253
+ currentRequest.requestData = null;
254
+ }
255
+ currentRequest.startTime = Date.now();
256
+ this.listenerHandle('send', currentRequest);
257
+ };
258
+
259
+ setIgnoredUrls = (ignoredUrls: string[]) => {
260
+ if (ignoredUrls?.length) {
261
+ if (
262
+ !Array.isArray(ignoredUrls) ||
263
+ typeof ignoredUrls[0] !== 'string'
264
+ ) {
265
+ console.warn(
266
+ 'ignoredUrls must be an array of strings. The logger has not been started.',
267
+ );
268
+ return;
269
+ }
270
+ this.ignoredUrls = new Set(ignoredUrls);
271
+ }
272
+ }
273
+
274
+ enable = (options?: StartNetworkLoggingOptions) => {
275
+ try {
276
+ if (
277
+ this.enabled ||
278
+ (XHRInterceptor.isInterceptorEnabled() && !options?.forceEnable)
279
+ ) {
280
+ if (!this.enabled) {
281
+ console.warn(
282
+ 'network interceptor has not been enabled as another interceptor is already running (e.g. another debugging program). Use option `forceEnable: true` to override this behaviour.',
283
+ );
284
+ }
285
+ return;
286
+ }
287
+
288
+ if (options?.ignoredHosts) {
289
+ if (
290
+ !Array.isArray(options.ignoredHosts) ||
291
+ typeof options.ignoredHosts[0] !== 'string'
292
+ ) {
293
+ console.warn(
294
+ 'ignoredHosts must be an array of strings. The logger has not been started.',
295
+ );
296
+ return;
297
+ }
298
+ this.ignoredHosts = new Set(options.ignoredHosts);
299
+ }
300
+
301
+ if (options?.ignoredPatterns) {
302
+ this.ignoredPatterns = options.ignoredPatterns;
303
+ }
304
+ this.setIgnoredUrls(options?.ignoredUrls)
305
+ XHRInterceptor.setOpenCallback(this.openHandle);
306
+ XHRInterceptor.setRequestHeaderCallback(this.requestHeaderHandle);
307
+ XHRInterceptor.setHeaderReceivedCallback(this.headerReceivedHandle);
308
+ XHRInterceptor.setSendCallback(this.sendHandle);
309
+ XHRInterceptor.setResponseCallback(this.responseHandle);
310
+ XHRInterceptor.enableInterception();
311
+ this.enabled = true;
312
+ } catch (error) {}
313
+ };
314
+
315
+ disable = () => {
316
+ if (!this.enabled) {
317
+ return;
318
+ }
319
+ XHRInterceptor.disableInterception();
320
+ this.enabled = false;
321
+ };
322
+
323
+ reset = () => {
324
+ this.disable();
325
+ this.removeAllListener();
326
+ this.ignoredHosts = undefined;
327
+ this.ignoredUrls = undefined;
328
+ this.ignoredPatterns = undefined;
329
+ this.allRequests.clear();
330
+ };
331
+ }
332
+
333
+ const SafeHTTPInterceptor = createClassWithErrorHandling(HTTPInterceptor)
334
+ const httpInterceptor = new SafeHTTPInterceptor();
335
+ export {
336
+ type StartNetworkLoggingOptions,
337
+ httpInterceptor,
338
+ type EventName,
339
+ type RequestMethod,
340
+ };