@ohbug/browser 2.4.1 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,81 @@
1
+ import { OhbugClient, OhbugConfig, OhbugBaseDetail } from '@ohbug/types';
2
+
3
+ interface OhbugBrowserClient {
4
+ __client: OhbugClient | null;
5
+ setup: (config: OhbugConfig) => OhbugClient;
6
+ }
7
+ declare const BrowserClient: OhbugBrowserClient;
8
+
9
+ interface UncaughtErrorDetail extends OhbugBaseDetail {
10
+ name: string;
11
+ filename?: string;
12
+ lineno?: number;
13
+ colno?: number;
14
+ stack: string;
15
+ }
16
+
17
+ interface ResourceErrorDetail extends OhbugBaseDetail {
18
+ src: string;
19
+ tagName: string;
20
+ id: string;
21
+ className: string;
22
+ name: string;
23
+ nodeType: number;
24
+ selector: string;
25
+ }
26
+
27
+ interface UnhandledrejectionErrorDetail extends OhbugBaseDetail {
28
+ name: string;
29
+ filename?: string;
30
+ lineno?: number;
31
+ colno?: number;
32
+ stack: string;
33
+ }
34
+
35
+ interface UnknownErrorDetail extends OhbugBaseDetail {
36
+ name: string;
37
+ filename?: string;
38
+ lineno?: number;
39
+ colno?: number;
40
+ stack: string;
41
+ }
42
+
43
+ interface AjaxErrorDetail extends OhbugBaseDetail {
44
+ req: {
45
+ url: string;
46
+ method: string;
47
+ data?: string;
48
+ params?: string;
49
+ };
50
+ res: {
51
+ response: string;
52
+ status: number;
53
+ statusText?: string;
54
+ };
55
+ }
56
+
57
+ interface FetchErrorDetail extends OhbugBaseDetail {
58
+ req: {
59
+ url: string;
60
+ method: string;
61
+ data?: string;
62
+ params?: string;
63
+ };
64
+ res: {
65
+ status: number;
66
+ statusText?: string;
67
+ };
68
+ }
69
+
70
+ interface WebsocketErrorDetail extends OhbugBaseDetail {
71
+ url: string;
72
+ params?: string;
73
+ timeStamp: number;
74
+ readyState: number;
75
+ protocol: string;
76
+ extensions: string;
77
+ binaryType: string;
78
+ bufferedAmount: number;
79
+ }
80
+
81
+ export { AjaxErrorDetail, FetchErrorDetail, ResourceErrorDetail, UncaughtErrorDetail, UnhandledrejectionErrorDetail, UnknownErrorDetail, WebsocketErrorDetail, BrowserClient as default };
package/dist/index.js CHANGED
@@ -35,6 +35,10 @@ var __copyProps = (to, from, except, desc) => {
35
35
  return to;
36
36
  };
37
37
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
38
+ // If the importer is in node compatibility mode or this is not an ESM
39
+ // file that has been converted to a CommonJS file using a Babel-
40
+ // compatible transform (i.e. "__esModule" has not been set), then set
41
+ // "default" to the CommonJS "module.exports" for node compatibility.
38
42
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
39
43
  mod
40
44
  ));
@@ -58,6 +62,7 @@ var device = () => {
58
62
  const {
59
63
  language,
60
64
  userAgent,
65
+ // @ts-expect-error Chromium only
61
66
  connection
62
67
  } = navigator;
63
68
  ohbugDevice.language = language;
@@ -83,7 +88,7 @@ var device = () => {
83
88
  };
84
89
 
85
90
  // src/version.ts
86
- var version = "2.4.1";
91
+ var version = "2.5.0";
87
92
 
88
93
  // src/extension.ts
89
94
  var import_core12 = require("@ohbug/core");
@@ -245,6 +250,7 @@ var import_utils4 = require("@ohbug/utils");
245
250
  var levels = ["log", "info", "warn", "error"];
246
251
  var consoleOriginal = Object.keys(levels).reduce(
247
252
  (acc, cur) => __spreadProps(__spreadValues({}, acc), {
253
+ // @ts-expect-error 修改了原生的console
248
254
  [cur]: console[cur]
249
255
  }),
250
256
  {
@@ -328,6 +334,7 @@ function resourceErrorHandler(e) {
328
334
  id: target && target.id,
329
335
  className: target && target.className,
330
336
  name: target && target.name,
337
+ // https://developer.mozilla.org/zh-CN/docs/Web/API/Node/nodeType
331
338
  nodeType: target && target.nodeType,
332
339
  selector
333
340
  };
@@ -490,28 +497,43 @@ function networkDispatcher(type, detail) {
490
497
  }
491
498
 
492
499
  // 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];
500
+ var groupParamsByKey = (params) => (
501
+ // @ts-expect-error worked
502
+ [...params.entries()].reduce((acc, tuple) => {
503
+ const [key, val] = tuple;
504
+ if (acc.hasOwnProperty(key)) {
505
+ if (Array.isArray(acc[key])) {
506
+ acc[key] = [...acc[key], val];
507
+ } else {
508
+ acc[key] = [acc[key], val];
509
+ }
498
510
  } else {
499
- acc[key] = [acc[key], val];
511
+ acc[key] = val;
500
512
  }
501
- } else {
502
- acc[key] = val;
503
- }
504
- return acc;
505
- }, {});
513
+ return acc;
514
+ }, {})
515
+ );
506
516
  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
