@ohbug/browser 2.0.0 → 2.0.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.mjs CHANGED
@@ -1,653 +1 @@
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 getGlobal10 } from "@ohbug/utils";
24
-
25
- // src/device.ts
26
- var device = () => {
27
- const ohbugDevice = {};
28
- if (navigator) {
29
- const { language, userAgent } = navigator;
30
- ohbugDevice.language = language;
31
- ohbugDevice.userAgent = userAgent;
32
- }
33
- if (document) {
34
- const { title } = document;
35
- ohbugDevice.title = title;
36
- }
37
- if (window.location) {
38
- const { href: url } = window.location;
39
- ohbugDevice.url = url;
40
- }
41
- return ohbugDevice;
42
- };
43
-
44
- // src/version.ts
45
- var version = "1.0.20";
46
-
47
- // src/extension.ts
48
- import { defineExtension } from "@ohbug/core";
49
-
50
- // src/capture/index.ts
51
- import { getGlobal as getGlobal8 } from "@ohbug/utils";
52
-
53
- // src/capture/action/captureUrlChange.ts
54
- import { getGlobal, getOhbugObject, parseUrl, replace } from "@ohbug/utils";
55
- var global = getGlobal();
56
- var lastHref;
57
- function handleUrlChange(from, to) {
58
- var _a2;
59
- const { client } = getOhbugObject();
60
- const parsedHref = parseUrl((_a2 = global == null ? void 0 : global.location) == null ? void 0 : _a2.href);
61
- let parsedFrom = parseUrl(from);
62
- const parsedTo = parseUrl(to);
63
- if (!parsedFrom.path)
64
- parsedFrom = parsedHref;
65
- lastHref = to;
66
- let targetFrom = from;
67
- let targetTo = to;
68
- if (parsedHref.protocol === parsedTo.protocol && parsedHref.host === parsedTo.host)
69
- targetTo = parsedTo.relative;
70
- if (parsedHref.protocol === parsedFrom.protocol && parsedHref.host === parsedFrom.host)
71
- targetFrom = parsedFrom.relative;
72
- if (targetFrom === targetTo)
73
- return;
74
- client.addAction(`navigation to ${to}`, {
75
- from,
76
- to
77
- }, "navigation");
78
- }
79
- function historyReplacement(original) {
80
- return function call(data, title, url) {
81
- if (url)
82
- handleUrlChange(lastHref, String(url));
83
- return original.apply(this, [data, title, url]);
84
- };
85
- }
86
- var _a, _b;
87
- var historyOriginal = {
88
- pushState: (_a = global == null ? void 0 : global.history) == null ? void 0 : _a.pushState,
89
- replaceState: (_b = global == null ? void 0 : global.history) == null ? void 0 : _b.replaceState,
90
- onpopstate: global == null ? void 0 : global.onpopstate
91
- };
92
- function historyListener() {
93
- historyOriginal.pushState = replace(global == null ? void 0 : global.history, "pushState", historyReplacement);
94
- historyOriginal.replaceState = replace(global == null ? void 0 : global.history, "replaceState", historyReplacement);
95
- historyOriginal.onpopstate = replace(global, "onpopstate", (origin) => function call(...args) {
96
- var _a2;
97
- const current = (_a2 = global == null ? void 0 : global.location) == null ? void 0 : _a2.href;
98
- handleUrlChange(lastHref, current);
99
- return origin == null ? void 0 : origin.apply(this, args);
100
- });
101
- }
102
- function hashListener(e) {
103
- const { oldURL, newURL } = e;
104
- handleUrlChange(oldURL, newURL);
105
- }
106
- function captureUrlChange() {
107
- var _a2;
108
- historyListener();
109
- (_a2 = global == null ? void 0 : global.addEventListener) == null ? void 0 : _a2.call(global, "hashchange", hashListener, true);
110
- }
111
- function removeCaptureUrlChange() {
112
- var _a2;
113
- global.history.pushState = historyOriginal.pushState;
114
- global.history.replaceState = historyOriginal.replaceState;
115
- global.onpopstate = historyOriginal.onpopstate;
116
- (_a2 = global == null ? void 0 : global.removeEventListener) == null ? void 0 : _a2.call(global, "hashchange", hashListener, true);
117
- }
118
-
119
- // src/capture/action/captureClick.ts
120
- import { getGlobal as getGlobal2, getOhbugObject as getOhbugObject2, getSelector } from "@ohbug/utils";
121
- var global2 = getGlobal2();
122
- function listener(e) {
123
- if (e.target) {
124
- const { client } = getOhbugObject2();
125
- const { tagName, id, className, name, src, outerHTML, nodeType } = e.target;
126
- const selector = getSelector(e);
127
- client.addAction("click node", {
128
- tagName,
129
- id,
130
- className,
131
- name,
132
- src,
133
- outerHTML,
134
- nodeType,
135
- selector
136
- }, "click");
137
- }
138
- }
139
- function captureClick() {
140
- var _a2, _b2;
141
- (_b2 = (_a2 = global2 == null ? void 0 : global2.document) == null ? void 0 : _a2.addEventListener) == null ? void 0 : _b2.call(_a2, "click", listener);
142
- }
143
- function removeCaptureClick() {
144
- var _a2, _b2;
145
- (_b2 = (_a2 = global2 == null ? void 0 : global2.document) == null ? void 0 : _a2.removeEventListener) == null ? void 0 : _b2.call(_a2, "click", listener);
146
- }
147
-
148
- // src/capture/console/captureConsole.ts
149
- import { getOhbugObject as getOhbugObject3, replace as replace2 } from "@ohbug/utils";
150
- var levels = ["log", "info", "warn", "error"];
151
- var consoleOriginal = Object.keys(levels).reduce((acc, cur) => __spreadProps(__spreadValues({}, acc), {
152
- [cur]: console[cur]
153
- }), {
154
- log: null,
155
- info: null,
156
- warn: null,
157
- error: null
158
- });
159
- function captureConsole() {
160
- const { client } = getOhbugObject3();
161
- levels.forEach((level) => {
162
- consoleOriginal[level] = replace2(console, level, (origin) => function call(...args) {
163
- const isOhbugConsole = args.some((arg) => typeof arg === "string" && arg.includes("Ohbug"));
164
- if (!isOhbugConsole)
165
- client.addAction(`console.${level}`, args, "console");
166
- return origin.apply(this, args);
167
- });
168
- });
169
- }
170
- function removeCaptureConsole() {
171
- if (console) {
172
- levels.forEach((level) => {
173
- console[level] = consoleOriginal[level];
174
- });
175
- }
176
- }
177
-
178
- // src/capture/network/captureAjaxError.ts
179
- import { getGlobal as getGlobal3, getOhbugObject as getOhbugObject11, replace as replace3 } from "@ohbug/utils";
180
- import { EventTypes as EventTypes9 } from "@ohbug/core";
181
-
182
- // src/handle/uncaughtErrorHandler.ts
183
- import { getOhbugObject as getOhbugObject4 } from "@ohbug/utils";
184
- import { EventTypes } from "@ohbug/core";
185
- function uncaughtErrorHandler(error) {
186
- const {
187
- message,
188
- filename,
189
- lineno,
190
- colno,
191
- error: { stack, name }
192
- } = error;
193
- const detail = {
194
- name,
195
- message,
196
- filename,
197
- lineno,
198
- colno,
199
- stack
200
- };
201
- const { client } = getOhbugObject4();
202
- const event = client.createEvent({
203
- category: "error",
204
- type: EventTypes.UNCAUGHT_ERROR,
205
- detail
206
- });
207
- client.notify(event);
208
- }
209
-
210
- // src/handle/resourceErrorHandler.ts
211
- import { getOhbugObject as getOhbugObject5, getSelector as getSelector2 } from "@ohbug/utils";
212
- import { EventTypes as EventTypes2 } from "@ohbug/core";
213
- function resourceErrorHandler(error) {
214
- const target = error.target || error.srcElement;
215
- const { outerHTML } = target;
216
- const selector = getSelector2(error);
217
- const detail = {
218
- outerHTML,
219
- src: target && target.src,
220
- tagName: target && target.tagName,
221
- id: target && target.id,
222
- className: target && target.className,
223
- name: target && target.name,
224
- nodeType: target && target.nodeType,
225
- selector
226
- };
227
- const { client } = getOhbugObject5();
228
- const event = client.createEvent({
229
- category: "error",
230
- type: EventTypes2.RESOURCE_ERROR,
231
- detail
232
- });
233
- client.notify(event);
234
- }
235
-
236
- // src/handle/unhandledrejectionErrorHandler.ts
237
- import { getOhbugObject as getOhbugObject6 } from "@ohbug/utils";
238
- import { EventTypes as EventTypes3 } from "@ohbug/core";
239
- function unhandledrejectionErrorHandler(error) {
240
- const detail = {
241
- message: error.reason.message || error.reason,
242
- stack: error.reason.stack
243
- };
244
- const { client } = getOhbugObject6();
245
- const event = client.createEvent({
246
- category: "error",
247
- type: EventTypes3.UNHANDLEDREJECTION_ERROR,
248
- detail
249
- });
250
- client.notify(event);
251
- }
252
-
253
- // src/handle/unknownErrorHandler.ts
254
- import { getOhbugObject as getOhbugObject7 } from "@ohbug/utils";
255
- import { EventTypes as EventTypes4 } from "@ohbug/core";
256
- function unknownErrorHandler(error) {
257
- const detail = error.message ? error : { message: error };
258
- const { client } = getOhbugObject7();
259
- const event = client.createEvent({
260
- category: "error",
261
- type: EventTypes4.UNKNOWN_ERROR,
262
- detail
263
- });
264
- client.notify(event);
265
- }
266
-
267
- // src/handle/ajaxErrorHandler.ts
268
- import { getOhbugObject as getOhbugObject8 } from "@ohbug/utils";
269
- import { EventTypes as EventTypes5 } from "@ohbug/core";
270
- function ajaxErrorHandler(detail) {
271
- const { client } = getOhbugObject8();
272
- const event = client.createEvent({
273
- category: "error",
274
- type: EventTypes5.AJAX_ERROR,
275
- detail
276
- });
277
- client.notify(event);
278
- }
279
-
280
- // src/handle/fetchErrorHandler.ts
281
- import { getOhbugObject as getOhbugObject9 } from "@ohbug/utils";
282
- import { EventTypes as EventTypes6 } from "@ohbug/core";
283
- function fetchErrorHandler(detail) {
284
- const { client } = getOhbugObject9();
285
- const event = client.createEvent({
286
- category: "error",
287
- type: EventTypes6.FETCH_ERROR,
288
- detail
289
- });
290
- client.notify(event);
291
- }
292
-
293
- // src/handle/websocketErrorHandler.ts
294
- import { getOhbugObject as getOhbugObject10 } from "@ohbug/utils";
295
- import { EventTypes as EventTypes7 } from "@ohbug/core";
296
- function websocketErrorHandler(detail) {
297
- const { client } = getOhbugObject10();
298
- const event = client.createEvent({
299
- category: "error",
300
- type: EventTypes7.WEBSOCKET_ERROR,
301
- detail
302
- });
303
- client.notify(event);
304
- }
305
-
306
- // src/dispatch/scriptDispatcher.ts
307
- function scriptDispatcher(e) {
308
- try {
309
- const { type } = e;
310
- if (type === "error") {
311
- const targetEvent = e;
312
- const { message, error } = targetEvent;
313
- const immutableTarget = e.target || e.srcElement;
314
- if (message && error)
315
- uncaughtErrorHandler(targetEvent);
316
- else if (immutableTarget)
317
- resourceErrorHandler(targetEvent);
318
- } else if (type === "unhandledrejection") {
319
- unhandledrejectionErrorHandler(e);
320
- } else {
321
- unknownErrorHandler(e);
322
- }
323
- } catch (error) {
324
- unknownErrorHandler(error);
325
- }
326
- }
327
-
328
- // src/dispatch/networkDispatcher.ts
329
- import { EventTypes as EventTypes8 } from "@ohbug/core";
330
- function networkDispatcher(type, detail) {
331
- try {
332
- switch (type) {
333
- case EventTypes8.AJAX_ERROR:
334
- ajaxErrorHandler(detail);
335
- break;
336
- case EventTypes8.FETCH_ERROR:
337
- fetchErrorHandler(detail);
338
- break;
339
- case EventTypes8.WEBSOCKET_ERROR:
340
- websocketErrorHandler(detail);
341
- break;
342
- default:
343
- break;
344
- }
345
- } catch (error) {
346
- unknownErrorHandler(error);
347
- }
348
- }
349
-
350
- // src/capture/network/captureAjaxError.ts
351
- var global3 = getGlobal3();
352
- var access = "XMLHttpRequest" in global3;
353
- var xhrOriginal = access ? {
354
- open: XMLHttpRequest.prototype.open,
355
- send: XMLHttpRequest.prototype.send
356
- } : {};
357
- function captureAjaxError() {
358
- if (!access)
359
- return;
360
- const { client } = getOhbugObject11();
361
- const desc = {
362
- method: "",
363
- url: ""
364
- };
365
- const xhrProto = XMLHttpRequest == null ? void 0 : XMLHttpRequest.prototype;
366
- xhrOriginal.open = replace3(xhrProto, "open", (origin) => function call(...args) {
367
- const [method, url] = args;
368
- desc.method = method;
369
- desc.url = url;
370
- return origin.apply(this, args);
371
- });
372
- xhrOriginal.send = replace3(xhrProto, "send", (origin) => function call(...args) {
373
- this.addEventListener("readystatechange", function handle() {
374
- if (this.readyState === 4) {
375
- if (desc.url !== client.__config.endpoint) {
376
- const detail = {
377
- req: {
378
- url: desc.url,
379
- method: desc.method,
380
- data: args[0] || {}
381
- },
382
- res: {
383
- status: this.status,
384
- statusText: this.statusText,
385
- response: this.response
386
- }
387
- };
388
- client.addAction("ajax", detail, "ajax");
389
- if (!this.status || this.status >= 400)
390
- networkDispatcher(EventTypes9.AJAX_ERROR, detail);
391
- }
392
- }
393
- });
394
- return origin.apply(this, args);
395
- });
396
- }
397
- function removeCaptureAjaxError() {
398
- if (access && xhrOriginal.open && xhrOriginal.send) {
399
- const xhrProto = XMLHttpRequest == null ? void 0 : XMLHttpRequest.prototype;
400
- xhrProto.open = xhrOriginal.open;
401
- xhrProto.send = xhrOriginal.send;
402
- }
403
- }
404
-
405
- // src/capture/network/captureFetchError.ts
406
- import { getGlobal as getGlobal4, getOhbugObject as getOhbugObject12, replace as replace4 } from "@ohbug/utils";
407
- import { EventTypes as EventTypes10 } from "@ohbug/core";
408
- var global4 = getGlobal4();
409
- var access2 = "fetch" in global4;
410
- var fetchOriginal = access2 ? global4.fetch : null;
411
- function captureFetchError() {
412
- if (!access2)
413
- return;
414
- const { client } = getOhbugObject12();
415
- fetchOriginal = replace4(global4, "fetch", (origin) => function call(...args) {
416
- return origin.apply(this, args).then((res) => {
417
- const [url, conf] = args;
418
- const detail = {
419
- req: {
420
- url,
421
- method: conf && conf.method,
422
- data: conf && conf.body || {}
423
- },
424
- res: {
425
- status: res.status,
426
- statusText: res.statusText
427
- }
428
- };
429
- client.addAction("fetch", detail, "fetch");
430
- if (!res.status || res.status >= 400)
431
- networkDispatcher(EventTypes10.FETCH_ERROR, detail);
432
- return res;
433
- }, (err) => {
434
- const [url, conf] = args;
435
- const detail = {
436
- req: {
437
- url,
438
- method: conf && conf.method,
439
- data: conf && conf.body || {}
440
- },
441
- res: {
442
- status: 400,
443
- statusText: "unknownError"
444
- }
445
- };
446
- networkDispatcher(EventTypes10.FETCH_ERROR, detail);
447
- throw err;
448
- });
449
- });
450
- }
451
- function removeCaptureFetchError() {
452
- if (access2 && fetchOriginal)
453
- global4.fetch = fetchOriginal;
454
- }
455
-
456
- // src/capture/network/captureWebSocketError.ts
457
- import { getGlobal as getGlobal5 } from "@ohbug/utils";
458
- import { EventTypes as EventTypes11 } from "@ohbug/core";
459
- var global5 = getGlobal5();
460
- function captureWebSocketError() {
461
- if (!("WebSocket" in global5))
462
- return;
463
- const wsProto = WebSocket == null ? void 0 : WebSocket.prototype;
464
- const backup = Object.getOwnPropertyDescriptor(wsProto, "onerror");
465
- Object.defineProperty(wsProto, "onerror", {
466
- set() {
467
- var _a2;
468
- const args = arguments;
469
- const arg = args[0];
470
- (_a2 = backup == null ? void 0 : backup.set) == null ? void 0 : _a2.call(this, function call(e) {
471
- const {
472
- target: {
473
- url,
474
- readyState,
475
- protocol,
476
- extensions,
477
- binaryType,
478
- bufferedAmount
479
- },
480
- timeStamp
481
- } = e;
482
- const detail = {
483
- url,
484
- timeStamp,
485
- readyState,
486
- protocol,
487
- extensions,
488
- binaryType,
489
- bufferedAmount
490
- };
491
- networkDispatcher(EventTypes11.WEBSOCKET_ERROR, detail);
492
- arg.apply(this, args);
493
- });
494
- }
495
- });
496
- }
497
-
498
- // src/capture/script/captureUncaughtError.ts
499
- import { getGlobal as getGlobal6 } from "@ohbug/utils";
500
- var global6 = getGlobal6();
501
- function listener2(e) {
502
- scriptDispatcher(e);
503
- }
504
- function captureUncaughtError() {
505
- var _a2;
506
- (_a2 = global6 == null ? void 0 : global6.addEventListener) == null ? void 0 : _a2.call(global6, "error", listener2, true);
507
- }
508
- function removeCaptureUncaughtError() {
509
- var _a2;
510
- (_a2 = global6 == null ? void 0 : global6.removeEventListener) == null ? void 0 : _a2.call(global6, "error", listener2, true);
511
- }
512
-
513
- // src/capture/script/captureUnhandledrejectionError.ts
514
- import { getGlobal as getGlobal7 } from "@ohbug/utils";
515
- var global7 = getGlobal7();
516
- function listener3(e) {
517
- scriptDispatcher(e);
518
- }
519
- function captureUnhandledrejectionError() {
520
- var _a2;
521
- (_a2 = global7 == null ? void 0 : global7.addEventListener) == null ? void 0 : _a2.call(global7, "unhandledrejection", listener3, true);
522
- }
523
- function removeCaptureUnhandledrejectionError() {
524
- var _a2;
525
- (_a2 = global7 == null ? void 0 : global7.removeEventListener) == null ? void 0 : _a2.call(global7, "unhandledrejection", listener3, true);
526
- }
527
-
528
- // src/capture/index.ts
529
- function captureAction() {
530
- captureUrlChange();
531
- captureClick();
532
- }
533
- function removeCaptureAction() {
534
- removeCaptureUrlChange();
535
- removeCaptureClick();
536
- }
537
- function captureNetwork() {
538
- captureAjaxError();
539
- captureFetchError();
540
- captureWebSocketError();
541
- }
542
- function removeCaptureNetwork() {
543
- removeCaptureAjaxError();
544
- removeCaptureFetchError();
545
- }
546
- function captureScript() {
547
- const global9 = getGlobal8();
548
- if (!global9.addEventListener)
549
- return;
550
- captureUncaughtError();
551
- captureUnhandledrejectionError();
552
- }
553
- function removeCaptureScript() {
554
- removeCaptureUncaughtError();
555
- removeCaptureUnhandledrejectionError();
556
- }
557
- function handleCapture() {
558
- captureScript();
559
- captureNetwork();
560
- captureAction();
561
- captureConsole();
562
- }
563
-
564
- // src/destroy.ts
565
- import { getGlobal as getGlobal9 } from "@ohbug/utils";
566
- var global8 = getGlobal9();
567
- function handleDestroy() {
568
- var _a2;
569
- (_a2 = global8 == null ? void 0 : global8.addEventListener) == null ? void 0 : _a2.call(global8, "unload", () => {
570
- removeCaptureScript();
571
- removeCaptureNetwork();
572
- removeCaptureAction();
573
- removeCaptureConsole();
574
- }, true);
575
- }
576
-
577
- // src/extension.ts
578
- var extension = defineExtension({
579
- name: "OhbugBrowser",
580
- setup: () => {
581
- handleCapture();
582
- handleDestroy();
583
- }
584
- });
585
-
586
- // src/notifier.ts
587
- import { getOhbugObject as getOhbugObject13 } from "@ohbug/utils";
588
- var getCircularReplacer = () => {
589
- const seen = /* @__PURE__ */ new WeakSet();
590
- return (_, value) => {
591
- if (typeof value === "object" && value !== null) {
592
- if (seen.has(value))
593
- return;
594
- seen.add(value);
595
- }
596
- return value;
597
- };
598
- };
599
- function notifier(event) {
600
- const { client } = getOhbugObject13();
601
- const url = client.__config.endpoint;
602
- return new Promise((resolve, reject) => {
603
- const json = JSON.stringify(event, getCircularReplacer());
604
- if (navigator.sendBeacon) {
605
- const result = navigator.sendBeacon(url, json);
606
- resolve(result);
607
- } else {
608
- const xhr = new XMLHttpRequest();
609
- xhr.onreadystatechange = () => {
610
- if (xhr.readyState === XMLHttpRequest.DONE) {
611
- if (xhr.status >= 200 && xhr.status < 300)
612
- return resolve(xhr.response);
613
- reject(xhr);
614
- }
615
- };
616
- xhr.open("POST", url);
617
- xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
618
- xhr.send(json);
619
- }
620
- });
621
- }
622
-
623
- // src/client.ts
624
- function createClient(config) {
625
- const global9 = getGlobal10();
626
- const sdk = {
627
- platform: "ohbug-browser",
628
- version
629
- };
630
- const client = new Client({ sdk, config, device, notifier });
631
- global9.__OHBUG__ = { client };
632
- client.use(extension);
633
- 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");
634
- return client;
635
- }
636
- var BrowserClient = {
637
- __client: null,
638
- setup(config) {
639
- var _a2;
640
- if (BrowserClient.__client) {
641
- (_a2 = BrowserClient.__client.__logger) == null ? void 0 : _a2.warn("init() has been called. Ignored.");
642
- return BrowserClient.__client;
643
- }
644
- BrowserClient.__client = createClient(config);
645
- return BrowserClient.__client;
646
- }
647
- };
648
-
649
- // src/index.ts
650
- var src_default = BrowserClient;
651
- export {
652
- src_default as default
653
- };
1
+ var ke=Object.defineProperty,He=Object.defineProperties;var Te=Object.getOwnPropertyDescriptors;var q=Object.getOwnPropertySymbols;var We=Object.prototype.hasOwnProperty,_e=Object.prototype.propertyIsEnumerable;var M=(e,t,r)=>t in e?ke(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,P=(e,t)=>{for(var r in t||(t={}))We.call(t,r)&&M(e,r,t[r]);if(q)for(var r of q(t))_e.call(t,r)&&M(e,r,t[r]);return e},X=(e,t)=>He(e,Te(t));import{Client as vt}from"@ohbug/core";import{getGlobal as Dt}from"@ohbug/utils";var K=()=>{let e={};if(navigator){let{language:t,userAgent:r}=navigator;e.language=t,e.userAgent=r}if(document){let{title:t}=document;e.title=t}if(window.location){let{href:t}=window.location;e.url=t}return e};var w="2.0.1";import{defineExtension as xt}from"@ohbug/core";import{getGlobal as dt}from"@ohbug/utils";import{getGlobal as Ue,getOhbugObject as Se,parseUrl as R,replace as C}from"@ohbug/utils";var a=Ue(),j;function k(e,t){var f;let{client:r}=Se(),o=R((f=a==null?void 0:a.location)==null?void 0:f.href),n=R(e),s=R(t);n.path||(n=o),j=t;let i=e,u=t;o.protocol===s.protocol&&o.host===s.host&&(u=s.relative),o.protocol===n.protocol&&o.host===n.host&&(i=n.relative),i!==u&&r.addAction(`navigation to ${t}`,{from:e,to:t},"navigation")}function J(e){return function(r,o,n){return n&&k(j,String(n)),e.apply(this,[r,o,n])}}var $,I,E={pushState:($=a==null?void 0:a.history)==null?void 0:$.pushState,replaceState:(I=a==null?void 0:a.history)==null?void 0:I.replaceState,onpopstate:a==null?void 0:a.onpopstate};function Ae(){E.pushState=C(a==null?void 0:a.history,"pushState",J),E.replaceState=C(a==null?void 0:a.history,"replaceState",J),E.onpopstate=C(a,"onpopstate",e=>function(...r){var n;let o=(n=a==null?void 0:a.location)==null?void 0:n.href;return k(j,o),e==null?void 0:e.apply(this,r)})}function z(e){let{oldURL:t,newURL:r}=e;k(t,r)}function Q(){var e;Ae(),(e=a==null?void 0:a.addEventListener)==null||e.call(a,"hashchange",z,!0)}function V(){var e;a.history.pushState=E.pushState,a.history.replaceState=E.replaceState,a.onpopstate=E.onpopstate,(e=a==null?void 0:a.removeEventListener)==null||e.call(a,"hashchange",z,!0)}import{getGlobal as Le,getOhbugObject as Fe,getSelector as Be}from"@ohbug/utils";var g=Le();function Y(e){if(e.target){let{client:t}=Fe(),{tagName:r,id:o,className:n,name:s,src:i,outerHTML:u,nodeType:f}=e.target,O=Be(e);t.addAction("click node",{tagName:r,id:o,className:n,name:s,src:i,outerHTML:u,nodeType:f,selector:O},"click")}}function Z(){var e,t;(t=(e=g==null?void 0:g.document)==null?void 0:e.addEventListener)==null||t.call(e,"click",Y)}function ee(){var e,t;(t=(e=g==null?void 0:g.document)==null?void 0:e.removeEventListener)==null||t.call(e,"click",Y)}import{getOhbugObject as Ne,replace as Ge}from"@ohbug/utils";var H=["log","info","warn","error"],te=Object.keys(H).reduce((e,t)=>X(P({},e),{[t]:console[t]}),{log:null,info:null,warn:null,error:null});function re(){let{client:e}=Ne();H.forEach(t=>{te[t]=Ge(console,t,r=>function(...n){return n.some(i=>typeof i=="string"&&i.includes("Ohbug"))||e.addAction(`console.${t}`,n,"console"),r.apply(this,n)})})}function T(){console&&H.forEach(e=>{console[e]=te[e]})}import{getGlobal as rt,getOhbugObject as ot,replace as oe}from"@ohbug/utils";import{EventTypes as nt}from"@ohbug/core";import{getOhbugObject as qe}from"@ohbug/utils";import{EventTypes as Me}from"@ohbug/core";function W(e){let{message:t,filename:r,lineno:o,colno:n,error:{stack:s,name:i}}=e,u={name:i,message:t,filename:r,lineno:o,colno:n,stack:s},{client:f}=qe(),O=f.createEvent({category:"error",type:Me.UNCAUGHT_ERROR,detail:u});f.notify(O)}import{getOhbugObject as Pe,getSelector as Xe}from"@ohbug/utils";import{EventTypes as Ke}from"@ohbug/core";function _(e){let t=e.target||e.srcElement,{outerHTML:r}=t,o=Xe(e),n={outerHTML:r,src:t&&t.src,tagName:t&&t.tagName,id:t&&t.id,className:t&&t.className,name:t&&t.name,nodeType:t&&t.nodeType,selector:o},{client:s}=Pe(),i=s.createEvent({category:"error",type:Ke.RESOURCE_ERROR,detail:n});s.notify(i)}import{getOhbugObject as Je}from"@ohbug/utils";import{EventTypes as $e}from"@ohbug/core";function U(e){let t={message:e.reason.message||e.reason,stack:e.reason.stack},{client:r}=Je(),o=r.createEvent({category:"error",type:$e.UNHANDLEDREJECTION_ERROR,detail:t});r.notify(o)}import{getOhbugObject as Ie}from"@ohbug/utils";import{EventTypes as ze}from"@ohbug/core";function y(e){let t=e.message?e:{message:e},{client:r}=Ie(),o=r.createEvent({category:"error",type:ze.UNKNOWN_ERROR,detail:t});r.notify(o)}import{getOhbugObject as Qe}from"@ohbug/utils";import{EventTypes as Ve}from"@ohbug/core";function S(e){let{client:t}=Qe(),r=t.createEvent({category:"error",type:Ve.AJAX_ERROR,detail:e});t.notify(r)}import{getOhbugObject as Ye}from"@ohbug/utils";import{EventTypes as Ze}from"@ohbug/core";function A(e){let{client:t}=Ye(),r=t.createEvent({category:"error",type:Ze.FETCH_ERROR,detail:e});t.notify(r)}import{getOhbugObject as et}from"@ohbug/utils";import{EventTypes as tt}from"@ohbug/core";function L(e){let{client:t}=et(),r=t.createEvent({category:"error",type:tt.WEBSOCKET_ERROR,detail:e});t.notify(r)}function v(e){try{let{type:t}=e;if(t==="error"){let r=e,{message:o,error:n}=r,s=e.target||e.srcElement;o&&n?W(r):s&&_(r)}else t==="unhandledrejection"?U(e):y(e)}catch(t){y(t)}}import{EventTypes as F}from"@ohbug/core";function d(e,t){try{switch(e){case F.AJAX_ERROR:S(t);break;case F.FETCH_ERROR:A(t);break;case F.WEBSOCKET_ERROR:L(t);break;default:break}}catch(r){y(r)}}var it=rt(),B="XMLHttpRequest"in it,x=B?{open:XMLHttpRequest.prototype.open,send:XMLHttpRequest.prototype.send}:{};function ne(){if(!B)return;let{client:e}=ot(),t={method:"",url:""},r=XMLHttpRequest==null?void 0:XMLHttpRequest.prototype;x.open=oe(r,"open",o=>function(...s){let[i,u]=s;return t.method=i,t.url=u,o.apply(this,s)}),x.send=oe(r,"send",o=>function(...s){return this.addEventListener("readystatechange",function(){if(this.readyState===4&&t.url!==e.__config.endpoint){let u={req:{url:t.url,method:t.method,data:s[0]||{}},res:{status:this.status,statusText:this.statusText,response:this.response}};e.addAction("ajax",u,"ajax"),(!this.status||this.status>=400)&&d(nt.AJAX_ERROR,u)}}),o.apply(this,s)})}function ie(){if(B&&x.open&&x.send){let e=XMLHttpRequest==null?void 0:XMLHttpRequest.prototype;e.open=x.open,e.send=x.send}}import{getGlobal as at,getOhbugObject as st,replace as ct}from"@ohbug/utils";import{EventTypes as ae}from"@ohbug/core";var D=at(),G="fetch"in D,N=G?D.fetch:null;function se(){if(!G)return;let{client:e}=st();N=ct(D,"fetch",t=>function(...o){return t.apply(this,o).then(n=>{let[s,i]=o,u={req:{url:s,method:i&&i.method,data:i&&i.body||{}},res:{status:n.status,statusText:n.statusText}};return e.addAction("fetch",u,"fetch"),(!n.status||n.status>=400)&&d(ae.FETCH_ERROR,u),n},n=>{let[s,i]=o,u={req:{url:s,method:i&&i.method,data:i&&i.body||{}},res:{status:400,statusText:"unknownError"}};throw d(ae.FETCH_ERROR,u),n})})}function ce(){G&&N&&(D.fetch=N)}import{getGlobal as pt}from"@ohbug/utils";import{EventTypes as ut}from"@ohbug/core";var lt=pt();function pe(){if(!("WebSocket"in lt))return;let e=WebSocket==null?void 0:WebSocket.prototype,t=Object.getOwnPropertyDescriptor(e,"onerror");Object.defineProperty(e,"onerror",{set(){var n;let r=arguments,o=r[0];(n=t==null?void 0:t.set)==null||n.call(this,function(i){let{target:{url:u,readyState:f,protocol:O,extensions:De,binaryType:we,bufferedAmount:Re},timeStamp:Ce}=i,je={url:u,timeStamp:Ce,readyState:f,protocol:O,extensions:De,binaryType:we,bufferedAmount:Re};d(ut.WEBSOCKET_ERROR,je),o.apply(this,r)})}})}import{getGlobal as mt}from"@ohbug/utils";var l=mt();function ue(e){v(e)}function le(){var e;(e=l==null?void 0:l.addEventListener)==null||e.call(l,"error",ue,!0)}function me(){var e;(e=l==null?void 0:l.removeEventListener)==null||e.call(l,"error",ue,!0)}import{getGlobal as ft}from"@ohbug/utils";var m=ft();function fe(e){v(e)}function de(){var e;(e=m==null?void 0:m.addEventListener)==null||e.call(m,"unhandledrejection",fe,!0)}function he(){var e;(e=m==null?void 0:m.removeEventListener)==null||e.call(m,"unhandledrejection",fe,!0)}function ht(){Q(),Z()}function Ee(){V(),ee()}function Et(){ne(),se(),pe()}function ge(){ie(),ce()}function gt(){!dt().addEventListener||(le(),de())}function ye(){me(),he()}function xe(){gt(),Et(),ht(),re()}import{getGlobal as yt}from"@ohbug/utils";var b=yt();function Oe(){var e;(e=b==null?void 0:b.addEventListener)==null||e.call(b,"unload",()=>{ye(),ge(),Ee(),T()},!0)}var be=xt({name:"OhbugBrowser",setup:()=>{xe(),Oe()}});import{getOhbugObject as Ot}from"@ohbug/utils";var bt=()=>{let e=new WeakSet;return(t,r)=>{if(typeof r=="object"&&r!==null){if(e.has(r))return;e.add(r)}return r}};function ve(e){let{client:t}=Ot(),r=t.__config.endpoint;return new Promise((o,n)=>{let s=JSON.stringify(e,bt());if(navigator.sendBeacon){let i=navigator.sendBeacon(r,s);o(i)}else{let i=new XMLHttpRequest;i.onreadystatechange=()=>{if(i.readyState===XMLHttpRequest.DONE){if(i.status>=200&&i.status<300)return o(i.response);n(i)}},i.open("POST",r),i.setRequestHeader("Content-Type","application/json;charset=UTF-8"),i.send(s)}})}function wt(e){let t=Dt(),r={platform:"ohbug-browser",version:w},o=new vt({sdk:r,config:e,device:K,notifier:ve});return t.__OHBUG__={client:o},o.use(be),o.__logger.info(`%c @ohbug/browser %c Detected Ohbug v${w} %c`,"background:#333; padding: 2px 1px; color: #FFF","background:#FF6F61; padding: 2px 1px; color: #FFF","background:transparent"),o}var h={__client:null,setup(e){var t;return h.__client?((t=h.__client.__logger)==null||t.warn("init() has been called. Ignored."),h.__client):(h.__client=wt(e),h.__client)}};var io=h;export{io as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ohbug/browser",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Ohbug SDK for browsers",
5
5
  "license": "Apache-2.0",
6
6
  "author": "chenyueban <jasonchan0527@gmail.com>",
@@ -23,21 +23,19 @@
23
23
  }
24
24
  },
