@ohbug/browser 2.5.1 → 2.5.3

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.mjs CHANGED
@@ -1,855 +1,670 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
-
21
- // src/client.ts
22
- import { Client } from "@ohbug/core";
23
- import { getGlobal as getGlobal11 } from "@ohbug/utils";
24
-
25
- // src/device.ts
26
- var device = () => {
27
- const ohbugDevice = {};
28
- if (navigator) {
29
- const {
30
- language,
31
- userAgent,
32
- // @ts-expect-error Chromium only
33
- connection
34
- } = navigator;
35
- ohbugDevice.language = language;
36
- ohbugDevice.userAgent = userAgent;
37
- if (connection) {
38
- ohbugDevice.connection = {
39
- downlink: connection.downlink,
40
- effectiveType: connection.effectiveType,
41
- rtt: connection.rtt
42
- };
43
- }
44
- }
45
- if (document) {
46
- const { title, referrer } = document;
47
- ohbugDevice.title = title;
48
- ohbugDevice.referrer = referrer;
49
- }
50
- if (window.location) {
51
- const { href: url } = window.location;
52
- ohbugDevice.url = url;
53
- }
54
- return ohbugDevice;
55
- };
56
-
57
- // src/version.ts
58
- var version = "2.5.1";
59
-
60
- // src/extension.ts
61
- import { defineExtension } from "@ohbug/core";
62
-
63
- // src/capture/index.ts
64
- import { getGlobal as getGlobal9 } from "@ohbug/utils";
65
-
66
- // src/replaceAddEventListener.ts
67
- import { getGlobal, replace } from "@ohbug/utils";
68
- var global = getGlobal();
69
- var access = "addEventListener" in global;
70
- var EventTargetProto = EventTarget == null ? void 0 : EventTarget.prototype;
71
- var EventTargetOriginal = access ? { addEventListener: EventTarget.prototype.addEventListener } : {};
1
+ import { Client, EventTypes, defineExtension } from "@ohbug/core";
2
+ import { getGlobal, getOhbugObject, getSelector, parseUrl, replace } from "@ohbug/utils";
3
+ import ErrorStackParser from "error-stack-parser";
4
+ //#region src/replaceAddEventListener.ts
5
+ const access$2 = "addEventListener" in getGlobal();
6
+ const EventTargetProto = EventTarget?.prototype;
7
+ const EventTargetOriginal = access$2 ? { addEventListener: EventTarget.prototype.addEventListener.bind(EventTarget.prototype) } : {};
72
8
  function replaceAddEventListener() {
73
- EventTargetProto.addEventListener = replace(
74
- EventTargetProto,
75
- "addEventListener",
76
- (origin) => function call(type, listener4, options) {
77
- const wrappedListener = function(...args) {
78
- try {
79
- return listener4.apply(this, args);
80
- } catch (err) {
81
- throw err;
82
- }
83
- };
84
- return origin.call(this, type, wrappedListener, options);
85
- }
86
- );
9
+ EventTargetProto.addEventListener = replace(EventTargetProto, "addEventListener", (origin) => function call(type, listener, options) {
10
+ const wrappedListener = (...args) => {
11
+ return listener.apply(this, args);
12
+ };
13
+ return origin.call(this, type, wrappedListener, options);
14
+ });
87
15
  }
88
16
  function removeReplaceAddEventListener() {
89
- if (access && EventTargetOriginal.addEventListener) {
90
- const EventTargetProto2 = EventTarget == null ? void 0 : EventTarget.prototype;
91
- EventTargetProto2.addEventListener = EventTargetOriginal.addEventListener;
92
- }
17
+ if (access$2 && EventTargetOriginal.addEventListener) {
18
+ const EventTargetProto = EventTarget?.prototype;
19
+ EventTargetProto.addEventListener = EventTargetOriginal.addEventListener;
20
+ }
21
+ }
22
+ //#endregion
23
+ //#region src/capture/action/captureClick.ts
24
+ const global$6 = getGlobal();
25
+ function listener$2(e) {
26
+ if (e.target) {
27
+ const { client } = getOhbugObject();
28
+ const { tagName, id, className, name, src, nodeType } = e.target;
29
+ if (tagName.toUpperCase() !== "HTML" && tagName.toUpperCase() !== "BODY") {
30
+ const selector = getSelector(e);
31
+ client.addAction("click node", {
32
+ tagName,
33
+ id: id || void 0,
34
+ className: className || void 0,
35
+ name: name || void 0,
36
+ src: src || void 0,
37
+ nodeType: nodeType || void 0,
38
+ selector: selector || void 0
39
+ }, "click");
40
+ }
41
+ }
93
42
  }
94
-
95
- // src/capture/action/captureUrlChange.ts
96
- import { getGlobal as getGlobal2, getOhbugObject, parseUrl, replace as replace2 } from "@ohbug/utils";
97
- var global2 = getGlobal2();
98
- var lastHref;
43
+ function captureClick() {
44
+ global$6?.document?.addEventListener?.("click", listener$2);
45
+ }
46
+ function removeCaptureClick() {
47
+ global$6?.document?.removeEventListener?.("click", listener$2);
48
+ }
49
+ //#endregion
50
+ //#region src/capture/action/captureUrlChange.ts
51
+ const global$5 = getGlobal();
52
+ let lastHref;
99
53
  function handleUrlChange(from, to) {
100
- var _a2;
101
- const { client } = getOhbugObject();
102
- const parsedHref = parseUrl((_a2 = global2 == null ? void 0 : global2.location) == null ? void 0 : _a2.href);
103
- let parsedFrom = parseUrl(from);
104
- const parsedTo = parseUrl(to);
105
- if (!parsedFrom.path) {
106
- parsedFrom = parsedHref;
107
- }
108
- lastHref = to;
109
- let targetFrom = from;
110
- let targetTo = to;
111
- if (parsedHref.protocol === parsedTo.protocol && parsedHref.host === parsedTo.host) {
112
- targetTo = parsedTo.relative;
113
- }
114
- if (parsedHref.protocol === parsedFrom.protocol && parsedHref.host === parsedFrom.host) {
115
- targetFrom = parsedFrom.relative;
116
- }
117
- if (targetFrom === targetTo)
118
- return;
119
- client.addAction(
120
- `navigation to ${to}`,
121
- {
122
- from,
123
- to
124
- },
125
- "navigation"
126
- );
54
+ const { client } = getOhbugObject();
55
+ const parsedHref = parseUrl(global$5?.location?.href);
56
+ let parsedFrom = parseUrl(from);
57
+ const parsedTo = parseUrl(to);
58
+ if (!parsedFrom.path) parsedFrom = parsedHref;
59
+ lastHref = to;
60
+ let targetFrom = from;
61
+ let targetTo = to;
62
+ if (parsedHref.protocol === parsedTo.protocol && parsedHref.host === parsedTo.host) targetTo = parsedTo.relative;
63
+ if (parsedHref.protocol === parsedFrom.protocol && parsedHref.host === parsedFrom.host) targetFrom = parsedFrom.relative;
64
+ if (targetFrom === targetTo) return;
65
+ client.addAction(`navigation to ${to}`, {
66
+ from,
67
+ to
68
+ }, "navigation");
127
69
  }