- };
517
+ try {
518
+ const location = new URL(data);
519
+ const url = location.origin + location.pathname;
520
+ const searchParams = location.search ? location.searchParams : void 0;
521
+ const params = searchParams ? JSON.stringify(groupParamsByKey(searchParams)) : void 0;
522
+ return {
523
+ url,
524
+ params
525
+ };
526
+ } catch (_) {
527
+ const location = data.split("?");
528
+ const url = location == null ? void 0 : location[0];
529
+ const search = location == null ? void 0 : location[1];
530
+ const searchParams = search ? new URLSearchParams(search) : void 0;
531
+ const params = searchParams ? JSON.stringify(groupParamsByKey(searchParams)) : void 0;
532
+ return {
533
+ url,
534
+ params
535
+ };
536
+ }
515
537
  }
516
538
 
517
539
  // src/capture/network/captureAjaxError.ts
@@ -755,17 +777,20 @@ function handleCapture() {
755
777
  // src/destroy.ts
756
778
  var import_utils18 = require("@ohbug/utils");
757
779
  var global9 = (0, import_utils18.getGlobal)();
780
+ function destroy() {
781
+ removeReplaceAddEventListener();
782
+ removeCaptureScript();
783
+ removeCaptureNetwork();
784
+ removeCaptureAction();
785
+ removeCaptureConsole();
786
+ }
758
787
  function handleDestroy() {
759
788
  var _a2;
760
789
  (_a2 = global9 == null ? void 0 : global9.addEventListener) == null ? void 0 : _a2.call(
761
790
  global9,
762
791
  "unload",
763
792
  () => {
764
- removeReplaceAddEventListener();
765
- removeCaptureScript();
766
- removeCaptureNetwork();
767
- removeCaptureAction();
768
- removeCaptureConsole();
793
+ destroy();
769
794
  },
770
795
  true
771
796
  );
@@ -820,13 +845,13 @@ function notifier(event) {
820
845
  }
821
846
 
822
847
  // src/client.ts
823
- function createClient(config) {
848
+ function createClient(config, handleDestroy2) {
824
849
  const global10 = (0, import_utils20.getGlobal)();
825
850
  const sdk = {
826
851
  platform: "ohbug-browser",
827
852
  version
828
853
  };
829
- const client = new import_core13.Client({ sdk, config, device, notifier });
854
+ const client = new import_core13.Client({ sdk, config, device, notifier, destroy: handleDestroy2 });
830
855
  global10.__OHBUG__ = { client };
831
856
  client.use(extension);
832
857
  client.__logger.info(
@@ -841,16 +866,20 @@ var BrowserClient = {
841
866
  __client: null,
842
867
  setup(config) {
843
868
  var _a2;
869
+ function destroyClient() {
870
+ const global10 = (0, import_utils20.getGlobal)();
871
+ destroy();
872
+ BrowserClient.__client = null;
873
+ global10.__OHBUG__ = void 0;
874
+ }
844
875
  if (BrowserClient.__client) {
845
- (_a2 = BrowserClient.__client.__logger) == null ? void 0 : _a2.warn("init() has been called. Ignored.");
876
+ (_a2 = BrowserClient.__client.__logger) == null ? void 0 : _a2.warn("setup() has been called. Ignored.");
846
877
  return BrowserClient.__client;
847
878
  }
848
- BrowserClient.__client = createClient(config);
879
+ BrowserClient.__client = createClient(config, destroyClient);
849
880
  return BrowserClient.__client;
850
881
  }
851
882
  };
852
883
 
853
884
  // src/index.ts
854
885
  var src_default = BrowserClient;
855
- // Annotate the CommonJS export names for ESM import in node:
856
- 0 && (module.exports = {});
package/dist/index.mjs CHANGED
@@ -29,6 +29,7 @@ var device = () => {
29
29
  const {
30
30
  language,
31
31
  userAgent,
32
+ // @ts-expect-error Chromium only
32
33
  connection
33
34
  } = navigator;
34
35
  ohbugDevice.language = language;
@@ -54,7 +55,7 @@ var device = () => {
54
55
  };
55
56
 
56
57
  // src/version.ts
57
- var version = "2.4.1";
58
+ var version = "2.5.0";
58
59
 
59
60
  // src/extension.ts
60
61
  import { defineExtension } from "@ohbug/core";
@@ -216,6 +217,7 @@ import { getOhbugObject as getOhbugObject3, replace as replace3 } from "@ohbug/u
216
217
  var levels = ["log", "info", "warn", "error"];
217
218
  var consoleOriginal = Object.keys(levels).reduce(
218
219
  (acc, cur) => __spreadProps(__spreadValues({}, acc), {
220
+ // @ts-expect-error 修改了原生的console
219
221
  [cur]: console[cur]
220
222
  }),
221
223
  {
@@ -299,6 +301,7 @@ function resourceErrorHandler(e) {
299
301
  id: target && target.id,
300
302
  className: target && target.className,
301
303
  name: target && target.name,
304
+ // https://developer.mozilla.org/zh-CN/docs/Web/API/Node/nodeType
302
305
  nodeType: target && target.nodeType,
303
306
  selector
304
307
  };
@@ -461,28 +464,43 @@ function networkDispatcher(type, detail) {
461
464
  }
462
465
 
463
466
  // 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];
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
+ }
469
477
  } else {
470
- acc[key] = [acc[key], val];
478
+ acc[key] = val;
471
479
  }
472
- } else {
473
- acc[key] = val;
474
- }
475
- return acc;
476
- }, {});
480
+ return acc;
481
+ }, {})
482
+ );
477
483
  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
