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