128
70
  function historyReplacement(original) {
129
- return function call(data, title, url) {
130
- if (url) {
131
- handleUrlChange(lastHref, String(url));
132
- }
133
- return original.apply(this, [data, title, url]);
134
- };
135
- }
136
- var _a, _b;
137
- var historyOriginal = {
138
- pushState: (_a = global2 == null ? void 0 : global2.history) == null ? void 0 : _a.pushState,
139
- replaceState: (_b = global2 == null ? void 0 : global2.history) == null ? void 0 : _b.replaceState,
140
- onpopstate: global2 == null ? void 0 : global2.onpopstate
71
+ return function call(data, title, url) {
72
+ if (url) handleUrlChange(lastHref, String(url));
73
+ return original.apply(this, [
74
+ data,
75
+ title,
76
+ url
77
+ ]);
78
+ };
79
+ }
80
+ const historyOriginal = {
81
+ pushState: global$5?.history?.pushState?.bind(global$5?.history),
82
+ replaceState: global$5?.history?.replaceState?.bind(global$5?.history),
83
+ onpopstate: global$5?.onpopstate
141
84
  };
142
85
  function historyListener() {
143
- historyOriginal.pushState = replace2(
144
- global2 == null ? void 0 : global2.history,
145
- "pushState",
146
- historyReplacement
147
- );
148
- historyOriginal.replaceState = replace2(
149
- global2 == null ? void 0 : global2.history,
150
- "replaceState",
151
- historyReplacement
152
- );
153
- historyOriginal.onpopstate = replace2(
154
- global2,
155
- "onpopstate",
156
- (origin) => function call(...args) {
157
- var _a2;
158
- const current = (_a2 = global2 == null ? void 0 : global2.location) == null ? void 0 : _a2.href;
159
- handleUrlChange(lastHref, current);
160
- return origin == null ? void 0 : origin.apply(this, args);
161
- }
162
- );
86
+ historyOriginal.pushState = replace(global$5?.history, "pushState", historyReplacement);
87
+ historyOriginal.replaceState = replace(global$5?.history, "replaceState", historyReplacement);
88
+ historyOriginal.onpopstate = replace(global$5, "onpopstate", (origin) => function call(...args) {
89
+ const current = global$5?.location?.href;
90
+ handleUrlChange(lastHref, current);
91
+ return origin?.apply(this, args);
92
+ });
163
93
  }
164
94
  function hashListener(e) {
165
- const { oldURL, newURL } = e;
166
- handleUrlChange(oldURL, newURL);
95
+ const { oldURL, newURL } = e;
96
+ handleUrlChange(oldURL, newURL);
167
97
  }
168
98
  function captureUrlChange() {
169
- var _a2;
170
- historyListener();
171
- (_a2 = global2 == null ? void 0 : global2.addEventListener) == null ? void 0 : _a2.call(global2, "hashchange", hashListener, true);
99
+ historyListener();
100
+ global$5?.addEventListener?.("hashchange", hashListener, true);
172
101
  }
173
102
  function removeCaptureUrlChange() {
174
- var _a2;
175
- global2.history.pushState = historyOriginal.pushState;
176
- global2.history.replaceState = historyOriginal.replaceState;
177
- global2.onpopstate = historyOriginal.onpopstate;
178
- (_a2 = global2 == null ? void 0 : global2.removeEventListener) == null ? void 0 : _a2.call(global2, "hashchange", hashListener, true);
179
- }
180
-
181
- // src/capture/action/captureClick.ts
182
- import { getGlobal as getGlobal3, getOhbugObject as getOhbugObject2, getSelector } from "@ohbug/utils";
183
- var global3 = getGlobal3();
184
- function listener(e) {
185
- if (e.target) {
186
- const { client } = getOhbugObject2();
187
- const { tagName, id, className, name, src, nodeType } = e.target;
188
- if (tagName.toUpperCase() !== "HTML" && tagName.toUpperCase() !== "BODY") {
189
- const selector = getSelector(e);
190
- client.addAction(
191
- "click node",
192
- {
193
- tagName,
194
- id: id || void 0,
195
- className: className || void 0,
196
- name: name || void 0,
197
- src: src || void 0,
198
- nodeType: nodeType || void 0,
199
- selector: selector || void 0
200
- },
201
- "click"
202
- );
203
- }
204
- }
205
- }
206
- function captureClick() {
207
- var _a2, _b2;
208
- (_b2 = (_a2 = global3 == null ? void 0 : global3.document) == null ? void 0 : _a2.addEventListener) == null ? void 0 : _b2.call(_a2, "click", listener);
209
- }
210
- function removeCaptureClick() {
211
- var _a2, _b2;
212
- (_b2 = (_a2 = global3 == null ? void 0 : global3.document) == null ? void 0 : _a2.removeEventListener) == null ? void 0 : _b2.call(_a2, "click", listener);
213
- }
214
-
215
- // src/capture/console/captureConsole.ts
216
- import { getOhbugObject as getOhbugObject3, replace as replace3 } from "@ohbug/utils";
217
- var levels = ["log", "info", "warn", "error"];
218
- var consoleOriginal = Object.keys(levels).reduce(
219
- (acc, cur) => __spreadProps(__spreadValues({}, acc), {
220
- // @ts-expect-error 修改了原生的console
221
- [cur]: console[cur]
222
- }),
223
- {
224
- log: null,
225
- info: null,
226
- warn: null,
227
- error: null
228
- }
229
- );
103
+ global$5.history.pushState = historyOriginal.pushState;
104
+ global$5.history.replaceState = historyOriginal.replaceState;
105
+ global$5.onpopstate = historyOriginal.onpopstate;
106
+ global$5?.removeEventListener?.("hashchange", hashListener, true);
107
+ }
108
+ //#endregion
109
+ //#region src/capture/console/captureConsole.ts
110
+ const levels = [
111
+ "log",
112
+ "info",
113
+ "warn",
114
+ "error"
115
+ ];
116
+ const consoleOriginal = Object.keys(levels).reduce((acc, cur) => ({
117
+ ...acc,
118
+ [cur]: console[cur]
119
+ }), {
120
+ log: null,
121
+ info: null,
122
+ warn: null,
123
+ error: null
124
+ });
230
125
  function captureConsole() {
231
- const { client } = getOhbugObject3();
232
- levels.forEach((level) => {
233
- consoleOriginal[level] = replace3(
234
- console,
235
- level,
236
- (origin) => function call(...args) {
237
- const isOhbugConsole = args.some((arg) => typeof arg === "string" && arg.includes("Ohbug"));
238
- if (!isOhbugConsole) {
239
- client.addAction(`console.${level}`, args, "console");
240
- }
241
- return origin.apply(this, args);
242
- }
243
- );
244
- });
126
+ const { client } = getOhbugObject();
127
+ levels.forEach((level) => {
128
+ consoleOriginal[level] = replace(console, level, (origin) => function call(...args) {
129
+ if (!args.some((arg) => typeof arg === "string" && arg.includes("Ohbug"))) client.addAction(`console.${level}`, args, "console");
130
+ return origin.apply(this, args);
131
+ });
132
+ });
245
133
  }