25
25
  "files": [
26
- "dist",
27
- "src"
26
+ "dist"
28
27
  ],
29
28
  "sideEffects": false,
30
29
  "publishConfig": {
31
30
  "access": "public"
32
31
  },
33
32
  "dependencies": {
34
- "@ohbug/core": "2.0.0",
35
- "@ohbug/types": "2.0.0",
36
- "@ohbug/utils": "2.0.0"
33
+ "@ohbug/core": "2.0.1",
34
+ "@ohbug/types": "2.0.1",
35
+ "@ohbug/utils": "2.0.1"
37
36
  },
38
37
  "scripts": {
39
38
  "build": "tsup",
40
39
  "dev": "tsup --watch"
41
- },
42
- "readme": "# `@ohbug/browser`\n\n[![npm](https://img.shields.io/npm/v/@ohbug/browser.svg?style=flat-square)](https://www.npmjs.com/package/@ohbug/browser)\n[![npm bundle size](https://img.shields.io/bundlephobia/min/@ohbug/browser?style=flat-square)](https://bundlephobia.com/result?p=@ohbug/browser)\n\nEnglish | [简体中文](./README-zh_CN.md)\n\n## Installation\n\n```\npnpm instal @ohbug/browser\n```\n\n## Usage\n\n```javascript\nimport Ohbug from '@ohbug/browser'\n\nOhbug.setup({ apiKey: 'YOUR_API_KEY' })\n```\n"
40
+ }
43
41
  }