@ohbug/browser 2.3.0 → 2.4.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/dist/index.d.ts CHANGED
@@ -33,6 +33,11 @@ interface UnhandledrejectionErrorDetail extends OhbugBaseDetail {
33
33
  }
34
34
 
35
35
  interface UnknownErrorDetail extends OhbugBaseDetail {
36
+ name: string;
37
+ filename?: string;
38
+ lineno?: number;
39
+ colno?: number;
40
+ stack: string;
36
41
  }
37
42
 
38
43
  interface AjaxErrorDetail extends OhbugBaseDetail {
package/dist/index.js CHANGED
@@ -49,7 +49,7 @@ module.exports = __toCommonJS(src_exports);
49
49
 
50
50
  // src/client.ts
51
51
  var import_core13 = require("@ohbug/core");
52
- var import_utils19 = require("@ohbug/utils");
52
+ var import_utils20 = require("@ohbug/utils");
53
53
 
54
54
  // src/device.ts
55
55
  var device = () => {
@@ -83,24 +83,53 @@ var device = () => {
83
83
  };
84
84
 
85
85
  // src/version.ts
86
- var version = "2.3.0";
86
+ var version = "2.4.0";
87
87
 
88
88
  // src/extension.ts
89
89
  var import_core12 = require("@ohbug/core");
90
90
 
91
91
  // src/capture/index.ts
92
- var import_utils16 = require("@ohbug/utils");
92
+ var import_utils17 = require("@ohbug/utils");
93
93
 
94
- // src/capture/action/captureUrlChange.ts
94
+ // src/replaceAddEventListener.ts
95
95
  var import_utils = require("@ohbug/utils");
96
96
  var global = (0, import_utils.getGlobal)();
97
+ var access = "addEventListener" in global;
98
+ var EventTargetProto = EventTarget == null ? void 0 : EventTarget.prototype;
99
+ var EventTargetOriginal = access ? { addEventListener: EventTarget.prototype.addEventListener } : {};
100
+ function replaceAddEventListener() {
101
+ EventTargetProto.addEventListener = (0, import_utils.replace)(
102
+ EventTargetProto,
103
+ "addEventListener",
104
+ (origin) => function call(type, listener4, options) {
105
+ const wrappedListener = function(...args) {
106
+ try {
107
+ return listener4.apply(this, args);
108
+ } catch (err) {
109
+ throw err;
110
+ }
111
+ };
112
+ return origin.call(this, type, wrappedListener, options);
113
+ }
114
+ );
115
+ }
116
+ function removeReplaceAddEventListener() {
117
+ if (access && EventTargetOriginal.addEventListener) {
118
+ const EventTargetProto2 = EventTarget == null ? void 0 : EventTarget.prototype;
119
+ EventTargetProto2.addEventListener = EventTargetOriginal.addEventListener;
120
+ }
121
+ }
122
+
123
+ // src/capture/action/captureUrlChange.ts
124
+ var import_utils2 = require("@ohbug/utils");
125
+ var global2 = (0, import_utils2.getGlobal)();
97
126
  var lastHref;
98
127
  function handleUrlChange(from, to) {
99
128
  var _a2;
100
- const { client } = (0, import_utils.getOhbugObject)();
101
- const parsedHref = (0, import_utils.parseUrl)((_a2 = global == null ? void 0 : global.location) == null ? void 0 : _a2.href);
102
- let parsedFrom = (0, import_utils.parseUrl)(from);
103
- const parsedTo = (0, import_utils.parseUrl)(to);
129
+ const { client } = (0, import_utils2.getOhbugObject)();
130
+ const parsedHref = (0, import_utils2.parseUrl)((_a2 = global2 == null ? void 0 : global2.location) == null ? void 0 : _a2.href);
131
+ let parsedFrom = (0, import_utils2.parseUrl)(from);
132
+ const parsedTo = (0, import_utils2.parseUrl)(to);
104
133
  if (!parsedFrom.path) {
105
134
  parsedFrom = parsedHref;
106
135
  }
@@ -134,27 +163,27 @@ function historyReplacement(original) {
134
163
  }
135
164
  var _a, _b;
136
165
  var historyOriginal = {
137
- pushState: (_a = global == null ? void 0 : global.history) == null ? void 0 : _a.pushState,
138
- replaceState: (_b = global == null ? void 0 : global.history) == null ? void 0 : _b.replaceState,
139
- onpopstate: global == null ? void 0 : global.onpopstate
166
+ pushState: (_a = global2 == null ? void 0 : global2.history) == null ? void 0 : _a.pushState,
167
+ replaceState: (_b = global2 == null ? void 0 : global2.history) == null ? void 0 : _b.replaceState,
168
+ onpopstate: global2 == null ? void 0 : global2.onpopstate
140
169
  };
141
170
  function historyListener() {
142
- historyOriginal.pushState = (0, import_utils.replace)(
143
- global == null ? void 0 : global.history,
171
+ historyOriginal.pushState = (0, import_utils2.replace)(
172
+ global2 == null ? void 0 : global2.history,
144
173
  "pushState",
145
174
  historyReplacement
146
175
  );
147
- historyOriginal.replaceState = (0, import_utils.replace)(
148
- global == null ? void 0 : global.history,
176
+ historyOriginal.replaceState = (0, import_utils2.replace)(
177
+ global2 == null ? void 0 : global2.history,
149
178
  "replaceState",
150
179
  historyReplacement
151
180
  );
152
- historyOriginal.onpopstate = (0, import_utils.replace)(
153
- global,
181
+ historyOriginal.onpopstate = (0, import_utils2.replace)(
182
+ global2,
154
183
  "onpopstate",
155
184
  (origin) => function call(...args) {
156
185
  var _a2;
157
- const current = (_a2 = global == null ? void 0 : global.location) == null ? void 0 : _a2.href;
186
+ const current = (_a2 = global2 == null ? void 0 : global2.location) == null ? void 0 : _a2.href;
158
187
  handleUrlChange(lastHref, current);
159
188
  return origin == null ? void 0 : origin.apply(this, args);
160
189
  }
@@ -167,25 +196,25 @@ function hashListener(e) {
167
196
  function captureUrlChange() {
168
197
  var _a2;
169
198
  historyListener();
170
- (_a2 = global == null ? void 0 : global.addEventListener) == null ? void 0 : _a2.call(global, "hashchange", hashListener, true);
199
+ (_a2 = global2 == null ? void 0 : global2.addEventListener) == null ? void 0 : _a2.call(global2, "hashchange", hashListener, true);
171
200
  }
172
201
  function removeCaptureUrlChange() {
173
202
  var _a2;
174
- global.history.pushState = historyOriginal.pushState;
175
- global.history.replaceState = historyOriginal.replaceState;
176
- global.onpopstate = historyOriginal.onpopstate;
177
- (_a2 = global == null ? void 0 : global.removeEventListener) == null ? void 0 : _a2.call(global, "hashchange", hashListener, true);
203
+ global2.history.pushState = historyOriginal.pushState;
204
+ global2.history.replaceState = historyOriginal.replaceState;
205
+ global2.onpopstate = historyOriginal.onpopstate;
206
+ (_a2 = global2 == null ? void 0 : global2.removeEventListener) == null ? void 0 : _a2.call(global2, "hashchange", hashListener, true);
178
207
  }
179
208
 
180
209
  // src/capture/action/captureClick.ts
181
- var import_utils2 = require("@ohbug/utils");
182
- var global2 = (0, import_utils2.getGlobal)();
210
+ var import_utils3 = require("@ohbug/utils");
211
+ var global3 = (0, import_utils3.getGlobal)();
183
212
  function listener(e) {
184
213
  if (e.target) {
185
- const { client } = (0, import_utils2.getOhbugObject)();
214
+ const { client } = (0, import_utils3.getOhbugObject)();
186
215
  const { tagName, id, className, name, src, nodeType } = e.target;
187
216
  if (tagName.toUpperCase() !== "HTML" && tagName.toUpperCase() !== "BODY") {
188
- const selector = (0, import_utils2.getSelector)(e);
217
+ const selector = (0, import_utils3.getSelector)(e);
189
218
  client.addAction(
190
219
  "click node",
191
220
  {
@@ -204,15 +233,15 @@ function listener(e) {
204
233
  }
205
234
  function captureClick() {
206
235
  var _a2, _b2;
207
- (_b2 = (_a2 = global2 == null ? void 0 : global2.document) == null ? void 0 : _a2.addEventListener) == null ? void 0 : _b2.call(_a2, "click", listener);
236
+ (_b2 = (_a2 = global3 == null ? void 0 : global3.document) == null ? void 0 : _a2.addEventListener) == null ? void 0 : _b2.call(_a2, "click", listener);
208
237
  }
209
238
  function removeCaptureClick() {
210
239
  var _a2, _b2;
211
- (_b2 = (_a2 = global2 == null ? void 0 : global2.document) == null ? void 0 : _a2.removeEventListener) == null ? void 0 : _b2.call(_a2, "click", listener);
240
+ (_b2 = (_a2 = global3 == null ? void 0 : global3.document) == null ? void 0 : _a2.removeEventListener) == null ? void 0 : _b2.call(_a2, "click", listener);
212
241
  }
213
242
 
214
243
  // src/capture/console/captureConsole.ts
215
- var import_utils3 = require("@ohbug/utils");
244
+ var import_utils4 = require("@ohbug/utils");
216
245
  var levels = ["log", "info", "warn", "error"];
217
246
  var consoleOriginal = Object.keys(levels).reduce(
218
247
  (acc, cur) => __spreadProps(__spreadValues({}, acc), {
@@ -226,9 +255,9 @@ var consoleOriginal = Object.keys(levels).reduce(
226
255
  }
227
256
  );
228
257
  function captureConsole() {
229
- const { client } = (0, import_utils3.getOhbugObject)();
258
+ const { client } = (0, import_utils4.getOhbugObject)();
230
259
  levels.forEach((level) => {
231
- consoleOriginal[level] = (0, import_utils3.replace)(
260
+ consoleOriginal[level] = (0, import_utils4.replace)(
232
261
  console,
233
262
  level,
234
263
  (origin) => function call(...args) {
@@ -250,25 +279,25 @@ function removeCaptureConsole() {
250
279
  }
251
280
 
252
281
  // src/capture/network/captureAjaxError.ts
253
- var import_utils11 = require("@ohbug/utils");
282
+ var import_utils12 = require("@ohbug/utils");
254
283
  var import_core9 = require("@ohbug/core");
255
284
 
256
285
  // src/handle/uncaughtErrorHandler.ts
257
- var import_utils4 = require("@ohbug/utils");
286
+ var import_utils5 = require("@ohbug/utils");
258
287
  var import_core = require("@ohbug/core");
259
288
  var import_error_stack_parser = __toESM(require("error-stack-parser"));
260
- function uncaughtErrorHandler(error) {
289
+ function uncaughtErrorHandler(e) {
261
290
  var _a2, _b2, _c;
262
- const [stackFrame] = import_error_stack_parser.default.parse(error.error);
291
+ const [stackFrame] = import_error_stack_parser.default.parse(e.error);
263
292
  const detail = {
264
- name: (_a2 = error == null ? void 0 : error.error) == null ? void 0 : _a2.name,
265
- message: (error == null ? void 0 : error.message) || ((_b2 = error == null ? void 0 : error.error) == null ? void 0 : _b2.message),
266
- filename: (error == null ? void 0 : error.filename) || (stackFrame == null ? void 0 : stackFrame.fileName),
267
- lineno: (error == null ? void 0 : error.lineno) || (stackFrame == null ? void 0 : stackFrame.lineNumber),
268
- colno: (error == null ? void 0 : error.colno) || (stackFrame == null ? void 0 : stackFrame.columnNumber),
269
- stack: (_c = error == null ? void 0 : error.error) == null ? void 0 : _c.stack
293
+ name: (_a2 = e == null ? void 0 : e.error) == null ? void 0 : _a2.name,
294
+ message: (e == null ? void 0 : e.message) || ((_b2 = e == null ? void 0 : e.error) == null ? void 0 : _b2.message),
295
+ filename: (e == null ? void 0 : e.filename) || (stackFrame == null ? void 0 : stackFrame.fileName),
296
+ lineno: (e == null ? void 0 : e.lineno) || (stackFrame == null ? void 0 : stackFrame.lineNumber),
297
+ colno: (e == null ? void 0 : e.colno) || (stackFrame == null ? void 0 : stackFrame.columnNumber),
298
+ stack: (_c = e == null ? void 0 : e.error) == null ? void 0 : _c.stack
270
299
  };
271
- const { client } = (0, import_utils4.getOhbugObject)();
300
+ const { client } = (0, import_utils5.getOhbugObject)();
272
301
  const event = client.createEvent({
273
302
  category: "error",
274
303
  type: import_core.EventTypes.UNCAUGHT_ERROR,
@@ -278,11 +307,11 @@ function uncaughtErrorHandler(error) {
278
307
  }
279
308
 
280
309
  // src/handle/resourceErrorHandler.ts
281
- var import_utils5 = require("@ohbug/utils");
310
+ var import_utils6 = require("@ohbug/utils");
282
311
  var import_core2 = require("@ohbug/core");
283
- function resourceErrorHandler(error) {
284
- const target = error.target || error.srcElement;
285
- const selector = (0, import_utils5.getSelector)(error);
312
+ function resourceErrorHandler(e) {
313
+ const target = e.target || e.srcElement;
314
+ const selector = (0, import_utils6.getSelector)(e);
286
315
  const detail = {
287
316
  src: target && target.src,
288
317
  tagName: target && target.tagName,
@@ -292,7 +321,7 @@ function resourceErrorHandler(error) {
292
321
  nodeType: target && target.nodeType,
293
322
  selector
294
323
  };
295
- const { client } = (0, import_utils5.getOhbugObject)();
324
+ const { client } = (0, import_utils6.getOhbugObject)();
296
325
  const event = client.createEvent({
297
326
  category: "error",
298
327
  type: import_core2.EventTypes.RESOURCE_ERROR,
@@ -302,21 +331,21 @@ function resourceErrorHandler(error) {
302
331
  }
303
332
 
304
333
  // src/handle/unhandledrejectionErrorHandler.ts
305
- var import_utils6 = require("@ohbug/utils");
334
+ var import_utils7 = require("@ohbug/utils");
306
335
  var import_core3 = require("@ohbug/core");
307
336
  var import_error_stack_parser2 = __toESM(require("error-stack-parser"));
308
- function unhandledrejectionErrorHandler(error) {
337
+ function unhandledrejectionErrorHandler(e) {
309
338
  var _a2, _b2, _c;
310
- const [stackFrame] = import_error_stack_parser2.default.parse(error.reason);
339
+ const [stackFrame] = import_error_stack_parser2.default.parse(e.reason);
311
340
  const detail = {
312
- name: (_a2 = error == null ? void 0 : error.reason) == null ? void 0 : _a2.name,
313
- message: ((_b2 = error == null ? void 0 : error.reason) == null ? void 0 : _b2.message) || (error == null ? void 0 : error.reason),
341
+ name: (_a2 = e == null ? void 0 : e.reason) == null ? void 0 : _a2.name,
342
+ message: ((_b2 = e == null ? void 0 : e.reason) == null ? void 0 : _b2.message) || (e == null ? void 0 : e.reason),
314
343
  filename: stackFrame == null ? void 0 : stackFrame.fileName,
315
344
  lineno: stackFrame == null ? void 0 : stackFrame.lineNumber,
316
345
  colno: stackFrame == null ? void 0 : stackFrame.columnNumber,
317
- stack: (_c = error == null ? void 0 : error.reason) == null ? void 0 : _c.stack
346
+ stack: (_c = e == null ? void 0 : e.reason) == null ? void 0 : _c.stack
318
347
  };
319
- const { client } = (0, import_utils6.getOhbugObject)();
348
+ const { client } = (0, import_utils7.getOhbugObject)();
320
349
  const event = client.createEvent({
321
350
  category: "error",
322
351
  type: import_core3.EventTypes.UNHANDLEDREJECTION_ERROR,
@@ -326,11 +355,21 @@ function unhandledrejectionErrorHandler(error) {
326
355
  }
327
356
 
328
357
  // src/handle/unknownErrorHandler.ts
329
- var import_utils7 = require("@ohbug/utils");
358
+ var import_utils8 = require("@ohbug/utils");
330
359
  var import_core4 = require("@ohbug/core");
331
- function unknownErrorHandler(error) {
332
- const detail = error.message ? error : { message: error };
333
- const { client } = (0, import_utils7.getOhbugObject)();
360
+ var import_error_stack_parser3 = __toESM(require("error-stack-parser"));
361
+ function unknownErrorHandler(e) {
362
+ var _a2, _b2, _c;
363
+ const [stackFrame] = import_error_stack_parser3.default.parse(e.error);
364
+ const detail = {
365
+ name: (_a2 = e == null ? void 0 : e.error) == null ? void 0 : _a2.name,
366
+ message: (e == null ? void 0 : e.message) || ((_b2 = e == null ? void 0 : e.error) == null ? void 0 : _b2.message),
367
+ filename: (e == null ? void 0 : e.filename) || (stackFrame == null ? void 0 : stackFrame.fileName),
368
+ lineno: (e == null ? void 0 : e.lineno) || (stackFrame == null ? void 0 : stackFrame.lineNumber),
369
+ colno: (e == null ? void 0 : e.colno) || (stackFrame == null ? void 0 : stackFrame.columnNumber),
370
+ stack: (_c = e == null ? void 0 : e.error) == null ? void 0 : _c.stack
371
+ };
372
+ const { client } = (0, import_utils8.getOhbugObject)();
334
373
  const event = client.createEvent({
335
374
  category: "error",
336
375
  type: import_core4.EventTypes.UNKNOWN_ERROR,
@@ -340,10 +379,10 @@ function unknownErrorHandler(error) {
340
379
  }
341
380
 
342
381
  // src/handle/ajaxErrorHandler.ts
343
- var import_utils8 = require("@ohbug/utils");
382
+ var import_utils9 = require("@ohbug/utils");
344
383
  var import_core5 = require("@ohbug/core");
345
384
  function ajaxErrorHandler(detail) {
346
- const { client } = (0, import_utils8.getOhbugObject)();
385
+ const { client } = (0, import_utils9.getOhbugObject)();
347
386
  const event = client.createEvent({
348
387
  category: "error",
349
388
  type: import_core5.EventTypes.AJAX_ERROR,
@@ -353,10 +392,10 @@ function ajaxErrorHandler(detail) {
353
392
  }
354
393
 
355
394
  // src/handle/fetchErrorHandler.ts
356
- var import_utils9 = require("@ohbug/utils");
395
+ var import_utils10 = require("@ohbug/utils");
357
396
  var import_core6 = require("@ohbug/core");
358
397
  function fetchErrorHandler(detail) {
359
- const { client } = (0, import_utils9.getOhbugObject)();
398
+ const { client } = (0, import_utils10.getOhbugObject)();
360
399
  const event = client.createEvent({
361
400
  category: "error",
362
401
  type: import_core6.EventTypes.FETCH_ERROR,
@@ -366,10 +405,10 @@ function fetchErrorHandler(detail) {
366
405
  }
367
406
 
368
407
  // src/handle/websocketErrorHandler.ts
369
- var import_utils10 = require("@ohbug/utils");
408
+ var import_utils11 = require("@ohbug/utils");
370
409
  var import_core7 = require("@ohbug/core");
371
410
  function websocketErrorHandler(detail) {
372
- const { client } = (0, import_utils10.getOhbugObject)();
411
+ const { client } = (0, import_utils11.getOhbugObject)();
373
412
  const event = client.createEvent({
374
413
  category: "error",
375
414
  type: import_core7.EventTypes.WEBSOCKET_ERROR,
@@ -424,22 +463,22 @@ function networkDispatcher(type, detail) {
424
463
  }
425
464
 
426
465
  // src/capture/network/captureAjaxError.ts
427
- var global3 = (0, import_utils11.getGlobal)();
428
- var access = "XMLHttpRequest" in global3;
429
- var xhrOriginal = access ? {
466
+ var global4 = (0, import_utils12.getGlobal)();
467
+ var access2 = "XMLHttpRequest" in global4;
468
+ var xhrOriginal = access2 ? {
430
469
  open: XMLHttpRequest.prototype.open,
431
470
  send: XMLHttpRequest.prototype.send
432
471
  } : {};
433
472
  function captureAjaxError() {
434
- if (!access)
473
+ if (!access2)
435
474
  return;
436
- const { client } = (0, import_utils11.getOhbugObject)();
475
+ const { client } = (0, import_utils12.getOhbugObject)();
437
476
  const desc = {
438
477
  method: "",
439
478
  url: ""
440
479
  };
441
480
  const xhrProto = XMLHttpRequest == null ? void 0 : XMLHttpRequest.prototype;
442
- xhrOriginal.open = (0, import_utils11.replace)(
481
+ xhrOriginal.open = (0, import_utils12.replace)(
443
482
  xhrProto,
444
483
  "open",
445
484
  (origin) => function call(...args) {
@@ -449,7 +488,7 @@ function captureAjaxError() {
449
488
  return origin.apply(this, args);
450
489
  }
451
490
  );
452
- xhrOriginal.send = (0, import_utils11.replace)(
491
+ xhrOriginal.send = (0, import_utils12.replace)(
453
492
  xhrProto,
454
493
  "send",
455
494
  (origin) => function call(...args) {
@@ -474,7 +513,7 @@ function captureAjaxError() {
474
513
  );
475
514
  }
476
515
  function removeCaptureAjaxError() {
477
- if (access && xhrOriginal.open && xhrOriginal.send) {
516
+ if (access2 && xhrOriginal.open && xhrOriginal.send) {
478
517
  const xhrProto = XMLHttpRequest == null ? void 0 : XMLHttpRequest.prototype;
479
518
  xhrProto.open = xhrOriginal.open;
480
519
  xhrProto.send = xhrOriginal.send;
@@ -482,17 +521,17 @@ function removeCaptureAjaxError() {
482
521
  }
483
522
 
484
523
  // src/capture/network/captureFetchError.ts
485
- var import_utils12 = require("@ohbug/utils");
524
+ var import_utils13 = require("@ohbug/utils");
486
525
  var import_core10 = require("@ohbug/core");
487
- var global4 = (0, import_utils12.getGlobal)();
488
- var access2 = "fetch" in global4;
489
- var fetchOriginal = access2 ? global4.fetch : null;
526
+ var global5 = (0, import_utils13.getGlobal)();
527
+ var access3 = "fetch" in global5;
528
+ var fetchOriginal = access3 ? global5.fetch : null;
490
529
  function captureFetchError() {
491
- if (!access2)
530
+ if (!access3)
492
531
  return;
493
- const { client } = (0, import_utils12.getOhbugObject)();
494
- fetchOriginal = (0, import_utils12.replace)(
495
- global4,
532
+ const { client } = (0, import_utils13.getOhbugObject)();
533
+ fetchOriginal = (0, import_utils13.replace)(
534
+ global5,
496
535
  "fetch",
497
536
  (origin) => function call(...args) {
498
537
  return origin.apply(this, args).then(
@@ -526,17 +565,17 @@ function captureFetchError() {
526
565
  );
527
566
  }
528
567
  function removeCaptureFetchError() {
529
- if (access2 && fetchOriginal) {
530
- global4.fetch = fetchOriginal;
568
+ if (access3 && fetchOriginal) {
569
+ global5.fetch = fetchOriginal;
531
570
  }
532
571
  }
533
572
 
534
573
  // src/capture/network/captureWebSocketError.ts
535
- var import_utils13 = require("@ohbug/utils");
574
+ var import_utils14 = require("@ohbug/utils");
536
575
  var import_core11 = require("@ohbug/core");
537
- var global5 = (0, import_utils13.getGlobal)();
576
+ var global6 = (0, import_utils14.getGlobal)();
538
577
  function captureWebSocketError() {
539
- if (!("WebSocket" in global5))
578
+ if (!("WebSocket" in global6))
540
579
  return;
541
580
  const wsProto = WebSocket == null ? void 0 : WebSocket.prototype;
542
581
  const backup = Object.getOwnPropertyDescriptor(wsProto, "onerror");
@@ -566,33 +605,33 @@ function captureWebSocketError() {
566
605
  }
567
606
 
568
607
  // src/capture/script/captureUncaughtError.ts
569
- var import_utils14 = require("@ohbug/utils");
570
- var global6 = (0, import_utils14.getGlobal)();
608
+ var import_utils15 = require("@ohbug/utils");
609
+ var global7 = (0, import_utils15.getGlobal)();
571
610
  function listener2(e) {
572
611
  scriptDispatcher(e);
573
612
  }
574
613
  function captureUncaughtError() {
575
614
  var _a2;
576
- (_a2 = global6 == null ? void 0 : global6.addEventListener) == null ? void 0 : _a2.call(global6, "error", listener2, true);
615
+ (_a2 = global7 == null ? void 0 : global7.addEventListener) == null ? void 0 : _a2.call(global7, "error", listener2, true);
577
616
  }
578
617
  function removeCaptureUncaughtError() {
579
618
  var _a2;
580
- (_a2 = global6 == null ? void 0 : global6.removeEventListener) == null ? void 0 : _a2.call(global6, "error", listener2, true);
619
+ (_a2 = global7 == null ? void 0 : global7.removeEventListener) == null ? void 0 : _a2.call(global7, "error", listener2, true);
581
620
  }
582
621
 
583
622
  // src/capture/script/captureUnhandledrejectionError.ts
584
- var import_utils15 = require("@ohbug/utils");
585
- var global7 = (0, import_utils15.getGlobal)();
623
+ var import_utils16 = require("@ohbug/utils");
624
+ var global8 = (0, import_utils16.getGlobal)();
586
625
  function listener3(e) {
587
626
  scriptDispatcher(e);
588
627
  }
589
628
  function captureUnhandledrejectionError() {
590
629
  var _a2;
591
- (_a2 = global7 == null ? void 0 : global7.addEventListener) == null ? void 0 : _a2.call(global7, "unhandledrejection", listener3, true);
630
+ (_a2 = global8 == null ? void 0 : global8.addEventListener) == null ? void 0 : _a2.call(global8, "unhandledrejection", listener3, true);
592
631
  }
593
632
  function removeCaptureUnhandledrejectionError() {
594
633
  var _a2;
595
- (_a2 = global7 == null ? void 0 : global7.removeEventListener) == null ? void 0 : _a2.call(global7, "unhandledrejection", listener3, true);
634
+ (_a2 = global8 == null ? void 0 : global8.removeEventListener) == null ? void 0 : _a2.call(global8, "unhandledrejection", listener3, true);
596
635
  }
597
636
 
598
637
  // src/capture/index.ts
@@ -614,8 +653,8 @@ function removeCaptureNetwork() {
614
653
  removeCaptureFetchError();
615
654
  }
616
655
  function captureScript() {
617
- const global9 = (0, import_utils16.getGlobal)();
618
- if (!global9.addEventListener)
656
+ const global10 = (0, import_utils17.getGlobal)();
657
+ if (!global10.addEventListener)
619
658
  return;
620
659
  captureUncaughtError();
621
660
  captureUnhandledrejectionError();
@@ -625,6 +664,7 @@ function removeCaptureScript() {
625
664
  removeCaptureUnhandledrejectionError();
626
665
  }
627
666
  function handleCapture() {
667
+ replaceAddEventListener();
628
668
  captureScript();
629
669
  captureNetwork();
630
670
  captureAction();
@@ -632,14 +672,15 @@ function handleCapture() {
632
672
  }
633
673
 
634
674
  // src/destroy.ts
635
- var import_utils17 = require("@ohbug/utils");
636
- var global8 = (0, import_utils17.getGlobal)();
675
+ var import_utils18 = require("@ohbug/utils");
676
+ var global9 = (0, import_utils18.getGlobal)();
637
677
  function handleDestroy() {
638
678
  var _a2;
639
- (_a2 = global8 == null ? void 0 : global8.addEventListener) == null ? void 0 : _a2.call(
640
- global8,
679
+ (_a2 = global9 == null ? void 0 : global9.addEventListener) == null ? void 0 : _a2.call(
680
+ global9,
641
681
  "unload",
642
682
  () => {
683
+ removeReplaceAddEventListener();
643
684
  removeCaptureScript();
644
685
  removeCaptureNetwork();
645
686
  removeCaptureAction();
@@ -659,7 +700,7 @@ var extension = (0, import_core12.defineExtension)({
659
700
  });
660
701
 
661
702
  // src/notifier.ts
662
- var import_utils18 = require("@ohbug/utils");
703
+ var import_utils19 = require("@ohbug/utils");
663
704
  var getCircularReplacer = () => {
664
705
  const seen = /* @__PURE__ */ new WeakSet();
665
706
  return (_, value) => {
@@ -673,7 +714,7 @@ var getCircularReplacer = () => {
673
714
  };
674
715
  };
675
716
  function notifier(event) {
676
- const { client } = (0, import_utils18.getOhbugObject)();
717
+ const { client } = (0, import_utils19.getOhbugObject)();
677
718
  const url = client.__config.endpoint;
678
719
  return new Promise((resolve, reject) => {
679
720
  const json = JSON.stringify(event, getCircularReplacer());
@@ -699,13 +740,13 @@ function notifier(event) {
699
740
 
700
741
  // src/client.ts
701
742
  function createClient(config) {
702
- const global9 = (0, import_utils19.getGlobal)();
743
+ const global10 = (0, import_utils20.getGlobal)();
703
744
  const sdk = {
704
745
  platform: "ohbug-browser",
705
746
  version
706
747
  };
707
748
  const client = new import_core13.Client({ sdk, config, device, notifier });
708
- global9.__OHBUG__ = { client };
749
+ global10.__OHBUG__ = { client };
709
750
  client.use(extension);
710
751
  client.__logger.info(
711
752
  `%c @ohbug/browser %c Detected Ohbug v${version} %c`,
package/dist/index.mjs CHANGED
@@ -20,7 +20,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
20
 
21
21
  // src/client.ts
22
22
  import { Client } from "@ohbug/core";
23
- import { getGlobal as getGlobal10 } from "@ohbug/utils";
23
+ import { getGlobal as getGlobal11 } from "@ohbug/utils";
24
24
 
25
25
  // src/device.ts
26
26
  var device = () => {
@@ -54,22 +54,51 @@ var device = () => {
54
54
  };
55
55
 
56
56
  // src/version.ts
57
- var version = "2.3.0";
57
+ var version = "2.4.0";
58
58
 
59
59
  // src/extension.ts
60
60
  import { defineExtension } from "@ohbug/core";
61
61
 
62
62
  // src/capture/index.ts
63
- import { getGlobal as getGlobal8 } from "@ohbug/utils";
63
+ import { getGlobal as getGlobal9 } from "@ohbug/utils";
64
64
 
65
- // src/capture/action/captureUrlChange.ts
66
- import { getGlobal, getOhbugObject, parseUrl, replace } from "@ohbug/utils";
65
+ // src/replaceAddEventListener.ts
66
+ import { getGlobal, replace } from "@ohbug/utils";
67
67
  var global = getGlobal();
68
+ var access = "addEventListener" in global;
69
+ var EventTargetProto = EventTarget == null ? void 0 : EventTarget.prototype;
70
+ var EventTargetOriginal = access ? { addEventListener: EventTarget.prototype.addEventListener } : {};
71
+ function replaceAddEventListener() {
72
+ EventTargetProto.addEventListener = replace(
73
+ EventTargetProto,
74
+ "addEventListener",
75
+ (origin) => function call(type, listener4, options) {
76
+ const wrappedListener = function(...args) {
77
+ try {
78
+ return listener4.apply(this, args);
79
+ } catch (err) {
80
+ throw err;
81
+ }
82
+ };
83
+ return origin.call(this, type, wrappedListener, options);
84
+ }
85
+ );
86
+ }
87
+ function removeReplaceAddEventListener() {
88
+ if (access && EventTargetOriginal.addEventListener) {
89
+ const EventTargetProto2 = EventTarget == null ? void 0 : EventTarget.prototype;
90
+ EventTargetProto2.addEventListener = EventTargetOriginal.addEventListener;
91
+ }
92
+ }
93
+
94
+ // src/capture/action/captureUrlChange.ts
95
+ import { getGlobal as getGlobal2, getOhbugObject, parseUrl, replace as replace2 } from "@ohbug/utils";
96
+ var global2 = getGlobal2();
68
97
  var lastHref;
69
98
  function handleUrlChange(from, to) {
70
99
  var _a2;
71
100
  const { client } = getOhbugObject();
72
- const parsedHref = parseUrl((_a2 = global == null ? void 0 : global.location) == null ? void 0 : _a2.href);
101
+ const parsedHref = parseUrl((_a2 = global2 == null ? void 0 : global2.location) == null ? void 0 : _a2.href);
73
102
  let parsedFrom = parseUrl(from);
74
103
  const parsedTo = parseUrl(to);
75
104
  if (!parsedFrom.path) {
@@ -105,27 +134,27 @@ function historyReplacement(original) {
105
134
  }
106
135
  var _a, _b;
107
136
  var historyOriginal = {
108
- pushState: (_a = global == null ? void 0 : global.history) == null ? void 0 : _a.pushState,
109
- replaceState: (_b = global == null ? void 0 : global.history) == null ? void 0 : _b.replaceState,
110
- onpopstate: global == null ? void 0 : global.onpopstate
137
+ pushState: (_a = global2 == null ? void 0 : global2.history) == null ? void 0 : _a.pushState,
138
+ replaceState: (_b = global2 == null ? void 0 : global2.history) == null ? void 0 : _b.replaceState,
139
+ onpopstate: global2 == null ? void 0 : global2.onpopstate
111
140
  };
112
141
  function historyListener() {
113
- historyOriginal.pushState = replace(
114
- global == null ? void 0 : global.history,
142
+ historyOriginal.pushState = replace2(
143
+ global2 == null ? void 0 : global2.history,
115
144
  "pushState",
116
145
  historyReplacement
117
146
  );
118
- historyOriginal.replaceState = replace(
119
- global == null ? void 0 : global.history,
147
+ historyOriginal.replaceState = replace2(
148
+ global2 == null ? void 0 : global2.history,
120
149
  "replaceState",
121
150
  historyReplacement
122
151
  );
123
- historyOriginal.onpopstate = replace(
124
- global,
152
+ historyOriginal.onpopstate = replace2(
153
+ global2,
125
154
  "onpopstate",
126
155
  (origin) => function call(...args) {
127
156
  var _a2;
128
- const current = (_a2 = global == null ? void 0 : global.location) == null ? void 0 : _a2.href;
157
+ const current = (_a2 = global2 == null ? void 0 : global2.location) == null ? void 0 : _a2.href;
129
158
  handleUrlChange(lastHref, current);
130
159
  return origin == null ? void 0 : origin.apply(this, args);
131
160
  }
@@ -138,19 +167,19 @@ function hashListener(e) {
138
167
  function captureUrlChange() {
139
168
  var _a2;
140
169
  historyListener();
141
- (_a2 = global == null ? void 0 : global.addEventListener) == null ? void 0 : _a2.call(global, "hashchange", hashListener, true);
170
+ (_a2 = global2 == null ? void 0 : global2.addEventListener) == null ? void 0 : _a2.call(global2, "hashchange", hashListener, true);
142
171
  }
143
172
  function removeCaptureUrlChange() {
144
173
  var _a2;
145
- global.history.pushState = historyOriginal.pushState;
146
- global.history.replaceState = historyOriginal.replaceState;
147
- global.onpopstate = historyOriginal.onpopstate;
148
- (_a2 = global == null ? void 0 : global.removeEventListener) == null ? void 0 : _a2.call(global, "hashchange", hashListener, true);
174
+ global2.history.pushState = historyOriginal.pushState;
175
+ global2.history.replaceState = historyOriginal.replaceState;
176
+ global2.onpopstate = historyOriginal.onpopstate;
177
+ (_a2 = global2 == null ? void 0 : global2.removeEventListener) == null ? void 0 : _a2.call(global2, "hashchange", hashListener, true);
149
178
  }
150
179
 
151
180
  // src/capture/action/captureClick.ts
152
- import { getGlobal as getGlobal2, getOhbugObject as getOhbugObject2, getSelector } from "@ohbug/utils";
153
- var global2 = getGlobal2();
181
+ import { getGlobal as getGlobal3, getOhbugObject as getOhbugObject2, getSelector } from "@ohbug/utils";
182
+ var global3 = getGlobal3();
154
183
  function listener(e) {
155
184
  if (e.target) {
156
185
  const { client } = getOhbugObject2();
@@ -175,15 +204,15 @@ function listener(e) {
175
204
  }
176
205
  function captureClick() {
177
206
  var _a2, _b2;
178
- (_b2 = (_a2 = global2 == null ? void 0 : global2.document) == null ? void 0 : _a2.addEventListener) == null ? void 0 : _b2.call(_a2, "click", listener);
207
+ (_b2 = (_a2 = global3 == null ? void 0 : global3.document) == null ? void 0 : _a2.addEventListener) == null ? void 0 : _b2.call(_a2, "click", listener);
179
208
  }
180
209
  function removeCaptureClick() {
181
210
  var _a2, _b2;
182
- (_b2 = (_a2 = global2 == null ? void 0 : global2.document) == null ? void 0 : _a2.removeEventListener) == null ? void 0 : _b2.call(_a2, "click", listener);
211
+ (_b2 = (_a2 = global3 == null ? void 0 : global3.document) == null ? void 0 : _a2.removeEventListener) == null ? void 0 : _b2.call(_a2, "click", listener);
183
212
  }
184
213
 
185
214
  // src/capture/console/captureConsole.ts
186
- import { getOhbugObject as getOhbugObject3, replace as replace2 } from "@ohbug/utils";
215
+ import { getOhbugObject as getOhbugObject3, replace as replace3 } from "@ohbug/utils";
187
216
  var levels = ["log", "info", "warn", "error"];
188
217
  var consoleOriginal = Object.keys(levels).reduce(
189
218
  (acc, cur) => __spreadProps(__spreadValues({}, acc), {
@@ -199,7 +228,7 @@ var consoleOriginal = Object.keys(levels).reduce(
199
228
  function captureConsole() {
200
229
  const { client } = getOhbugObject3();
201
230
  levels.forEach((level) => {
202
- consoleOriginal[level] = replace2(
231
+ consoleOriginal[level] = replace3(
203
232
  console,
204
233
  level,
205
234
  (origin) => function call(...args) {
@@ -221,23 +250,23 @@ function removeCaptureConsole() {
221
250
  }
222
251
 
223
252
  // src/capture/network/captureAjaxError.ts
224
- import { getGlobal as getGlobal3, getOhbugObject as getOhbugObject11, replace as replace3 } from "@ohbug/utils";
253
+ import { getGlobal as getGlobal4, getOhbugObject as getOhbugObject11, replace as replace4 } from "@ohbug/utils";
225
254
  import { EventTypes as EventTypes9 } from "@ohbug/core";
226
255
 
227
256
  // src/handle/uncaughtErrorHandler.ts
228
257
  import { getOhbugObject as getOhbugObject4 } from "@ohbug/utils";
229
258
  import { EventTypes } from "@ohbug/core";
230
259
  import ErrorStackParser from "error-stack-parser";
231
- function uncaughtErrorHandler(error) {
260
+ function uncaughtErrorHandler(e) {
232
261
  var _a2, _b2, _c;
233
- const [stackFrame] = ErrorStackParser.parse(error.error);
262
+ const [stackFrame] = ErrorStackParser.parse(e.error);
234
263
  const detail = {
235
- name: (_a2 = error == null ? void 0 : error.error) == null ? void 0 : _a2.name,
236
- message: (error == null ? void 0 : error.message) || ((_b2 = error == null ? void 0 : error.error) == null ? void 0 : _b2.message),
237
- filename: (error == null ? void 0 : error.filename) || (stackFrame == null ? void 0 : stackFrame.fileName),
238
- lineno: (error == null ? void 0 : error.lineno) || (stackFrame == null ? void 0 : stackFrame.lineNumber),
239
- colno: (error == null ? void 0 : error.colno) || (stackFrame == null ? void 0 : stackFrame.columnNumber),
240
- stack: (_c = error == null ? void 0 : error.error) == null ? void 0 : _c.stack
264
+ name: (_a2 = e == null ? void 0 : e.error) == null ? void 0 : _a2.name,
265
+ message: (e == null ? void 0 : e.message) || ((_b2 = e == null ? void 0 : e.error) == null ? void 0 : _b2.message),
266
+ filename: (e == null ? void 0 : e.filename) || (stackFrame == null ? void 0 : stackFrame.fileName),
267
+ lineno: (e == null ? void 0 : e.lineno) || (stackFrame == null ? void 0 : stackFrame.lineNumber),
268
+ colno: (e == null ? void 0 : e.colno) || (stackFrame == null ? void 0 : stackFrame.columnNumber),
269
+ stack: (_c = e == null ? void 0 : e.error) == null ? void 0 : _c.stack
241
270
  };
242
271
  const { client } = getOhbugObject4();
243
272
  const event = client.createEvent({
@@ -251,9 +280,9 @@ function uncaughtErrorHandler(error) {
251
280
  // src/handle/resourceErrorHandler.ts
252
281
  import { getOhbugObject as getOhbugObject5, getSelector as getSelector2 } from "@ohbug/utils";
253
282
  import { EventTypes as EventTypes2 } from "@ohbug/core";
254
- function resourceErrorHandler(error) {
255
- const target = error.target || error.srcElement;
256
- const selector = getSelector2(error);
283
+ function resourceErrorHandler(e) {
284
+ const target = e.target || e.srcElement;
285
+ const selector = getSelector2(e);
257
286
  const detail = {
258
287
  src: target && target.src,
259
288
  tagName: target && target.tagName,
@@ -276,16 +305,16 @@ function resourceErrorHandler(error) {
276
305
  import { getOhbugObject as getOhbugObject6 } from "@ohbug/utils";
277
306
  import { EventTypes as EventTypes3 } from "@ohbug/core";
278
307
  import ErrorStackParser2 from "error-stack-parser";
279
- function unhandledrejectionErrorHandler(error) {
308
+ function unhandledrejectionErrorHandler(e) {
280
309
  var _a2, _b2, _c;
281
- const [stackFrame] = ErrorStackParser2.parse(error.reason);
310
+ const [stackFrame] = ErrorStackParser2.parse(e.reason);
282
311
  const detail = {
283
- name: (_a2 = error == null ? void 0 : error.reason) == null ? void 0 : _a2.name,
284
- message: ((_b2 = error == null ? void 0 : error.reason) == null ? void 0 : _b2.message) || (error == null ? void 0 : error.reason),
312
+ name: (_a2 = e == null ? void 0 : e.reason) == null ? void 0 : _a2.name,
313
+ message: ((_b2 = e == null ? void 0 : e.reason) == null ? void 0 : _b2.message) || (e == null ? void 0 : e.reason),
285
314
  filename: stackFrame == null ? void 0 : stackFrame.fileName,
286
315
  lineno: stackFrame == null ? void 0 : stackFrame.lineNumber,
287
316
  colno: stackFrame == null ? void 0 : stackFrame.columnNumber,
288
- stack: (_c = error == null ? void 0 : error.reason) == null ? void 0 : _c.stack
317
+ stack: (_c = e == null ? void 0 : e.reason) == null ? void 0 : _c.stack
289
318
  };
290
319
  const { client } = getOhbugObject6();
291
320
  const event = client.createEvent({
@@ -299,8 +328,18 @@ function unhandledrejectionErrorHandler(error) {
299
328
  // src/handle/unknownErrorHandler.ts
300
329
  import { getOhbugObject as getOhbugObject7 } from "@ohbug/utils";
301
330
  import { EventTypes as EventTypes4 } from "@ohbug/core";
302
- function unknownErrorHandler(error) {
303
- const detail = error.message ? error : { message: error };
331
+ import ErrorStackParser3 from "error-stack-parser";
332
+ function unknownErrorHandler(e) {
333
+ var _a2, _b2, _c;
334
+ const [stackFrame] = ErrorStackParser3.parse(e.error);
335
+ const detail = {
336
+ name: (_a2 = e == null ? void 0 : e.error) == null ? void 0 : _a2.name,
337
+ message: (e == null ? void 0 : e.message) || ((_b2 = e == null ? void 0 : e.error) == null ? void 0 : _b2.message),
338
+ filename: (e == null ? void 0 : e.filename) || (stackFrame == null ? void 0 : stackFrame.fileName),
339
+ lineno: (e == null ? void 0 : e.lineno) || (stackFrame == null ? void 0 : stackFrame.lineNumber),
340
+ colno: (e == null ? void 0 : e.colno) || (stackFrame == null ? void 0 : stackFrame.columnNumber),
341
+ stack: (_c = e == null ? void 0 : e.error) == null ? void 0 : _c.stack
342
+ };
304
343
  const { client } = getOhbugObject7();
305
344
  const event = client.createEvent({
306
345
  category: "error",
@@ -395,14 +434,14 @@ function networkDispatcher(type, detail) {
395
434
  }
396
435
 
397
436
  // src/capture/network/captureAjaxError.ts
398
- var global3 = getGlobal3();
399
- var access = "XMLHttpRequest" in global3;
400
- var xhrOriginal = access ? {
437
+ var global4 = getGlobal4();
438
+ var access2 = "XMLHttpRequest" in global4;
439
+ var xhrOriginal = access2 ? {
401
440
  open: XMLHttpRequest.prototype.open,
402
441
  send: XMLHttpRequest.prototype.send
403
442
  } : {};
404
443
  function captureAjaxError() {
405
- if (!access)
444
+ if (!access2)
406
445
  return;
407
446
  const { client } = getOhbugObject11();
408
447
  const desc = {
@@ -410,7 +449,7 @@ function captureAjaxError() {
410
449
  url: ""
411
450
  };
412
451
  const xhrProto = XMLHttpRequest == null ? void 0 : XMLHttpRequest.prototype;
413
- xhrOriginal.open = replace3(
452
+ xhrOriginal.open = replace4(
414
453
  xhrProto,
415
454
  "open",
416
455
  (origin) => function call(...args) {
@@ -420,7 +459,7 @@ function captureAjaxError() {
420
459
  return origin.apply(this, args);
421
460
  }
422
461
  );
423
- xhrOriginal.send = replace3(
462
+ xhrOriginal.send = replace4(
424
463
  xhrProto,
425
464
  "send",
426
465
  (origin) => function call(...args) {
@@ -445,7 +484,7 @@ function captureAjaxError() {
445
484
  );
446
485
  }
447
486
  function removeCaptureAjaxError() {
448
- if (access && xhrOriginal.open && xhrOriginal.send) {
487
+ if (access2 && xhrOriginal.open && xhrOriginal.send) {
449
488
  const xhrProto = XMLHttpRequest == null ? void 0 : XMLHttpRequest.prototype;
450
489
  xhrProto.open = xhrOriginal.open;
451
490
  xhrProto.send = xhrOriginal.send;
@@ -453,17 +492,17 @@ function removeCaptureAjaxError() {
453
492
  }
454
493
 
455
494
  // src/capture/network/captureFetchError.ts
456
- import { getGlobal as getGlobal4, getOhbugObject as getOhbugObject12, replace as replace4 } from "@ohbug/utils";
495
+ import { getGlobal as getGlobal5, getOhbugObject as getOhbugObject12, replace as replace5 } from "@ohbug/utils";
457
496
  import { EventTypes as EventTypes10 } from "@ohbug/core";
458
- var global4 = getGlobal4();
459
- var access2 = "fetch" in global4;
460
- var fetchOriginal = access2 ? global4.fetch : null;
497
+ var global5 = getGlobal5();
498
+ var access3 = "fetch" in global5;
499
+ var fetchOriginal = access3 ? global5.fetch : null;
461
500
  function captureFetchError() {
462
- if (!access2)
501
+ if (!access3)
463
502
  return;
464
503
  const { client } = getOhbugObject12();
465
- fetchOriginal = replace4(
466
- global4,
504
+ fetchOriginal = replace5(
505
+ global5,
467
506
  "fetch",
468
507
  (origin) => function call(...args) {
469
508
  return origin.apply(this, args).then(
@@ -497,17 +536,17 @@ function captureFetchError() {
497
536
  );
498
537
  }
499
538
  function removeCaptureFetchError() {
500
- if (access2 && fetchOriginal) {
501
- global4.fetch = fetchOriginal;
539
+ if (access3 && fetchOriginal) {
540
+ global5.fetch = fetchOriginal;
502
541
  }
503
542
  }
504
543
 
505
544
  // src/capture/network/captureWebSocketError.ts
506
- import { getGlobal as getGlobal5 } from "@ohbug/utils";
545
+ import { getGlobal as getGlobal6 } from "@ohbug/utils";
507
546
  import { EventTypes as EventTypes11 } from "@ohbug/core";
508
- var global5 = getGlobal5();
547
+ var global6 = getGlobal6();
509
548
  function captureWebSocketError() {
510
- if (!("WebSocket" in global5))
549
+ if (!("WebSocket" in global6))
511
550
  return;
512
551
  const wsProto = WebSocket == null ? void 0 : WebSocket.prototype;
513
552
  const backup = Object.getOwnPropertyDescriptor(wsProto, "onerror");
@@ -537,33 +576,33 @@ function captureWebSocketError() {
537
576
  }
538
577
 
539
578
  // src/capture/script/captureUncaughtError.ts
540
- import { getGlobal as getGlobal6 } from "@ohbug/utils";
541
- var global6 = getGlobal6();
579
+ import { getGlobal as getGlobal7 } from "@ohbug/utils";
580
+ var global7 = getGlobal7();
542
581
  function listener2(e) {
543
582
  scriptDispatcher(e);
544
583
  }
545
584
  function captureUncaughtError() {
546
585
  var _a2;
547
- (_a2 = global6 == null ? void 0 : global6.addEventListener) == null ? void 0 : _a2.call(global6, "error", listener2, true);
586
+ (_a2 = global7 == null ? void 0 : global7.addEventListener) == null ? void 0 : _a2.call(global7, "error", listener2, true);
548
587
  }
549
588
  function removeCaptureUncaughtError() {
550
589
  var _a2;
551
- (_a2 = global6 == null ? void 0 : global6.removeEventListener) == null ? void 0 : _a2.call(global6, "error", listener2, true);
590
+ (_a2 = global7 == null ? void 0 : global7.removeEventListener) == null ? void 0 : _a2.call(global7, "error", listener2, true);
552
591
  }
553
592
 
554
593
  // src/capture/script/captureUnhandledrejectionError.ts
555
- import { getGlobal as getGlobal7 } from "@ohbug/utils";
556
- var global7 = getGlobal7();
594
+ import { getGlobal as getGlobal8 } from "@ohbug/utils";
595
+ var global8 = getGlobal8();
557
596
  function listener3(e) {
558
597
  scriptDispatcher(e);
559
598
  }
560
599
  function captureUnhandledrejectionError() {
561
600
  var _a2;
562
- (_a2 = global7 == null ? void 0 : global7.addEventListener) == null ? void 0 : _a2.call(global7, "unhandledrejection", listener3, true);
601
+ (_a2 = global8 == null ? void 0 : global8.addEventListener) == null ? void 0 : _a2.call(global8, "unhandledrejection", listener3, true);
563
602
  }
564
603
  function removeCaptureUnhandledrejectionError() {
565
604
  var _a2;
566
- (_a2 = global7 == null ? void 0 : global7.removeEventListener) == null ? void 0 : _a2.call(global7, "unhandledrejection", listener3, true);
605
+ (_a2 = global8 == null ? void 0 : global8.removeEventListener) == null ? void 0 : _a2.call(global8, "unhandledrejection", listener3, true);
567
606
  }
568
607
 
569
608
  // src/capture/index.ts
@@ -585,8 +624,8 @@ function removeCaptureNetwork() {
585
624
  removeCaptureFetchError();
586
625
  }
587
626
  function captureScript() {
588
- const global9 = getGlobal8();
589
- if (!global9.addEventListener)
627
+ const global10 = getGlobal9();
628
+ if (!global10.addEventListener)
590
629
  return;
591
630
  captureUncaughtError();
592
631
  captureUnhandledrejectionError();
@@ -596,6 +635,7 @@ function removeCaptureScript() {
596
635
  removeCaptureUnhandledrejectionError();
597
636
  }
598
637
  function handleCapture() {
638
+ replaceAddEventListener();
599
639
  captureScript();
600
640
  captureNetwork();
601
641
  captureAction();
@@ -603,14 +643,15 @@ function handleCapture() {
603
643
  }
604
644
 
605
645
  // src/destroy.ts
606
- import { getGlobal as getGlobal9 } from "@ohbug/utils";
607
- var global8 = getGlobal9();
646
+ import { getGlobal as getGlobal10 } from "@ohbug/utils";
647
+ var global9 = getGlobal10();
608
648
  function handleDestroy() {
609
649
  var _a2;
610
- (_a2 = global8 == null ? void 0 : global8.addEventListener) == null ? void 0 : _a2.call(
611
- global8,
650
+ (_a2 = global9 == null ? void 0 : global9.addEventListener) == null ? void 0 : _a2.call(
651
+ global9,
612
652
  "unload",
613
653
  () => {
654
+ removeReplaceAddEventListener();
614
655
  removeCaptureScript();
615
656
  removeCaptureNetwork();
616
657
  removeCaptureAction();
@@ -670,13 +711,13 @@ function notifier(event) {
670
711
 
671
712
  // src/client.ts
672
713
  function createClient(config) {
673
- const global9 = getGlobal10();
714
+ const global10 = getGlobal11();
674
715
  const sdk = {
675
716
  platform: "ohbug-browser",
676
717
  version
677
718
  };
678
719
  const client = new Client({ sdk, config, device, notifier });
679
- global9.__OHBUG__ = { client };
720
+ global10.__OHBUG__ = { client };
680
721
  client.use(extension);
681
722
  client.__logger.info(
682
723
  `%c @ohbug/browser %c Detected Ohbug v${version} %c`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ohbug/browser",
3
- "version": "2.3.0",
3
+ "version": "2.4.0",
4
4
  "description": "Ohbug SDK for browsers",
5
5
  "license": "Apache-2.0",
6
6
  "author": "chenyueban <jasonchan0527@gmail.com>",