246
134
  function removeCaptureConsole() {
247
- if (console) {
248
- levels.forEach((level) => {
249
- console[level] = consoleOriginal[level];
250
- });
251
- }
135
+ if (console) levels.forEach((level) => {
136
+ console[level] = consoleOriginal[level];
137
+ });
252
138
  }
253
-
254
- // src/capture/network/captureAjaxError.ts
255
- import { getGlobal as getGlobal4, getOhbugObject as getOhbugObject11, replace as replace4 } from "@ohbug/utils";
256
- import { EventTypes as EventTypes9 } from "@ohbug/core";
257
-
258
- // src/handle/uncaughtErrorHandler.ts
259
- import { getOhbugObject as getOhbugObject4 } from "@ohbug/utils";
260
- import { EventTypes } from "@ohbug/core";
261
- import ErrorStackParser from "error-stack-parser";
139
+ //#endregion
140
+ //#region src/handle/uncaughtErrorHandler.ts
262
141
  function uncaughtErrorHandler(e) {
263
- var _a2, _b2, _c, _d;
264
- const detail = {
265
- name: (_a2 = e == null ? void 0 : e.error) == null ? void 0 : _a2.name,
266
- message: (e == null ? void 0 : e.message) || ((_b2 = e == null ? void 0 : e.error) == null ? void 0 : _b2.message),
267
- filename: e == null ? void 0 : e.filename,
268
- lineno: e == null ? void 0 : e.lineno,
269
- colno: e == null ? void 0 : e.colno,
270
- stack: (_c = e == null ? void 0 : e.error) == null ? void 0 : _c.stack
271
- };
272
- if (e.error) {
273
- try {
274
- const stackFrame = (_d = ErrorStackParser.parse(e.error)) == null ? void 0 : _d[0];
275
- if (stackFrame) {
276
- detail.filename = stackFrame.fileName;
277
- detail.lineno = stackFrame.lineNumber;
278
- detail.colno = stackFrame.columnNumber;
279
- }
280
- } catch (_) {
281
- }
282
- }
283
- const { client } = getOhbugObject4();
284
- const event = client.createEvent({
285
- category: "error",
286
- type: EventTypes.UNCAUGHT_ERROR,
287
- detail
288
- });
289
- client.notify(event);
290
- }
291
-
292
- // src/handle/resourceErrorHandler.ts
293
- import { getOhbugObject as getOhbugObject5, getSelector as getSelector2 } from "@ohbug/utils";
294
- import { EventTypes as EventTypes2 } from "@ohbug/core";
142
+ const detail = {
143
+ name: e?.error?.name,
144
+ message: e?.message || e?.error?.message,
145
+ filename: e?.filename,
146
+ lineno: e?.lineno,
147
+ colno: e?.colno,
148
+ stack: e?.error?.stack
149
+ };
150
+ if (e.error) try {
151
+ const stackFrame = ErrorStackParser.parse(e.error)?.[0];
152
+ if (stackFrame) {
153
+ detail.filename = stackFrame.fileName;
154
+ detail.lineno = stackFrame.lineNumber;
155
+ detail.colno = stackFrame.columnNumber;
156
+ }
157
+ } catch {}
158
+ const { client } = getOhbugObject();
159
+ const event = client.createEvent({
160
+ category: "error",
161
+ type: EventTypes.UNCAUGHT_ERROR,
162
+ detail
163
+ });
164
+ client.notify(event);
165
+ }
166
+ //#endregion
167
+ //#region src/handle/resourceErrorHandler.ts
295
168
  function resourceErrorHandler(e) {
296
- const target = e.target || e.srcElement;
297
- const selector = getSelector2(e);
298
- const detail = {
299
- src: target && target.src,
300
- tagName: target && target.tagName,
301
- id: target && target.id,
302
- className: target && target.className,
303
- name: target && target.name,
304
- // https://developer.mozilla.org/zh-CN/docs/Web/API/Node/nodeType
305
- nodeType: target && target.nodeType,
306
- selector
307
- };
308
- const { client } = getOhbugObject5();
309
- const event = client.createEvent({
310
- category: "error",
311
- type: EventTypes2.RESOURCE_ERROR,
312
- detail
313
- });
314
- client.notify(event);
315
- }
316
-
317
- // src/handle/unhandledrejectionErrorHandler.ts
318
- import { getOhbugObject as getOhbugObject6 } from "@ohbug/utils";
319
- import { EventTypes as EventTypes3 } from "@ohbug/core";
320
- import ErrorStackParser2 from "error-stack-parser";
169
+ const target = e.target || e.srcElement;
170
+ const selector = getSelector(e);
171
+ const detail = {
172
+ src: target && target.src,
173
+ tagName: target && target.tagName,
174
+ id: target && target.id,
175
+ className: target && target.className,
176
+ name: target && target.name,
177
+ nodeType: target && target.nodeType,
178
+ selector
179
+ };
180
+ const { client } = getOhbugObject();
181
+ const event = client.createEvent({
182
+ category: "error",
183
+ type: EventTypes.RESOURCE_ERROR,
184
+ detail
185
+ });
186
+ client.notify(event);
187
+ }
188
+ //#endregion
189
+ //#region src/handle/unhandledrejectionErrorHandler.ts
321
190
  function unhandledrejectionErrorHandler(e) {
322
- var _a2, _b2, _c, _d;
323
- const detail = {
324
- name: (_a2 = e == null ? void 0 : e.reason) == null ? void 0 : _a2.name,
325
- message: ((_b2 = e == null ? void 0 : e.reason) == null ? void 0 : _b2.message) || (e == null ? void 0 : e.reason),
326
- stack: (_c = e == null ? void 0 : e.reason) == null ? void 0 : _c.stack
327
- };
328
- if (e.reason) {
329
- try {
330
- const stackFrame = (_d = ErrorStackParser2.parse(e.reason)) == null ? void 0 : _d[0];
331
- if (stackFrame) {
332
- detail.filename = stackFrame.fileName;
333
- detail.lineno = stackFrame.lineNumber;
334
- detail.colno = stackFrame.columnNumber;
335
- }
336
- } catch (_) {
337
- }
338
- }
339
- const { client } = getOhbugObject6();
340
- const event = client.createEvent({
341
- category: "error",
342
- type: EventTypes3.UNHANDLEDREJECTION_ERROR,
343
- detail
344
- });
345
- client.notify(event);
346
- }
347
-
348
- // src/handle/unknownErrorHandler.ts
349
- import { getOhbugObject as getOhbugObject7 } from "@ohbug/utils";
350
- import { EventTypes as EventTypes4 } from "@ohbug/core";
351
- import ErrorStackParser3 from "error-stack-parser";
191
+ const detail = {
192
+ name: e?.reason?.name,
193
+ message: e?.reason?.message || e?.reason,
194
+ stack: e?.reason?.stack
195
+ };
196
+ if (e.reason) try {
197
+ const stackFrame = ErrorStackParser.parse(e.reason)?.[0];
198
+ if (stackFrame) {
199
+ detail.filename = stackFrame.fileName;
200
+ detail.lineno = stackFrame.lineNumber;
201
+ detail.colno = stackFrame.columnNumber;
202
+ }
203
+ } catch {}
204
+ const { client } = getOhbugObject();
205
+ const event = client.createEvent({
206
+ category: "error",
207
+ type: EventTypes.UNHANDLEDREJECTION_ERROR,
208
+ detail
209
+ });
210
+ client.notify(event);
211
+ }
212
+ //#endregion
213
+ //#region src/handle/unknownErrorHandler.ts
352
214
  function unknownErrorHandler(e) {
353
- var _a2, _b2, _c, _d;
354
- const detail = {
355
- name: (_a2 = e == null ? void 0 : e.error) == null ? void 0 : _a2.name,
356
- message: (e == null ? void 0 : e.message) || ((_b2 = e == null ? void 0 : e.error) == null ? void 0 : _b2.message),
357
- filename: e == null ? void 0 : e.filename,
358
- lineno: e == null ? void 0 : e.lineno,
359
- colno: e == null ? void 0 : e.colno,
360
- stack: (_c = e == null ? void 0 : e.error) == null ? void 0 : _c.stack
361
- };
362
- if (e.error) {
363
- try {
364
- const stackFrame = (_d = ErrorStackParser3.parse(e.error)) == null ? void 0 : _d[0];
365
- if (stackFrame) {
366
- detail.filename = stackFrame.fileName;
367
- detail.lineno = stackFrame.lineNumber;
368
- detail.colno = stackFrame.columnNumber;
369
- }
370
- } catch (_) {
371
- }
372
- }
373
- const { client } = getOhbugObject7();
374
- const event = client.createEvent({
375
- category: "error",
376
- type: EventTypes4.UNKNOWN_ERROR,
377
- detail
378
- });
379
- client.notify(event);
380
- }
381
-
382
- // src/handle/ajaxErrorHandler.ts
383
- import { getOhbugObject as getOhbugObject8 } from "@ohbug/utils";
384
- import { EventTypes as EventTypes5 } from "@ohbug/core";
215
+ const detail = {
216
+ name: e?.error?.name,
217
+ message: e?.message || e?.error?.message,
218
+ filename: e?.filename,
219
+ lineno: e?.lineno,
220
+ colno: e?.colno,
221
+ stack: e?.error?.stack
222
+ };
223
+ if (e.error) try {
224
+ const stackFrame = ErrorStackParser.parse(e.error)?.[0];
225
+ if (stackFrame) {
226
+ detail.filename = stackFrame.fileName;
227
+ detail.lineno = stackFrame.lineNumber;
228
+ detail.colno = stackFrame.columnNumber;
229
+ }
230
+ } catch {}
231
+ const { client } = getOhbugObject();
232
+ const event = client.createEvent({
233
+ category: "error",
234
+ type: EventTypes.UNKNOWN_ERROR,
235
+ detail
236
+ });
237
+ client.notify(event);
238
+ }
239
+ //#endregion
240
+ //#region src/handle/ajaxErrorHandler.ts
385
241
  function ajaxErrorHandler(detail) {
386
- const { client } = getOhbugObject8();
387
- const event = client.createEvent({
388
- category: "error",
389
- type: EventTypes5.AJAX_ERROR,
390
- detail
391
- });
392
- client.notify(event);
393
- }
394
-
395
- // src/handle/fetchErrorHandler.ts
396
- import { getOhbugObject as getOhbugObject9 } from "@ohbug/utils";
397
- import { EventTypes as EventTypes6 } from "@ohbug/core";
242
+ const { client } = getOhbugObject();
243
+ const event = client.createEvent({
244
+ category: "error",
245
+ type: EventTypes.AJAX_ERROR,
246
+ detail
247
+ });
248
+ client.notify(event);
249
+ }
250
+ //#endregion
251
+ //#region src/handle/fetchErrorHandler.ts
398
252
  function fetchErrorHandler(detail) {
399
- const { client } = getOhbugObject9();
400
- const event = client.createEvent({
401
- category: "error",
402
- type: EventTypes6.FETCH_ERROR,
403
- detail
404
- });
405
- client.notify(event);
406
- }
407
-
408
- // src/handle/websocketErrorHandler.ts
409
- import { getOhbugObject as getOhbugObject10 } from "@ohbug/utils";
410
- import { EventTypes as EventTypes7 } from "@ohbug/core";
253
+ const { client } = getOhbugObject();
254
+ const event = client.createEvent({
255
+ category: "error",
256
+ type: EventTypes.FETCH_ERROR,
257
+ detail
258
+ });
259
+ client.notify(event);
260
+ }
261
+ //#endregion
262
+ //#region src/handle/websocketErrorHandler.ts
411
263
  function websocketErrorHandler(detail) {
412
- const { client } = getOhbugObject10();
413
- const event = client.createEvent({
414
- category: "error",
415
- type: EventTypes7.WEBSOCKET_ERROR,
416
- detail
417
- });
418
- client.notify(event);
419
- }
420
-
421
- // src/dispatch/scriptDispatcher.ts
264
+ const { client } = getOhbugObject();
265
+ const event = client.createEvent({
266
+ category: "error",
267
+ type: EventTypes.WEBSOCKET_ERROR,
268
+ detail
269
+ });
270
+ client.notify(event);
271
+ }
272
+ //#endregion
273
+ //#region src/dispatch/scriptDispatcher.ts
422
274
  function scriptDispatcher(e) {
423
- try {
424
- const { type } = e;
425
- if (type === "error") {
426
- const targetEvent = e;
427
- const { message, error } = targetEvent;
428
- const immutableTarget = e.target || e.srcElement;
429
- if (message && error) {
430
- uncaughtErrorHandler(targetEvent);
431
- } else if (immutableTarget) {
432
- resourceErrorHandler(targetEvent);
433
- }
434
- } else if (type === "unhandledrejection") {
435
- unhandledrejectionErrorHandler(e);
436
- } else {
437
- unknownErrorHandler(e);
438
- }
439
- } catch (error) {
440
- unknownErrorHandler(error);
441
- }
442
- }
443
-
444
- // src/dispatch/networkDispatcher.ts
445
- import { EventTypes as EventTypes8 } from "@ohbug/core";
275
+ try {
276
+ const { type } = e;
277
+ if (type === "error") {
278
+ const targetEvent = e;
279
+ const { message, error } = targetEvent;
280
+ const immutableTarget = e.target || e.srcElement;
281
+ if (message && error) uncaughtErrorHandler(targetEvent);
282
+ else if (immutableTarget) resourceErrorHandler(targetEvent);
283
+ } else if (type === "unhandledrejection") unhandledrejectionErrorHandler(e);
284
+ else unknownErrorHandler(e);
285
+ } catch (error) {
286
+ unknownErrorHandler(error);
287
+ }
288
+ }
289
+ //#endregion
290
+ //#region src/dispatch/networkDispatcher.ts
446
291
  function networkDispatcher(type, detail) {
447
- try {
448
- switch (type) {
449
- case EventTypes8.AJAX_ERROR:
450
- ajaxErrorHandler(detail);
451
- break;
452
- case EventTypes8.FETCH_ERROR:
453
- fetchErrorHandler(detail);
454
- break;
455
- case EventTypes8.WEBSOCKET_ERROR:
456
- websocketErrorHandler(detail);
457
- break;
458
- default:
459
- break;
460
- }
461
- } catch (error) {
462
- unknownErrorHandler(error);
463
- }
464
- }
465
-
466
- // src/capture/network/getParams.ts
467
- var groupParamsByKey = (params) => (
468
- // @ts-expect-error worked
469
- [...params.entries()].reduce((acc, tuple) => {
470
- const [key, val] = tuple;
471
- if (acc.hasOwnProperty(key)) {
472
- if (Array.isArray(acc[key])) {
473
- acc[key] = [...acc[key], val];
474
- } else {
475
- acc[key] = [acc[key], val];
476
- }
477
- } else {
478
- acc[key] = val;
479
- }
480
- return acc;
481
- }, {})
482
- );
292
+ try {
293
+ switch (type) {
294
+ case EventTypes.AJAX_ERROR:
295
+ ajaxErrorHandler(detail);
296
+ break;
297
+ case EventTypes.FETCH_ERROR:
298
+ fetchErrorHandler(detail);
299
+ break;
300
+ case EventTypes.WEBSOCKET_ERROR:
301
+ websocketErrorHandler(detail);
302
+ break;
303
+ default: break;
304
+ }
305
+ } catch (error) {
306
+ unknownErrorHandler(error);
307
+ }
308
+ }
309
+ //#endregion
310
+ //#region src/capture/network/getParams.ts
311
+ const groupParamsByKey = (params) => [...params.entries()].reduce((acc, tuple) => {
312
+ const [key, val] = tuple;
313
+ if (acc.hasOwnProperty(key)) if (Array.isArray(acc[key])) acc[key] = [...acc[key], val];
314
+ else acc[key] = [acc[key], val];
315
+ else acc[key] = val;
316
+ return acc;
317
+ }, {});
483
318
  function getParams(data) {
484
- try {
485
- const location = new URL(data);
486
- const url = location.origin + location.pathname;
487
- const searchParams = location.search ? location.searchParams : void 0;
488
- const params = searchParams ? JSON.stringify(groupParamsByKey(searchParams)) : void 0;
489
- return {
490
- url,
491
- params
492
- };
493
- } catch (_) {
494
- const location = data.split("?");
495
- const url = location == null ? void 0 : location[0];
496
- const search = location == null ? void 0 : location[1];
497
- const searchParams = search ? new URLSearchParams(search) : void 0;
498
- const params = searchParams ? JSON.stringify(groupParamsByKey(searchParams)) : void 0;
499
- return {
500
- url,
501
- params
502
- };
503
- }
504
- }
505
-
506
- // src/capture/network/captureAjaxError.ts
507
- var global4 = getGlobal4();
508
- var access2 = "XMLHttpRequest" in global4;
509
- var xhrOriginal = access2 ? {
510
- open: XMLHttpRequest.prototype.open,
511
- send: XMLHttpRequest.prototype.send
319
+ try {
320
+ const location = new URL(data);
321
+ const url = location.origin + location.pathname;
322
+ const searchParams = location.search ? location.searchParams : void 0;
323
+ return {
324
+ url,
325
+ params: searchParams ? JSON.stringify(groupParamsByKey(searchParams)) : void 0
326
+ };
327
+ } catch {
328
+ const location = data.split("?");
329
+ const url = location?.[0];
330
+ const search = location?.[1];
331
+ const searchParams = search ? new URLSearchParams(search) : void 0;
332
+ return {
333
+ url,
334
+ params: searchParams ? JSON.stringify(groupParamsByKey(searchParams)) : void 0
335
+ };
336
+ }
337
+ }
338
+ //#endregion
339
+ //#region src/capture/network/captureAjaxError.ts
340
+ const access$1 = "XMLHttpRequest" in getGlobal();
341
+ const xhrOriginal = access$1 ? {
342
+ open: XMLHttpRequest.prototype.open.bind(XMLHttpRequest.prototype),
343
+ send: XMLHttpRequest.prototype.send.bind(XMLHttpRequest.prototype)
512
344
  } : {};
