@ohbug/browser 2.3.0 → 2.4.1

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,12 +33,24 @@ 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 {
39
44
  req: {
40
45
  url: string;
41
46
  method: string;
47
+ data?: string;
48
+ params?: string;
49
+ };
50
+ res: {
51
+ response: string;
52
+ status: number;
53
+ statusText?: string;
42
54
  };
43
55
  }
44
56
 
@@ -46,13 +58,24 @@ interface FetchErrorDetail extends OhbugBaseDetail {
46
58
  req: {
47
59
  url: string;
48
60
  method: string;
61
+ data?: string;
62
+ params?: string;
63
+ };
64
+ res: {
65
+ status: number;
66
+ statusText?: string;
49
67
  };
50
68
  }
51
69
 
52
70
  interface WebsocketErrorDetail extends OhbugBaseDetail {
53
71
  url: string;
72
+ params?: string;
54
73
  timeStamp: number;
55
74
  readyState: number;
75
+ protocol: string;
76
+ extensions: string;
77
+ binaryType: string;
78
+ bufferedAmount: number;
56
79
  }
57
80
 
58
81
  export { AjaxErrorDetail, FetchErrorDetail, ResourceErrorDetail, UncaughtErrorDetail, UnhandledrejectionErrorDetail, UnknownErrorDetail, WebsocketErrorDetail, BrowserClient as default };
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.1";
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,35 @@ 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) {
261
- var _a2, _b2, _c;
262
- const [stackFrame] = import_error_stack_parser.default.parse(error.error);
289
+ function uncaughtErrorHandler(e) {
290
+ var _a2, _b2, _c, _d;
263
291
  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
292
+ name: (_a2 = e == null ? void 0 : e.error) == null ? void 0 : _a2.name,
293
+ message: (e == null ? void 0 : e.message) || ((_b2 = e == null ? void 0 : e.error) == null ? void 0 : _b2.message),
294
+ filename: e == null ? void 0 : e.filename,
295
+ lineno: e == null ? void 0 : e.lineno,
296
+ colno: e == null ? void 0 : e.colno,
297
+ stack: (_c = e == null ? void 0 : e.error) == null ? void 0 : _c.stack
270
298
  };
271
- const { client } = (0, import_utils4.getOhbugObject)();
299
+ if (e.error) {
300
+ try {
301
+ const stackFrame = (_d = import_error_stack_parser.default.parse(e.error)) == null ? void 0 : _d[0];
302
+ if (stackFrame) {
303
+ detail.filename = stackFrame.fileName;
304
+ detail.lineno = stackFrame.lineNumber;
305
+ detail.colno = stackFrame.columnNumber;
306
+ }
307
+ } catch (_) {
308
+ }
309
+ }
310
+ const { client } = (0, import_utils5.getOhbugObject)();
272
311
  const event = client.createEvent({
273
312
  category: "error",
274
313
  type: import_core.EventTypes.UNCAUGHT_ERROR,
@@ -278,11 +317,11 @@ function uncaughtErrorHandler(error) {
278
317
  }
279
318
 
280
319
  // src/handle/resourceErrorHandler.ts
281
- var import_utils5 = require("@ohbug/utils");
320
+ var import_utils6 = require("@ohbug/utils");
282
321
  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);
322
+ function resourceErrorHandler(e) {
323
+ const target = e.target || e.srcElement;
324
+ const selector = (0, import_utils6.getSelector)(e);
286
325
  const detail = {
287
326
  src: target && target.src,
288
327
  tagName: target && target.tagName,
@@ -292,7 +331,7 @@ function resourceErrorHandler(error) {
292
331
  nodeType: target && target.nodeType,
293
332
  selector
294
333
  };
295
- const { client } = (0, import_utils5.getOhbugObject)();
334
+ const { client } = (0, import_utils6.getOhbugObject)();
296
335
  const event = client.createEvent({
297
336
  category: "error",
298
337
  type: import_core2.EventTypes.RESOURCE_ERROR,
@@ -302,21 +341,28 @@ function resourceErrorHandler(error) {
302
341
  }
303
342
 
304
343
  // src/handle/unhandledrejectionErrorHandler.ts
305
- var import_utils6 = require("@ohbug/utils");
344
+ var import_utils7 = require("@ohbug/utils");
306
345
  var import_core3 = require("@ohbug/core");
307
346
  var import_error_stack_parser2 = __toESM(require("error-stack-parser"));
308
- function unhandledrejectionErrorHandler(error) {
309
- var _a2, _b2, _c;
310
- const [stackFrame] = import_error_stack_parser2.default.parse(error.reason);
347
+ function unhandledrejectionErrorHandler(e) {
348
+ var _a2, _b2, _c, _d;
311
349
  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),
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 = error == null ? void 0 : error.reason) == null ? void 0 : _c.stack
350
+ name: (_a2 = e == null ? void 0 : e.reason) == null ? void 0 : _a2.name,
351
+ message: ((_b2 = e == null ? void 0 : e.reason) == null ? void 0 : _b2.message) || (e == null ? void 0 : e.reason),
352
+ stack: (_c = e == null ? void 0 : e.reason) == null ? void 0 : _c.stack
318
353
  };
319
- const { client } = (0, import_utils6.getOhbugObject)();
354
+ if (e.reason) {
355
+ try {
356
+ const stackFrame = (_d = import_error_stack_parser2.default.parse(e.reason)) == null ? void 0 : _d[0];
357
+ if (stackFrame) {
358
+ detail.filename = stackFrame.fileName;
359
+ detail.lineno = stackFrame.lineNumber;
360
+ detail.colno = stackFrame.columnNumber;
361
+ }
362
+ } catch (_) {
363
+ }
364
+ }
365
+ const { client } = (0, import_utils7.getOhbugObject)();
320
366
  const event = client.createEvent({
321
367
  category: "error",
322
368
  type: import_core3.EventTypes.UNHANDLEDREJECTION_ERROR,
@@ -326,11 +372,31 @@ function unhandledrejectionErrorHandler(error) {
326
372
  }
327
373
 
328
374
  // src/handle/unknownErrorHandler.ts
329
- var import_utils7 = require("@ohbug/utils");
375
+ var import_utils8 = require("@ohbug/utils");
330
376
  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)();
377
+ var import_error_stack_parser3 = __toESM(require("error-stack-parser"));
378
+ function unknownErrorHandler(e) {
379
+ var _a2, _b2, _c, _d;
380
+ const detail = {
381
+ name: (_a2 = e == null ? void 0 : e.error) == null ? void 0 : _a2.name,
382
+ message: (e == null ? void 0 : e.message) || ((_b2 = e == null ? void 0 : e.error) == null ? void 0 : _b2.message),
383
+ filename: e == null ? void 0 : e.filename,
384
+ lineno: e == null ? void 0 : e.lineno,
385
+ colno: e == null ? void 0 : e.colno,
386
+ stack: (_c = e == null ? void 0 : e.error) == null ? void 0 : _c.stack
387
+ };
388
+ if (e.error) {
389
+ try {
390
+ const stackFrame = (_d = import_error_stack_parser3.default.parse(e.error)) == null ? void 0 : _d[0];
391
+ if (stackFrame) {
392
+ detail.filename = stackFrame.fileName;
393
+ detail.lineno = stackFrame.lineNumber;
394
+ detail.colno = stackFrame.columnNumber;
395
+ }
396
+ } catch (_) {
397
+ }
398
+ }
399
+ const { client } = (0, import_utils8.getOhbugObject)();
334
400
  const event = client.createEvent({
335
401
  category: "error",
336
402
  type: import_core4.EventTypes.UNKNOWN_ERROR,
@@ -340,10 +406,10 @@ function unknownErrorHandler(error) {
340
406
  }
341
407
 
342
408
  // src/handle/ajaxErrorHandler.ts
343
- var import_utils8 = require("@ohbug/utils");
409
+ var import_utils9 = require("@ohbug/utils");
344
410
  var import_core5 = require("@ohbug/core");
345
411
  function ajaxErrorHandler(detail) {
346
- const { client } = (0, import_utils8.getOhbugObject)();
412
+ const { client } = (0, import_utils9.getOhbugObject)();
347
413
  const event = client.createEvent({
348
414
  category: "error",
349
415
  type: import_core5.EventTypes.AJAX_ERROR,
@@ -353,10 +419,10 @@ function ajaxErrorHandler(detail) {
353
419
  }
354
420
 
355
421
  // src/handle/fetchErrorHandler.ts
356
- var import_utils9 = require("@ohbug/utils");
422
+ var import_utils10 = require("@ohbug/utils");
357
423
  var import_core6 = require("@ohbug/core");
358
424
  function fetchErrorHandler(detail) {
359
- const { client } = (0, import_utils9.getOhbugObject)();
425
+ const { client } = (0, import_utils10.getOhbugObject)();
360
426
  const event = client.createEvent({
361
427
  category: "error",
362
428
  type: import_core6.EventTypes.FETCH_ERROR,
@@ -366,10 +432,10 @@ function fetchErrorHandler(detail) {
366
432
  }
367
433
 
368
434
  // src/handle/websocketErrorHandler.ts
369
- var import_utils10 = require("@ohbug/utils");
435
+ var import_utils11 = require("@ohbug/utils");
370
436
  var import_core7 = require("@ohbug/core");
371
437
  function websocketErrorHandler(detail) {
372
- const { client } = (0, import_utils10.getOhbugObject)();
438
+ const { client } = (0, import_utils11.getOhbugObject)();
373
439
  const event = client.createEvent({
374
440
  category: "error",
375
441
  type: import_core7.EventTypes.WEBSOCKET_ERROR,
@@ -423,23 +489,48 @@ function networkDispatcher(type, detail) {
423
489
  }
424
490
  }
425
491
 
492
+ // src/capture/network/getParams.ts
493
+ var groupParamsByKey = (params) => [...params.entries()].reduce((acc, tuple) => {
494
+ const [key, val] = tuple;
495
+ if (acc.hasOwnProperty(key)) {
496
+ if (Array.isArray(acc[key])) {
497
+ acc[key] = [...acc[key], val];
498
+ } else {
499
+ acc[key] = [acc[key], val];
500
+ }
501
+ } else {
502
+ acc[key] = val;
503
+ }
504
+ return acc;
505
+ }, {});
506
+ function getParams(data) {
507
+ const location = new URL(data);
508
+ const url = location.origin + location.pathname;
509
+ const searchParams = location.search ? new URLSearchParams(location.search) : void 0;
510
+ const params = searchParams ? JSON.stringify(groupParamsByKey(searchParams)) : void 0;
511
+ return {
512
+ url,
513
+ params
514
+ };
515
+ }
516
+
426
517
  // src/capture/network/captureAjaxError.ts
427
- var global3 = (0, import_utils11.getGlobal)();
428
- var access = "XMLHttpRequest" in global3;
429
- var xhrOriginal = access ? {
518
+ var global4 = (0, import_utils12.getGlobal)();
519
+ var access2 = "XMLHttpRequest" in global4;
520
+ var xhrOriginal = access2 ? {
430
521
  open: XMLHttpRequest.prototype.open,
431
522
  send: XMLHttpRequest.prototype.send
432
523
  } : {};
433
524
  function captureAjaxError() {
434
- if (!access)
525
+ if (!access2)
435
526
  return;
436
- const { client } = (0, import_utils11.getOhbugObject)();
527
+ const { client } = (0, import_utils12.getOhbugObject)();
437
528
  const desc = {
438
529
  method: "",
439
530
  url: ""
440
531
  };
441
532
  const xhrProto = XMLHttpRequest == null ? void 0 : XMLHttpRequest.prototype;
442
- xhrOriginal.open = (0, import_utils11.replace)(
533
+ xhrOriginal.open = (0, import_utils12.replace)(
443
534
  xhrProto,
444
535
  "open",
445
536
  (origin) => function call(...args) {
@@ -449,17 +540,25 @@ function captureAjaxError() {
449
540
  return origin.apply(this, args);
450
541
  }
451
542
  );
452
- xhrOriginal.send = (0, import_utils11.replace)(
543
+ xhrOriginal.send = (0, import_utils12.replace)(
453
544
  xhrProto,
454
545
  "send",
455
546
  (origin) => function call(...args) {
456
547
  this.addEventListener("readystatechange", function handle() {
457
548
  if (this.readyState === 4) {
458
549
  if (desc.url !== client.__config.endpoint) {
550
+ const { url, params } = getParams(desc.url);
459
551
  const detail = {
460
552
  req: {
461
- url: desc.url,
462
- method: desc.method
553
+ url,
554
+ method: desc.method,
555
+ data: args[0],
556
+ params
557
+ },
558
+ res: {
559
+ status: this.status,
560
+ statusText: this.statusText,
561
+ response: this.response
463
562
  }
464
563
  };
465
564
  client.addAction("ajax", detail, "ajax");
@@ -474,7 +573,7 @@ function captureAjaxError() {
474
573
  );
475
574
  }
476
575
  function removeCaptureAjaxError() {
477
- if (access && xhrOriginal.open && xhrOriginal.send) {
576
+ if (access2 && xhrOriginal.open && xhrOriginal.send) {
478
577
  const xhrProto = XMLHttpRequest == null ? void 0 : XMLHttpRequest.prototype;
479
578
  xhrProto.open = xhrOriginal.open;
480
579
  xhrProto.send = xhrOriginal.send;
@@ -482,26 +581,33 @@ function removeCaptureAjaxError() {
482
581
  }
483
582
 
484
583
  // src/capture/network/captureFetchError.ts
485
- var import_utils12 = require("@ohbug/utils");
584
+ var import_utils13 = require("@ohbug/utils");
486
585
  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;
586
+ var global5 = (0, import_utils13.getGlobal)();
587
+ var access3 = "fetch" in global5;
588
+ var fetchOriginal = access3 ? global5.fetch : null;
490
589
  function captureFetchError() {
491
- if (!access2)
590
+ if (!access3)
492
591
  return;
493
- const { client } = (0, import_utils12.getOhbugObject)();
494
- fetchOriginal = (0, import_utils12.replace)(
495
- global4,
592
+ const { client } = (0, import_utils13.getOhbugObject)();
593
+ fetchOriginal = (0, import_utils13.replace)(
594
+ global5,
496
595
  "fetch",
497
596
  (origin) => function call(...args) {
498
597
  return origin.apply(this, args).then(
499
598
  (res) => {
500
- const [url, conf] = args;
599
+ const [originalUrl, conf] = args;
600
+ const { url, params } = getParams(originalUrl);
501
601
  const detail = {
502
602
  req: {
503
603
  url,
504
- method: conf && conf.method
604
+ method: conf && conf.method,
605
+ data: conf && conf.body,
606
+ params
607
+ },
608
+ res: {
609
+ status: res.status,
610
+ statusText: res.statusText
505
611
  }
506
612
  };
507
613
  client.addAction("fetch", detail, "fetch");
@@ -511,12 +617,16 @@ function captureFetchError() {
511
617
  return res;
512
618
  },
513
619
  (err) => {
514
- const [url, conf] = args;
620
+ const [originalUrl, conf] = args;
621
+ const { url, params } = getParams(originalUrl);
515
622
  const detail = {
516
623
  req: {
517
624
  url,
518
- method: conf && conf.method
519
- }
625
+ method: conf && conf.method,
626
+ data: conf && conf.body,
627
+ params
628
+ },
629
+ res: { status: 400 }
520
630
  };
521
631
  networkDispatcher(import_core10.EventTypes.FETCH_ERROR, detail);
522
632
  throw err;
@@ -526,17 +636,17 @@ function captureFetchError() {
526
636
  );
527
637
  }
528
638
  function removeCaptureFetchError() {
529
- if (access2 && fetchOriginal) {
530
- global4.fetch = fetchOriginal;
639
+ if (access3 && fetchOriginal) {
640
+ global5.fetch = fetchOriginal;
531
641
  }
532
642
  }
533
643
 
534
644
  // src/capture/network/captureWebSocketError.ts
535
- var import_utils13 = require("@ohbug/utils");
645
+ var import_utils14 = require("@ohbug/utils");
536
646
  var import_core11 = require("@ohbug/core");
537
- var global5 = (0, import_utils13.getGlobal)();
647
+ var global6 = (0, import_utils14.getGlobal)();
538
648
  function captureWebSocketError() {
539
- if (!("WebSocket" in global5))
649
+ if (!("WebSocket" in global6))
540
650
  return;
541
651
  const wsProto = WebSocket == null ? void 0 : WebSocket.prototype;
542
652
  const backup = Object.getOwnPropertyDescriptor(wsProto, "onerror");
@@ -548,15 +658,25 @@ function captureWebSocketError() {
548
658
  (_a2 = backup == null ? void 0 : backup.set) == null ? void 0 : _a2.call(this, function call(e) {
549
659
  const {
550
660
  target: {
551
- url,
552
- readyState
661
+ url: originalUrl,
662
+ readyState,
663
+ protocol,
664
+ extensions,
665
+ binaryType,
666
+ bufferedAmount
553
667
  },
554
668
  timeStamp
555
669
  } = e;
670
+ const { url, params } = getParams(originalUrl);
556
671
  const detail = {
557
672
  url,
673
+ params,
558
674
  timeStamp,
559
- readyState
675
+ readyState,
676
+ protocol,
677
+ extensions,
678
+ binaryType,
679
+ bufferedAmount
560
680
  };
561
681
  networkDispatcher(import_core11.EventTypes.WEBSOCKET_ERROR, detail);
562
682
  arg.apply(this, args);
@@ -566,33 +686,33 @@ function captureWebSocketError() {
566
686
  }
567
687
 
568
688
  // src/capture/script/captureUncaughtError.ts
569
- var import_utils14 = require("@ohbug/utils");
570
- var global6 = (0, import_utils14.getGlobal)();
689
+ var import_utils15 = require("@ohbug/utils");
690
+ var global7 = (0, import_utils15.getGlobal)();
571
691
  function listener2(e) {
572
692
  scriptDispatcher(e);
573
693
  }
574
694
  function captureUncaughtError() {
575
695
  var _a2;
576
- (_a2 = global6 == null ? void 0 : global6.addEventListener) == null ? void 0 : _a2.call(global6, "error", listener2, true);
696
+ (_a2 = global7 == null ? void 0 : global7.addEventListener) == null ? void 0 : _a2.call(global7, "error", listener2, true);
577
697
  }
578
698
  function removeCaptureUncaughtError() {
579
699
  var _a2;
580
- (_a2 = global6 == null ? void 0 : global6.removeEventListener) == null ? void 0 : _a2.call(global6, "error", listener2, true);
700
+ (_a2 = global7 == null ? void 0 : global7.removeEventListener) == null ? void 0 : _a2.call(global7, "error", listener2, true);
581
701
  }
582
702
 
583
703
  // src/capture/script/captureUnhandledrejectionError.ts
584
- var import_utils15 = require("@ohbug/utils");
585
- var global7 = (0, import_utils15.getGlobal)();
704
+ var import_utils16 = require("@ohbug/utils");
705
+ var global8 = (0, import_utils16.getGlobal)();
586
706
  function listener3(e) {
587
707
  scriptDispatcher(e);
588
708
  }
589
709
  function captureUnhandledrejectionError() {
590
710
  var _a2;
591
- (_a2 = global7 == null ? void 0 : global7.addEventListener) == null ? void 0 : _a2.call(global7, "unhandledrejection", listener3, true);
711
+ (_a2 = global8 == null ? void 0 : global8.addEventListener) == null ? void 0 : _a2.call(global8, "unhandledrejection", listener3, true);
592
712
  }
593
713
  function removeCaptureUnhandledrejectionError() {
594
714
  var _a2;
595
- (_a2 = global7 == null ? void 0 : global7.removeEventListener) == null ? void 0 : _a2.call(global7, "unhandledrejection", listener3, true);
715
+ (_a2 = global8 == null ? void 0 : global8.removeEventListener) == null ? void 0 : _a2.call(global8, "unhandledrejection", listener3, true);
596
716
  }
597
717
 
598
718
  // src/capture/index.ts
@@ -614,8 +734,8 @@ function removeCaptureNetwork() {
614
734
  removeCaptureFetchError();
615
735
  }
616
736
  function captureScript() {
617
- const global9 = (0, import_utils16.getGlobal)();
618
- if (!global9.addEventListener)
737
+ const global10 = (0, import_utils17.getGlobal)();
738
+ if (!global10.addEventListener)
619
739
  return;
620
740
  captureUncaughtError();
621
741
  captureUnhandledrejectionError();
@@ -625,6 +745,7 @@ function removeCaptureScript() {
625
745
  removeCaptureUnhandledrejectionError();
626
746
  }
627
747
  function handleCapture() {
748
+ replaceAddEventListener();
628
749
  captureScript();
629
750
  captureNetwork();
630
751
  captureAction();
@@ -632,14 +753,15 @@ function handleCapture() {
632
753
  }
633
754
 
634
755
  // src/destroy.ts
635
- var import_utils17 = require("@ohbug/utils");
636
- var global8 = (0, import_utils17.getGlobal)();
756
+ var import_utils18 = require("@ohbug/utils");
757
+ var global9 = (0, import_utils18.getGlobal)();
637
758
  function handleDestroy() {
638
759
  var _a2;
639
- (_a2 = global8 == null ? void 0 : global8.addEventListener) == null ? void 0 : _a2.call(
640
- global8,
760
+ (_a2 = global9 == null ? void 0 : global9.addEventListener) == null ? void 0 : _a2.call(
761
+ global9,
641
762
  "unload",
642
763
  () => {
764
+ removeReplaceAddEventListener();
643
765
  removeCaptureScript();
644
766
  removeCaptureNetwork();
645
767
  removeCaptureAction();
@@ -659,7 +781,7 @@ var extension = (0, import_core12.defineExtension)({
659
781
  });
660
782
 
661
783
  // src/notifier.ts
662
- var import_utils18 = require("@ohbug/utils");
784
+ var import_utils19 = require("@ohbug/utils");
663
785
  var getCircularReplacer = () => {
664
786
  const seen = /* @__PURE__ */ new WeakSet();
665
787
  return (_, value) => {
@@ -673,7 +795,7 @@ var getCircularReplacer = () => {
673
795
  };
674
796
  };
675
797
  function notifier(event) {
676
- const { client } = (0, import_utils18.getOhbugObject)();
798
+ const { client } = (0, import_utils19.getOhbugObject)();
677
799
  const url = client.__config.endpoint;
678
800
  return new Promise((resolve, reject) => {
679
801
  const json = JSON.stringify(event, getCircularReplacer());
@@ -699,13 +821,13 @@ function notifier(event) {
699
821
 
700
822
  // src/client.ts
701
823
  function createClient(config) {
702
- const global9 = (0, import_utils19.getGlobal)();
824
+ const global10 = (0, import_utils20.getGlobal)();
703
825
  const sdk = {
704
826
  platform: "ohbug-browser",
705
827
  version
706
828
  };
707
829
  const client = new import_core13.Client({ sdk, config, device, notifier });
708
- global9.__OHBUG__ = { client };
830
+ global10.__OHBUG__ = { client };
709
831
  client.use(extension);
710
832
  client.__logger.info(
711
833
  `%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.1";
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,24 +250,34 @@ 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) {
232
- var _a2, _b2, _c;
233
- const [stackFrame] = ErrorStackParser.parse(error.error);
260
+ function uncaughtErrorHandler(e) {
261
+ var _a2, _b2, _c, _d;
234
262
  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
263
+ name: (_a2 = e == null ? void 0 : e.error) == null ? void 0 : _a2.name,
264
+ message: (e == null ? void 0 : e.message) || ((_b2 = e == null ? void 0 : e.error) == null ? void 0 : _b2.message),
265
+ filename: e == null ? void 0 : e.filename,
266
+ lineno: e == null ? void 0 : e.lineno,
267
+ colno: e == null ? void 0 : e.colno,
268
+ stack: (_c = e == null ? void 0 : e.error) == null ? void 0 : _c.stack
241
269
  };
270
+ if (e.error) {
271
+ try {
272
+ const stackFrame = (_d = ErrorStackParser.parse(e.error)) == null ? void 0 : _d[0];
273
+ if (stackFrame) {
274
+ detail.filename = stackFrame.fileName;
275
+ detail.lineno = stackFrame.lineNumber;
276
+ detail.colno = stackFrame.columnNumber;
277
+ }
278
+ } catch (_) {
279
+ }
280
+ }
242
281
  const { client } = getOhbugObject4();
243
282
  const event = client.createEvent({
244
283
  category: "error",
@@ -251,9 +290,9 @@ function uncaughtErrorHandler(error) {
251
290
  // src/handle/resourceErrorHandler.ts
252
291
  import { getOhbugObject as getOhbugObject5, getSelector as getSelector2 } from "@ohbug/utils";
253
292
  import { EventTypes as EventTypes2 } from "@ohbug/core";
254
- function resourceErrorHandler(error) {
255
- const target = error.target || error.srcElement;
256
- const selector = getSelector2(error);
293
+ function resourceErrorHandler(e) {
294
+ const target = e.target || e.srcElement;
295
+ const selector = getSelector2(e);
257
296
  const detail = {
258
297
  src: target && target.src,
259
298
  tagName: target && target.tagName,
@@ -276,17 +315,24 @@ function resourceErrorHandler(error) {
276
315
  import { getOhbugObject as getOhbugObject6 } from "@ohbug/utils";
277
316
  import { EventTypes as EventTypes3 } from "@ohbug/core";
278
317
  import ErrorStackParser2 from "error-stack-parser";
279
- function unhandledrejectionErrorHandler(error) {
280
- var _a2, _b2, _c;
281
- const [stackFrame] = ErrorStackParser2.parse(error.reason);
318
+ function unhandledrejectionErrorHandler(e) {
319
+ var _a2, _b2, _c, _d;
282
320
  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),
285
- filename: stackFrame == null ? void 0 : stackFrame.fileName,
286
- lineno: stackFrame == null ? void 0 : stackFrame.lineNumber,
287
- colno: stackFrame == null ? void 0 : stackFrame.columnNumber,
288
- stack: (_c = error == null ? void 0 : error.reason) == null ? void 0 : _c.stack
321
+ name: (_a2 = e == null ? void 0 : e.reason) == null ? void 0 : _a2.name,
322
+ message: ((_b2 = e == null ? void 0 : e.reason) == null ? void 0 : _b2.message) || (e == null ? void 0 : e.reason),
323
+ stack: (_c = e == null ? void 0 : e.reason) == null ? void 0 : _c.stack
289
324
  };
325
+ if (e.reason) {
326
+ try {
327
+ const stackFrame = (_d = ErrorStackParser2.parse(e.reason)) == null ? void 0 : _d[0];
328
+ if (stackFrame) {
329
+ detail.filename = stackFrame.fileName;
330
+ detail.lineno = stackFrame.lineNumber;
331
+ detail.colno = stackFrame.columnNumber;
332
+ }
333
+ } catch (_) {
334
+ }
335
+ }
290
336
  const { client } = getOhbugObject6();
291
337
  const event = client.createEvent({
292
338
  category: "error",
@@ -299,8 +345,28 @@ function unhandledrejectionErrorHandler(error) {
299
345
  // src/handle/unknownErrorHandler.ts
300
346
  import { getOhbugObject as getOhbugObject7 } from "@ohbug/utils";
301
347
  import { EventTypes as EventTypes4 } from "@ohbug/core";
302
- function unknownErrorHandler(error) {
303
- const detail = error.message ? error : { message: error };
348
+ import ErrorStackParser3 from "error-stack-parser";
349
+ function unknownErrorHandler(e) {
350
+ var _a2, _b2, _c, _d;
351
+ const detail = {
352
+ name: (_a2 = e == null ? void 0 : e.error) == null ? void 0 : _a2.name,
353
+ message: (e == null ? void 0 : e.message) || ((_b2 = e == null ? void 0 : e.error) == null ? void 0 : _b2.message),
354
+ filename: e == null ? void 0 : e.filename,
355
+ lineno: e == null ? void 0 : e.lineno,
356
+ colno: e == null ? void 0 : e.colno,
357
+ stack: (_c = e == null ? void 0 : e.error) == null ? void 0 : _c.stack
358
+ };
359
+ if (e.error) {
360
+ try {
361
+ const stackFrame = (_d = ErrorStackParser3.parse(e.error)) == null ? void 0 : _d[0];
362
+ if (stackFrame) {
363
+ detail.filename = stackFrame.fileName;
364
+ detail.lineno = stackFrame.lineNumber;
365
+ detail.colno = stackFrame.columnNumber;
366
+ }
367
+ } catch (_) {
368
+ }
369
+ }
304
370
  const { client } = getOhbugObject7();
305
371
  const event = client.createEvent({
306
372
  category: "error",
@@ -394,15 +460,40 @@ function networkDispatcher(type, detail) {
394
460
  }
395
461
  }
396
462
 
463
+ // src/capture/network/getParams.ts
464
+ var groupParamsByKey = (params) => [...params.entries()].reduce((acc, tuple) => {
465
+ const [key, val] = tuple;
466
+ if (acc.hasOwnProperty(key)) {
467
+ if (Array.isArray(acc[key])) {
468
+ acc[key] = [...acc[key], val];
469
+ } else {
470
+ acc[key] = [acc[key], val];
471
+ }
472
+ } else {
473
+ acc[key] = val;
474
+ }
475
+ return acc;
476
+ }, {});
477
+ function getParams(data) {
478
+ const location = new URL(data);
479
+ const url = location.origin + location.pathname;
480
+ const searchParams = location.search ? new URLSearchParams(location.search) : void 0;
481
+ const params = searchParams ? JSON.stringify(groupParamsByKey(searchParams)) : void 0;
482
+ return {
483
+ url,
484
+ params
485
+ };
486
+ }
487
+
397
488
  // src/capture/network/captureAjaxError.ts
398
- var global3 = getGlobal3();
399
- var access = "XMLHttpRequest" in global3;
400
- var xhrOriginal = access ? {
489
+ var global4 = getGlobal4();
490
+ var access2 = "XMLHttpRequest" in global4;
491
+ var xhrOriginal = access2 ? {
401
492
  open: XMLHttpRequest.prototype.open,
402
493
  send: XMLHttpRequest.prototype.send
403
494
  } : {};
404
495
  function captureAjaxError() {
405
- if (!access)
496
+ if (!access2)
406
497
  return;
407
498
  const { client } = getOhbugObject11();
408
499
  const desc = {
@@ -410,7 +501,7 @@ function captureAjaxError() {
410
501
  url: ""
411
502
  };
412
503
  const xhrProto = XMLHttpRequest == null ? void 0 : XMLHttpRequest.prototype;
413
- xhrOriginal.open = replace3(
504
+ xhrOriginal.open = replace4(
414
505
  xhrProto,
415
506
  "open",
416
507
  (origin) => function call(...args) {
@@ -420,17 +511,25 @@ function captureAjaxError() {
420
511
  return origin.apply(this, args);
421
512
  }
422
513
  );
423
- xhrOriginal.send = replace3(
514
+ xhrOriginal.send = replace4(
424
515
  xhrProto,
425
516
  "send",
426
517
  (origin) => function call(...args) {
427
518
  this.addEventListener("readystatechange", function handle() {
428
519
  if (this.readyState === 4) {
429
520
  if (desc.url !== client.__config.endpoint) {
521
+ const { url, params } = getParams(desc.url);
430
522
  const detail = {
431
523
  req: {
432
- url: desc.url,
433
- method: desc.method
524
+ url,
525
+ method: desc.method,
526
+ data: args[0],
527
+ params
528
+ },
529
+ res: {
530
+ status: this.status,
531
+ statusText: this.statusText,
532
+ response: this.response
434
533
  }
435
534
  };
436
535
  client.addAction("ajax", detail, "ajax");
@@ -445,7 +544,7 @@ function captureAjaxError() {
445
544
  );
446
545
  }
447
546
  function removeCaptureAjaxError() {
448
- if (access && xhrOriginal.open && xhrOriginal.send) {
547
+ if (access2 && xhrOriginal.open && xhrOriginal.send) {
449
548
  const xhrProto = XMLHttpRequest == null ? void 0 : XMLHttpRequest.prototype;
450
549
  xhrProto.open = xhrOriginal.open;
451
550
  xhrProto.send = xhrOriginal.send;
@@ -453,26 +552,33 @@ function removeCaptureAjaxError() {
453
552
  }
454
553
 
455
554
  // src/capture/network/captureFetchError.ts
456
- import { getGlobal as getGlobal4, getOhbugObject as getOhbugObject12, replace as replace4 } from "@ohbug/utils";
555
+ import { getGlobal as getGlobal5, getOhbugObject as getOhbugObject12, replace as replace5 } from "@ohbug/utils";
457
556
  import { EventTypes as EventTypes10 } from "@ohbug/core";
458
- var global4 = getGlobal4();
459
- var access2 = "fetch" in global4;
460
- var fetchOriginal = access2 ? global4.fetch : null;
557
+ var global5 = getGlobal5();
558
+ var access3 = "fetch" in global5;
559
+ var fetchOriginal = access3 ? global5.fetch : null;
461
560
  function captureFetchError() {
462
- if (!access2)
561
+ if (!access3)
463
562
  return;
464
563
  const { client } = getOhbugObject12();
465
- fetchOriginal = replace4(
466
- global4,
564
+ fetchOriginal = replace5(
565
+ global5,
467
566
  "fetch",
468
567
  (origin) => function call(...args) {
469
568
  return origin.apply(this, args).then(
470
569
  (res) => {
471
- const [url, conf] = args;
570
+ const [originalUrl, conf] = args;
571
+ const { url, params } = getParams(originalUrl);
472
572
  const detail = {
473
573
  req: {
474
574
  url,
475
- method: conf && conf.method
575
+ method: conf && conf.method,
576
+ data: conf && conf.body,
577
+ params
578
+ },
579
+ res: {
580
+ status: res.status,
581
+ statusText: res.statusText
476
582
  }
477
583
  };
478
584
  client.addAction("fetch", detail, "fetch");
@@ -482,12 +588,16 @@ function captureFetchError() {
482
588
  return res;
483
589
  },
484
590
  (err) => {
485
- const [url, conf] = args;
591
+ const [originalUrl, conf] = args;
592
+ const { url, params } = getParams(originalUrl);
486
593
  const detail = {
487
594
  req: {
488
595
  url,
489
- method: conf && conf.method
490
- }
596
+ method: conf && conf.method,
597
+ data: conf && conf.body,
598
+ params
599
+ },
600
+ res: { status: 400 }
491
601
  };
492
602
  networkDispatcher(EventTypes10.FETCH_ERROR, detail);
493
603
  throw err;
@@ -497,17 +607,17 @@ function captureFetchError() {
497
607
  );
498
608
  }
499
609
  function removeCaptureFetchError() {
500
- if (access2 && fetchOriginal) {
501
- global4.fetch = fetchOriginal;
610
+ if (access3 && fetchOriginal) {
611
+ global5.fetch = fetchOriginal;
502
612
  }
503
613
  }
504
614
 
505
615
  // src/capture/network/captureWebSocketError.ts
506
- import { getGlobal as getGlobal5 } from "@ohbug/utils";
616
+ import { getGlobal as getGlobal6 } from "@ohbug/utils";
507
617
  import { EventTypes as EventTypes11 } from "@ohbug/core";
508
- var global5 = getGlobal5();
618
+ var global6 = getGlobal6();
509
619
  function captureWebSocketError() {
510
- if (!("WebSocket" in global5))
620
+ if (!("WebSocket" in global6))
511
621
  return;
512
622
  const wsProto = WebSocket == null ? void 0 : WebSocket.prototype;
513
623
  const backup = Object.getOwnPropertyDescriptor(wsProto, "onerror");
@@ -519,15 +629,25 @@ function captureWebSocketError() {
519
629
  (_a2 = backup == null ? void 0 : backup.set) == null ? void 0 : _a2.call(this, function call(e) {
520
630
  const {
521
631
  target: {
522
- url,
523
- readyState
632
+ url: originalUrl,
633
+ readyState,
634
+ protocol,
635
+ extensions,
636
+ binaryType,
637
+ bufferedAmount
524
638
  },
525
639
  timeStamp
526
640
  } = e;
641
+ const { url, params } = getParams(originalUrl);
527
642
  const detail = {
528
643
  url,
644
+ params,
529
645
  timeStamp,
530
- readyState
646
+ readyState,
647
+ protocol,
648
+ extensions,
649
+ binaryType,
650
+ bufferedAmount
531
651
  };
532
652
  networkDispatcher(EventTypes11.WEBSOCKET_ERROR, detail);
533
653
  arg.apply(this, args);
@@ -537,33 +657,33 @@ function captureWebSocketError() {
537
657
  }
538
658
 
539
659
  // src/capture/script/captureUncaughtError.ts
540
- import { getGlobal as getGlobal6 } from "@ohbug/utils";
541
- var global6 = getGlobal6();
660
+ import { getGlobal as getGlobal7 } from "@ohbug/utils";
661
+ var global7 = getGlobal7();
542
662
  function listener2(e) {
543
663
  scriptDispatcher(e);
544
664
  }
545
665
  function captureUncaughtError() {
546
666
  var _a2;
547
- (_a2 = global6 == null ? void 0 : global6.addEventListener) == null ? void 0 : _a2.call(global6, "error", listener2, true);
667
+ (_a2 = global7 == null ? void 0 : global7.addEventListener) == null ? void 0 : _a2.call(global7, "error", listener2, true);
548
668
  }
549
669
  function removeCaptureUncaughtError() {
550
670
  var _a2;
551
- (_a2 = global6 == null ? void 0 : global6.removeEventListener) == null ? void 0 : _a2.call(global6, "error", listener2, true);
671
+ (_a2 = global7 == null ? void 0 : global7.removeEventListener) == null ? void 0 : _a2.call(global7, "error", listener2, true);
552
672
  }
553
673
 
554
674
  // src/capture/script/captureUnhandledrejectionError.ts
555
- import { getGlobal as getGlobal7 } from "@ohbug/utils";
556
- var global7 = getGlobal7();
675
+ import { getGlobal as getGlobal8 } from "@ohbug/utils";
676
+ var global8 = getGlobal8();
557
677
  function listener3(e) {
558
678
  scriptDispatcher(e);
559
679
  }
560
680
  function captureUnhandledrejectionError() {
561
681
  var _a2;
562
- (_a2 = global7 == null ? void 0 : global7.addEventListener) == null ? void 0 : _a2.call(global7, "unhandledrejection", listener3, true);
682
+ (_a2 = global8 == null ? void 0 : global8.addEventListener) == null ? void 0 : _a2.call(global8, "unhandledrejection", listener3, true);
563
683
  }
564
684
  function removeCaptureUnhandledrejectionError() {
565
685
  var _a2;
566
- (_a2 = global7 == null ? void 0 : global7.removeEventListener) == null ? void 0 : _a2.call(global7, "unhandledrejection", listener3, true);
686
+ (_a2 = global8 == null ? void 0 : global8.removeEventListener) == null ? void 0 : _a2.call(global8, "unhandledrejection", listener3, true);
567
687
  }
568
688
 
569
689
  // src/capture/index.ts
@@ -585,8 +705,8 @@ function removeCaptureNetwork() {
585
705
  removeCaptureFetchError();
586
706
  }
587
707
  function captureScript() {
588
- const global9 = getGlobal8();
589
- if (!global9.addEventListener)
708
+ const global10 = getGlobal9();
709
+ if (!global10.addEventListener)
590
710
  return;
591
711
  captureUncaughtError();
592
712
  captureUnhandledrejectionError();
@@ -596,6 +716,7 @@ function removeCaptureScript() {
596
716
  removeCaptureUnhandledrejectionError();
597
717
  }
598
718
  function handleCapture() {
719
+ replaceAddEventListener();
599
720
  captureScript();
600
721
  captureNetwork();
601
722
  captureAction();
@@ -603,14 +724,15 @@ function handleCapture() {
603
724
  }
604
725
 
605
726
  // src/destroy.ts
606
- import { getGlobal as getGlobal9 } from "@ohbug/utils";
607
- var global8 = getGlobal9();
727
+ import { getGlobal as getGlobal10 } from "@ohbug/utils";
728
+ var global9 = getGlobal10();
608
729
  function handleDestroy() {
609
730
  var _a2;
610
- (_a2 = global8 == null ? void 0 : global8.addEventListener) == null ? void 0 : _a2.call(
611
- global8,
731
+ (_a2 = global9 == null ? void 0 : global9.addEventListener) == null ? void 0 : _a2.call(
732
+ global9,
612
733
  "unload",
613
734
  () => {
735
+ removeReplaceAddEventListener();
614
736
  removeCaptureScript();
615
737
  removeCaptureNetwork();
616
738
  removeCaptureAction();
@@ -670,13 +792,13 @@ function notifier(event) {
670
792
 
671
793
  // src/client.ts
672
794
  function createClient(config) {
673
- const global9 = getGlobal10();
795
+ const global10 = getGlobal11();
674
796
  const sdk = {
675
797
  platform: "ohbug-browser",
676
798
  version
677
799
  };
678
800
  const client = new Client({ sdk, config, device, notifier });
679
- global9.__OHBUG__ = { client };
801
+ global10.__OHBUG__ = { client };
680
802
  client.use(extension);
681
803
  client.__logger.info(
682
804
  `%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.1",
4
4
  "description": "Ohbug SDK for browsers",
5
5
  "license": "Apache-2.0",
6
6
  "author": "chenyueban <jasonchan0527@gmail.com>",