- };
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
+ }
486
504
  }
487
505
 
488
506
  // src/capture/network/captureAjaxError.ts
@@ -726,17 +744,20 @@ function handleCapture() {
726
744
  // src/destroy.ts
727
745
  import { getGlobal as getGlobal10 } from "@ohbug/utils";
728
746
  var global9 = getGlobal10();
747
+ function destroy() {
748
+ removeReplaceAddEventListener();
749
+ removeCaptureScript();
750
+ removeCaptureNetwork();
751
+ removeCaptureAction();
752
+ removeCaptureConsole();
753
+ }
729
754
  function handleDestroy() {
730
755
  var _a2;
731
756
  (_a2 = global9 == null ? void 0 : global9.addEventListener) == null ? void 0 : _a2.call(
732
757
  global9,
733
758
  "unload",
734
759
  () => {
735
- removeReplaceAddEventListener();
736
- removeCaptureScript();
737
- removeCaptureNetwork();
738
- removeCaptureAction();
739
- removeCaptureConsole();
760
+ destroy();
740
761
  },
741
762
  true
742
763
  );
@@ -791,13 +812,13 @@ function notifier(event) {
791
812
  }
792
813
 
793
814
  // src/client.ts
794
- function createClient(config) {
815
+ function createClient(config, handleDestroy2) {
795
816
  const global10 = getGlobal11();
796
817
  const sdk = {
797
818
  platform: "ohbug-browser",
798
819
  version
799
820
  };
800
- const client = new Client({ sdk, config, device, notifier });
821
+ const client = new Client({ sdk, config, device, notifier, destroy: handleDestroy2 });
801
822
  global10.__OHBUG__ = { client };
802
823
  client.use(extension);
803
824
  client.__logger.info(
@@ -812,11 +833,17 @@ var BrowserClient = {
812
833
  __client: null,
813
834
  setup(config) {
814
835
  var _a2;
836
+ function destroyClient() {
837
+ const global10 = getGlobal11();
838
+ destroy();
839
+ BrowserClient.__client = null;
840
+ global10.__OHBUG__ = void 0;
841
+ }
815
842
  if (BrowserClient.__client) {
816
- (_a2 = BrowserClient.__client.__logger) == null ? void 0 : _a2.warn("init() has been called. Ignored.");
843
+ (_a2 = BrowserClient.__client.__logger) == null ? void 0 : _a2.warn("setup() has been called. Ignored.");
817
844
  return BrowserClient.__client;
818
845
  }
819
- BrowserClient.__client = createClient(config);
846
+ BrowserClient.__client = createClient(config, destroyClient);
820
847
  return BrowserClient.__client;
821
848
  }
822
849
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ohbug/browser",
3
- "version": "2.4.1",
3
+ "version": "2.5.0",
4
4
  "description": "Ohbug SDK for browsers",
5
5
  "license": "Apache-2.0",
6
6
  "author": "chenyueban <jasonchan0527@gmail.com>",
@@ -30,10 +30,10 @@
30
30
  "access": "public"
31
31
  },
32
32
  "dependencies": {
33
- "@ohbug/core": "2.1.1",
34
- "@ohbug/types": "2.1.1",
35
- "@ohbug/utils": "2.0.6",
36
- "error-stack-parser": "^2.1.4"
33
+ "error-stack-parser": "^2.1.4",
34
+ "@ohbug/core": "2.2.0",
35
+ "@ohbug/utils": "2.0.7",
36
+ "@ohbug/types": "2.2.0"
37
37
  },
38
38
  "scripts": {
39
39
  "build": "tsup",