345
+ /**
346
+ * capture AJAX_ERROR
347
+ */
513
348
  function captureAjaxError() {
514
- if (!access2)
515
- return;
516
- const { client } = getOhbugObject11();
517
- const desc = {
518
- method: "",
519
- url: ""
520
- };
521
- const xhrProto = XMLHttpRequest == null ? void 0 : XMLHttpRequest.prototype;
522
- xhrOriginal.open = replace4(
523
- xhrProto,
524
- "open",
525
- (origin) => function call(...args) {
526
- const [method, url] = args;
527
- desc.method = method;
528
- desc.url = url;
529
- return origin.apply(this, args);
530
- }
531
- );
532
- xhrOriginal.send = replace4(
533
- xhrProto,
534
- "send",
535
- (origin) => function call(...args) {
536
- this.addEventListener("readystatechange", function handle() {
537
- if (this.readyState === 4) {
538
- if (desc.url !== client.__config.endpoint) {
539
- const { url, params } = getParams(desc.url);
540
- const detail = {
541
- req: {
542
- url,
543
- method: desc.method,
544
- data: args[0],
545
- params
546
- },
547
- res: {
548
- status: this.status,
549
- statusText: this.statusText,
550
- response: this.response
551
- }
552
- };
553
- client.addAction("ajax", detail, "ajax");
554
- if (!this.status || this.status >= 400) {
555
- networkDispatcher(EventTypes9.AJAX_ERROR, detail);
556
- }
557
- }
558
- }
559
- });
560
- return origin.apply(this, args);
561
- }
562
- );
349
+ if (!access$1) return;
350
+ const { client } = getOhbugObject();
351
+ const desc = {
352
+ method: "",
353
+ url: ""
354
+ };
355
+ const xhrProto = XMLHttpRequest?.prototype;
356
+ xhrOriginal.open = replace(xhrProto, "open", (origin) => function call(...args) {
357
+ const [method, url] = args;
358
+ desc.method = method;
359
+ desc.url = url;
360
+ return origin.apply(this, args);
361
+ });
362
+ xhrOriginal.send = replace(xhrProto, "send", (origin) => function call(...args) {
363
+ this.addEventListener("readystatechange", function handle() {
364
+ if (this.readyState === 4) {
365
+ if (desc.url !== client.__config.endpoint) {
366
+ const { url, params } = getParams(desc.url);
367
+ const detail = {
368
+ req: {
369
+ url,
370
+ method: desc.method,
371
+ data: args[0],
372
+ params
373
+ },
374
+ res: {
375
+ status: this.status,
376
+ statusText: this.statusText,
377
+ response: this.response
378
+ }
379
+ };
380
+ client.addAction("ajax", detail, "ajax");
381
+ if (!this.status || this.status >= 400) networkDispatcher(EventTypes.AJAX_ERROR, detail);
382
+ }
383
+ }
384
+ });
385
+ return origin.apply(this, args);
386
+ });
563
387
  }
564
388
  function removeCaptureAjaxError() {
565
- if (access2 && xhrOriginal.open && xhrOriginal.send) {
566
- const xhrProto = XMLHttpRequest == null ? void 0 : XMLHttpRequest.prototype;
567
- xhrProto.open = xhrOriginal.open;
568
- xhrProto.send = xhrOriginal.send;
569
- }
570
- }
571
-
572
- // src/capture/network/captureFetchError.ts
573
- import { getGlobal as getGlobal5, getOhbugObject as getOhbugObject12, replace as replace5 } from "@ohbug/utils";
574
- import { EventTypes as EventTypes10 } from "@ohbug/core";
575
- var global5 = getGlobal5();
576
- var access3 = "fetch" in global5;
577
- var fetchOriginal = access3 ? global5.fetch : null;
389
+ if (access$1 && xhrOriginal.open && xhrOriginal.send) {
390
+ const xhrProto = XMLHttpRequest?.prototype;
391
+ xhrProto.open = xhrOriginal.open;
392
+ xhrProto.send = xhrOriginal.send;
393
+ }
394
+ }
395
+ //#endregion
396
+ //#region src/capture/network/captureFetchError.ts
397
+ const global$4 = getGlobal();
398
+ const access = "fetch" in global$4;
399
+ let fetchOriginal = access ? global$4.fetch.bind(global$4) : null;
400
+ /**
401
+ * capture FETCH_ERROR
402
+ */
578
403
  function captureFetchError() {
579
- if (!access3)
580
- return;
581
- const { client } = getOhbugObject12();
582
- fetchOriginal = replace5(
583
- global5,
584
- "fetch",
585
- (origin) => function call(...args) {
586
- return origin.apply(this, args).then(
587
- (res) => {
588
- const [originalUrl, conf] = args;
589
- const { url, params } = getParams(originalUrl);
590
- const detail = {
591
- req: {
592
- url,
593
- method: conf && conf.method,
594
- data: conf && conf.body,
595
- params
596
- },
597
- res: {
598
- status: res.status,
599
- statusText: res.statusText
600
- }
601
- };
602
- client.addAction("fetch", detail, "fetch");
603
- if (!res.status || res.status >= 400) {
604
- networkDispatcher(EventTypes10.FETCH_ERROR, detail);
605
- }
606
- return res;
607
- },
608
- (err) => {
609
- const [originalUrl, conf] = args;
610
- const { url, params } = getParams(originalUrl);
611
- const detail = {
612
- req: {
613
- url,
614
- method: conf && conf.method,
615
- data: conf && conf.body,
616
- params
617
- },
618
- res: { status: 400 }
619
- };
620
- networkDispatcher(EventTypes10.FETCH_ERROR, detail);
621
- throw err;
622
- }
623
- );
624
- }
625
- );
404
+ if (!access) return;
405
+ const { client } = getOhbugObject();
406
+ fetchOriginal = replace(global$4, "fetch", (origin) => function call(...args) {
407
+ return origin.apply(this, args).then((res) => {
408
+ const [originalUrl, conf] = args;
409
+ const { url, params } = getParams(originalUrl);
410
+ const detail = {
411
+ req: {
412
+ url,
413
+ method: conf && conf.method,
414
+ data: conf && conf.body,
415
+ params
416
+ },
417
+ res: {
418
+ status: res.status,
419
+ statusText: res.statusText
420
+ }
421
+ };
422
+ client.addAction("fetch", detail, "fetch");
423
+ if (!res.status || res.status >= 400) networkDispatcher(EventTypes.FETCH_ERROR, detail);
424
+ return res;
425
+ }, (err) => {
426
+ const [originalUrl, conf] = args;
427
+ const { url, params } = getParams(originalUrl);
428
+ const detail = {
429
+ req: {
430
+ url,
431
+ method: conf && conf.method,
432
+ data: conf && conf.body,
433
+ params
434
+ },
435
+ res: {
436
+ status: 0,
437
+ statusText: err.message
438
+ }
439
+ };
440
+ networkDispatcher(EventTypes.FETCH_ERROR, detail);
441
+ throw err;
442
+ });
443
+ });
626
444
  }
627
445
  function removeCaptureFetchError() {
628
- if (access3 && fetchOriginal) {
629
- global5.fetch = fetchOriginal;
630
- }
631
- }
632
-
633
- // src/capture/network/captureWebSocketError.ts
634
- import { getGlobal as getGlobal6 } from "@ohbug/utils";
635
- import { EventTypes as EventTypes11 } from "@ohbug/core";
636
- var global6 = getGlobal6();
446
+ if (access && fetchOriginal) global$4.fetch = fetchOriginal;
447
+ }
448
+ //#endregion
449
+ //#region src/capture/network/captureWebSocketError.ts
450
+ const global$3 = getGlobal();
451
+ /**
452
+ * capture WEBSOCKET_ERROR
453
+ */
637
454
  function captureWebSocketError() {
638
- if (!("WebSocket" in global6))
639
- return;
640
- const wsProto = WebSocket == null ? void 0 : WebSocket.prototype;
641
- const backup = Object.getOwnPropertyDescriptor(wsProto, "onerror");
642
- Object.defineProperty(wsProto, "onerror", {
643
- set() {
644
- var _a2;
645
- const args = arguments;
646
- const arg = args[0];
647
- (_a2 = backup == null ? void 0 : backup.set) == null ? void 0 : _a2.call(this, function call(e) {
648
- const {
649
- target: {
650
- url: originalUrl,
651
- readyState,
652
- protocol,
653
- extensions,
654
- binaryType,
655
- bufferedAmount
656
- },
657
- timeStamp
658
- } = e;
659
- const { url, params } = getParams(originalUrl);
660
- const detail = {
661
- url,
662
- params,
663
- timeStamp,
664
- readyState,
665
- protocol,
666
- extensions,
667
- binaryType,
668
- bufferedAmount
669
- };
670
- networkDispatcher(EventTypes11.WEBSOCKET_ERROR, detail);
671
- arg.apply(this, args);
672
- });
673
- }
674
- });
675
- }
676
-
677
- // src/capture/script/captureUncaughtError.ts
678
- import { getGlobal as getGlobal7 } from "@ohbug/utils";
679
- var global7 = getGlobal7();
680
- function listener2(e) {
681
- scriptDispatcher(e);
682
- }
455
+ if (!("WebSocket" in global$3)) return;
456
+ const wsProto = WebSocket?.prototype;
457
+ const backup = Object.getOwnPropertyDescriptor(wsProto, "onerror");
458
+ Object.defineProperty(wsProto, "onerror", { set() {
459
+ const args = arguments;
460
+ const arg = args[0];
461
+ backup?.set?.call(this, function call(e) {
462
+ const { target: { url: originalUrl, readyState, protocol, extensions, binaryType, bufferedAmount }, timeStamp } = e;
463
+ const { url, params } = getParams(originalUrl);
464
+ const detail = {
465
+ url,
466
+ params,
467
+ timeStamp,
468
+ readyState,
469
+ protocol,
470
+ extensions,
471
+ binaryType,
472
+ bufferedAmount
473
+ };
474
+ networkDispatcher(EventTypes.WEBSOCKET_ERROR, detail);
475
+ arg.apply(this, args);
476
+ });
477
+ } });
478
+ }
479
+ //#endregion
480
+ //#region src/capture/script/captureUncaughtError.ts
481
+ const global$2 = getGlobal();
482
+ function listener$1(e) {
483
+ scriptDispatcher(e);
484
+ }
485
+ /**
486
+ * capture UNCAUGHT_ERROR RESOURCE_ERROR
487
+ */
683
488
  function captureUncaughtError() {
684
- var _a2;
685
- (_a2 = global7 == null ? void 0 : global7.addEventListener) == null ? void 0 : _a2.call(global7, "error", listener2, true);
489
+ global$2?.addEventListener?.("error", listener$1, true);
686
490
  }
687
491
  function removeCaptureUncaughtError() {
688
- var _a2;
689
- (_a2 = global7 == null ? void 0 : global7.removeEventListener) == null ? void 0 : _a2.call(global7, "error", listener2, true);
492
+ global$2?.removeEventListener?.("error", listener$1, true);
690
493
  }
691
-
692
- // src/capture/script/captureUnhandledrejectionError.ts
693
- import { getGlobal as getGlobal8 } from "@ohbug/utils";
694
- var global8 = getGlobal8();
695
- function listener3(e) {
696
- scriptDispatcher(e);
494
+ //#endregion
495
+ //#region src/capture/script/captureUnhandledrejectionError.ts
496
+ const global$1 = getGlobal();
497
+ function listener(e) {
498
+ scriptDispatcher(e);
697
499
  }
500
+ /**
501
+ * capture UNHANDLEDREJECTION_ERROR
502
+ */
698
503
  function captureUnhandledrejectionError() {
699
- var _a2;
700
- (_a2 = global8 == null ? void 0 : global8.addEventListener) == null ? void 0 : _a2.call(global8, "unhandledrejection", listener3, true);
504
+ global$1?.addEventListener?.("unhandledrejection", listener, true);
701
505
  }
702
506
  function removeCaptureUnhandledrejectionError() {
703
- var _a2;
704
- (_a2 = global8 == null ? void 0 : global8.removeEventListener) == null ? void 0 : _a2.call(global8, "unhandledrejection", listener3, true);
507
+ global$1?.removeEventListener?.("unhandledrejection", listener, true);
705
508
  }
706
-
707
- // src/capture/index.ts
509
+ //#endregion
510
+ //#region src/capture/index.ts
708
511
  function captureAction() {
709
- captureUrlChange();
710
- captureClick();
512
+ captureUrlChange();
513
+ captureClick();
711
514
  }
712
515
  function removeCaptureAction() {
713
- removeCaptureUrlChange();
714
- removeCaptureClick();
516
+ removeCaptureUrlChange();
517
+ removeCaptureClick();
715
518
  }
716
519
  function captureNetwork() {
717
- captureAjaxError();
718
- captureFetchError();
719
- captureWebSocketError();
520
+ captureAjaxError();
521
+ captureFetchError();
522
+ captureWebSocketError();
720
523
  }
721
524
  function removeCaptureNetwork() {
722
- removeCaptureAjaxError();
723
- removeCaptureFetchError();
525
+ removeCaptureAjaxError();
526
+ removeCaptureFetchError();
724
527
  }
725
528
  function captureScript() {
726
- const global10 = getGlobal9();
727
- if (!global10.addEventListener)
728
- return;
729
- captureUncaughtError();
730
- captureUnhandledrejectionError();
529
+ if (!getGlobal().addEventListener) return;
530
+ captureUncaughtError();
531
+ captureUnhandledrejectionError();
731
532
  }
732
533
  function removeCaptureScript() {
733
- removeCaptureUncaughtError();
734
- removeCaptureUnhandledrejectionError();
534
+ removeCaptureUncaughtError();
535
+ removeCaptureUnhandledrejectionError();
735
536
  }
736
537
  function handleCapture() {
737
- replaceAddEventListener();
738
- captureScript();
739
- captureNetwork();
740
- captureAction();
741
- captureConsole();
742
- }
743
-
744
- // src/destroy.ts
745
- import { getGlobal as getGlobal10 } from "@ohbug/utils";
746
- var global9 = getGlobal10();
538
+ replaceAddEventListener();
539
+ captureScript();
540
+ captureNetwork();
541
+ captureAction();
542
+ captureConsole();
543
+ }
544
+ //#endregion
545
+ //#region src/destroy.ts
546
+ const global = getGlobal();
747
547
  function destroy() {
748
- removeReplaceAddEventListener();
749
- removeCaptureScript();
750
- removeCaptureNetwork();
751
- removeCaptureAction();
752
- removeCaptureConsole();
548
+ removeReplaceAddEventListener();
549
+ removeCaptureScript();
550
+ removeCaptureNetwork();
551
+ removeCaptureAction();
552
+ removeCaptureConsole();
753
553
  }
754
554
  function handleDestroy() {
755
- var _a2;
756
- (_a2 = global9 == null ? void 0 : global9.addEventListener) == null ? void 0 : _a2.call(
757
- global9,
758
- "unload",
759
- () => {
760
- destroy();
761
- },
762
- true
763
- );
764
- }
765
-
766
- // src/extension.ts
767
- var extension = defineExtension({
768
- name: "OhbugBrowser",
769
- onSetup: () => {
770
- handleCapture();
771
- handleDestroy();
772
- }
555
+ global?.addEventListener?.("unload", () => {
556
+ destroy();
557
+ }, true);
558
+ }
559
+ //#endregion
560
+ //#region src/device.ts
561
+ const device = () => {
562
+ const ohbugDevice = {};
563
+ if (navigator) {
564
+ const { language, userAgent, connection } = navigator;
565
+ ohbugDevice.language = language;
566
+ ohbugDevice.userAgent = userAgent;
567
+ if (connection) ohbugDevice.connection = {
568
+ downlink: connection.downlink,
569
+ effectiveType: connection.effectiveType,
570
+ rtt: connection.rtt
571
+ };
572
+ }
573
+ if (document) {
574
+ const { title, referrer } = document;
575
+ ohbugDevice.title = title;
576
+ ohbugDevice.referrer = referrer;
577
+ }
578
+ if (window.location) {
579
+ const { href: url } = window.location;
580
+ ohbugDevice.url = url;
581
+ }
582
+ return ohbugDevice;
583
+ };
584
+ //#endregion
585
+ //#region src/extension.ts
586
+ const extension = defineExtension({
587
+ name: "OhbugBrowser",
588
+ onSetup: () => {
589
+ handleCapture();
590
+ handleDestroy();
591
+ }
773
592
  });
774
-
775
- // src/notifier.ts
776
- import { getOhbugObject as getOhbugObject13 } from "@ohbug/utils";
777
- var getCircularReplacer = () => {
778
- const seen = /* @__PURE__ */ new WeakSet();
779
- return (_, value) => {
780
- if (typeof value === "object" && value !== null) {
781
- if (seen.has(value)) {
782
- return;
783
- }
784
- seen.add(value);
785
- }
786
- return value;
787
- };
593
+ //#endregion
594
+ //#region src/notifier.ts
595
+ const getCircularReplacer = () => {
596
+ const seen = /* @__PURE__ */ new WeakSet();
597
+ return (_, value) => {
598
+ if (typeof value === "object" && value !== null) {
599
+ if (seen.has(value)) return;
600
+ seen.add(value);
601
+ }
602
+ return value;
603
+ };
788
604
  };
789
605
  function notifier(event) {
790
- const { client } = getOhbugObject13();
791
- const url = client.__config.endpoint;
792
- return new Promise((resolve, reject) => {
793
- const json = JSON.stringify(event, getCircularReplacer());
794
- if (navigator.sendBeacon) {
795
- const result = navigator.sendBeacon(url, json);
796
- resolve(result);
797
- } else {
798
- const xhr = new XMLHttpRequest();
799
- xhr.onreadystatechange = () => {
800
- if (xhr.readyState === XMLHttpRequest.DONE) {
801
- if (xhr.status >= 200 && xhr.status < 300) {
802
- return resolve(xhr.response);
803
- }
804
- reject(xhr);
805
- }
806
- };
807
- xhr.open("POST", url);
808
- xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
809
- xhr.send(json);
810
- }
811
- });
812
- }
813
-
814
- // src/client.ts
815
- function createClient(config, handleDestroy2) {
816
- const global10 = getGlobal11();
817
- const sdk = {
818
- platform: "ohbug-browser",
819
- version
820
- };
821
- const client = new Client({ sdk, config, device, notifier, destroy: handleDestroy2 });
822
- global10.__OHBUG__ = { client };
823
- client.use(extension);
824
- client.__logger.info(
825
- `%c @ohbug/browser %c Detected Ohbug v${version} %c`,
826
- "background:#333; padding: 2px 1px; color: #FFF",
827
- "background:#FF6F61; padding: 2px 1px; color: #FFF",
828
- "background:transparent"
829
- );
830
- return client;
831
- }
832
- var BrowserClient = {
833
- __client: null,
834
- setup(config) {
835
- var _a2;
836
- function destroyClient() {
837
- const global10 = getGlobal11();
838
- destroy();
839
- BrowserClient.__client = null;
840
- global10.__OHBUG__ = void 0;
841
- }
842
- if (BrowserClient.__client) {
843
- (_a2 = BrowserClient.__client.__logger) == null ? void 0 : _a2.warn("setup() has been called. Ignored.");
844
- return BrowserClient.__client;
845
- }
846
- BrowserClient.__client = createClient(config, destroyClient);
847
- return BrowserClient.__client;
848
- }
606
+ const { client } = getOhbugObject();
607
+ const url = client.__config.endpoint;
608
+ return new Promise((resolve, reject) => {
609
+ const json = JSON.stringify(event, getCircularReplacer());
610
+ if (navigator.sendBeacon) resolve(navigator.sendBeacon(url, json));
611
+ else {
612
+ const xhr = new XMLHttpRequest();
613
+ xhr.onreadystatechange = () => {
614
+ if (xhr.readyState === XMLHttpRequest.DONE) {
615
+ if (xhr.status >= 200 && xhr.status < 300) return resolve(xhr.response);
616
+ reject(xhr);
617
+ }
618
+ };
619
+ xhr.open("POST", url);
620
+ xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
621
+ xhr.send(json);
622
+ }
623
+ });
624
+ }
625
+ //#endregion
626
+ //#region src/version.ts
627
+ const version = "2.5.3";
628
+ //#endregion
629
+ //#region src/client.ts
630
+ function createClient(config, handleDestroy) {
631
+ const global = getGlobal();
632
+ const client = new Client({
633
+ sdk: {
634
+ platform: "ohbug-browser",
635
+ version
636
+ },
637
+ config,
638
+ device,
639
+ notifier: config.notifier ?? notifier,
640
+ destroy: handleDestroy
641
+ });
642
+ global.__OHBUG__ = { client };
643
+ client.use(extension);
644
+ client.__logger.info(`%c @ohbug/browser %c Detected Ohbug v${version} %c`, "background:#333; padding: 2px 1px; color: #FFF", "background:#FF6F61; padding: 2px 1px; color: #FFF", "background:transparent");
645
+ return client;
646
+ }
647
+ const BrowserClient = {
648
+ __client: null,
649
+ setup(config) {
650
+ function destroyClient() {
651
+ const global = getGlobal();
652
+ destroy();
653
+ BrowserClient.__client = null;
654
+ global.__OHBUG__ = void 0;
655
+ }
656
+ if (BrowserClient.__client) {
657
+ BrowserClient.__client.__logger?.warn("setup() has been called. Ignored.");
658
+ return BrowserClient.__client;
659
+ }
660
+ BrowserClient.__client = createClient(config, destroyClient);
661
+ return BrowserClient.__client;
662
+ }
849
663
  };
850
-
851
- // src/index.ts
664
+ //#endregion
665
+ //#region src/index.ts
852
666
  var src_default = BrowserClient;
853
- export {
854
- src_default as default
855
- };
667
+ //#endregion
668
+ export { src_default as default };
669
+
670
+ //# sourceMappingURL=index.mjs.map