@ohbug/browser 2.4.2 → 2.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +81 -0
- package/dist/index.js +40 -23
- package/dist/index.mjs +36 -21
- package/package.json +5 -5
package/dist/index.d.mts
ADDED
|
@@ -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.
|
|
91
|
+
var version = "2.5.1";
|
|
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,19 +497,22 @@ function networkDispatcher(type, detail) {
|
|
|
490
497
|
}
|
|
491
498
|
|
|
492
499
|
// src/capture/network/getParams.ts
|
|
493
|
-
var groupParamsByKey = (params) =>
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
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] =
|
|
511
|
+
acc[key] = val;
|
|
500
512
|
}
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
return acc;
|
|
505
|
-
}, {});
|
|
513
|
+
return acc;
|
|
514
|
+
}, {})
|
|
515
|
+
);
|
|
506
516
|
function getParams(data) {
|
|
507
517
|
try {
|
|
508
518
|
const location = new URL(data);
|
|
@@ -767,17 +777,20 @@ function handleCapture() {
|
|
|
767
777
|
// src/destroy.ts
|
|
768
778
|
var import_utils18 = require("@ohbug/utils");
|
|
769
779
|
var global9 = (0, import_utils18.getGlobal)();
|
|
780
|
+
function destroy() {
|
|
781
|
+
removeReplaceAddEventListener();
|
|
782
|
+
removeCaptureScript();
|
|
783
|
+
removeCaptureNetwork();
|
|
784
|
+
removeCaptureAction();
|
|
785
|
+
removeCaptureConsole();
|
|
786
|
+
}
|
|
770
787
|
function handleDestroy() {
|
|
771
788
|
var _a2;
|
|
772
789
|
(_a2 = global9 == null ? void 0 : global9.addEventListener) == null ? void 0 : _a2.call(
|
|
773
790
|
global9,
|
|
774
791
|
"unload",
|
|
775
792
|
() => {
|
|
776
|
-
|
|
777
|
-
removeCaptureScript();
|
|
778
|
-
removeCaptureNetwork();
|
|
779
|
-
removeCaptureAction();
|
|
780
|
-
removeCaptureConsole();
|
|
793
|
+
destroy();
|
|
781
794
|
},
|
|
782
795
|
true
|
|
783
796
|
);
|
|
@@ -832,13 +845,13 @@ function notifier(event) {
|
|
|
832
845
|
}
|
|
833
846
|
|
|
834
847
|
// src/client.ts
|
|
835
|
-
function createClient(config) {
|
|
848
|
+
function createClient(config, handleDestroy2) {
|
|
836
849
|
const global10 = (0, import_utils20.getGlobal)();
|
|
837
850
|
const sdk = {
|
|
838
851
|
platform: "ohbug-browser",
|
|
839
852
|
version
|
|
840
853
|
};
|
|
841
|
-
const client = new import_core13.Client({ sdk, config, device, notifier });
|
|
854
|
+
const client = new import_core13.Client({ sdk, config, device, notifier, destroy: handleDestroy2 });
|
|
842
855
|
global10.__OHBUG__ = { client };
|
|
843
856
|
client.use(extension);
|
|
844
857
|
client.__logger.info(
|
|
@@ -853,16 +866,20 @@ var BrowserClient = {
|
|
|
853
866
|
__client: null,
|
|
854
867
|
setup(config) {
|
|
855
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
|
+
}
|
|
856
875
|
if (BrowserClient.__client) {
|
|
857
|
-
(_a2 = BrowserClient.__client.__logger) == null ? void 0 : _a2.warn("
|
|
876
|
+
(_a2 = BrowserClient.__client.__logger) == null ? void 0 : _a2.warn("setup() has been called. Ignored.");
|
|
858
877
|
return BrowserClient.__client;
|
|
859
878
|
}
|
|
860
|
-
BrowserClient.__client = createClient(config);
|
|
879
|
+
BrowserClient.__client = createClient(config, destroyClient);
|
|
861
880
|
return BrowserClient.__client;
|
|
862
881
|
}
|
|
863
882
|
};
|
|
864
883
|
|
|
865
884
|
// src/index.ts
|
|
866
885
|
var src_default = BrowserClient;
|
|
867
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
868
|
-
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.
|
|
58
|
+
var version = "2.5.1";
|
|
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,19 +464,22 @@ function networkDispatcher(type, detail) {
|
|
|
461
464
|
}
|
|
462
465
|
|
|
463
466
|
// src/capture/network/getParams.ts
|
|
464
|
-
var groupParamsByKey = (params) =>
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
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] =
|
|
478
|
+
acc[key] = val;
|
|
471
479
|
}
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
return acc;
|
|
476
|
-
}, {});
|
|
480
|
+
return acc;
|
|
481
|
+
}, {})
|
|
482
|
+
);
|
|
477
483
|
function getParams(data) {
|
|
478
484
|
try {
|
|
479
485
|
const location = new URL(data);
|
|
@@ -738,17 +744,20 @@ function handleCapture() {
|
|
|
738
744
|
// src/destroy.ts
|
|
739
745
|
import { getGlobal as getGlobal10 } from "@ohbug/utils";
|
|
740
746
|
var global9 = getGlobal10();
|
|
747
|
+
function destroy() {
|
|
748
|
+
removeReplaceAddEventListener();
|
|
749
|
+
removeCaptureScript();
|
|
750
|
+
removeCaptureNetwork();
|
|
751
|
+
removeCaptureAction();
|
|
752
|
+
removeCaptureConsole();
|
|
753
|
+
}
|
|
741
754
|
function handleDestroy() {
|
|
742
755
|
var _a2;
|
|
743
756
|
(_a2 = global9 == null ? void 0 : global9.addEventListener) == null ? void 0 : _a2.call(
|
|
744
757
|
global9,
|
|
745
758
|
"unload",
|
|
746
759
|
() => {
|
|
747
|
-
|
|
748
|
-
removeCaptureScript();
|
|
749
|
-
removeCaptureNetwork();
|
|
750
|
-
removeCaptureAction();
|
|
751
|
-
removeCaptureConsole();
|
|
760
|
+
destroy();
|
|
752
761
|
},
|
|
753
762
|
true
|
|
754
763
|
);
|
|
@@ -803,13 +812,13 @@ function notifier(event) {
|
|
|
803
812
|
}
|
|
804
813
|
|
|
805
814
|
// src/client.ts
|
|
806
|
-
function createClient(config) {
|
|
815
|
+
function createClient(config, handleDestroy2) {
|
|
807
816
|
const global10 = getGlobal11();
|
|
808
817
|
const sdk = {
|
|
809
818
|
platform: "ohbug-browser",
|
|
810
819
|
version
|
|
811
820
|
};
|
|
812
|
-
const client = new Client({ sdk, config, device, notifier });
|
|
821
|
+
const client = new Client({ sdk, config, device, notifier, destroy: handleDestroy2 });
|
|
813
822
|
global10.__OHBUG__ = { client };
|
|
814
823
|
client.use(extension);
|
|
815
824
|
client.__logger.info(
|
|
@@ -824,11 +833,17 @@ var BrowserClient = {
|
|
|
824
833
|
__client: null,
|
|
825
834
|
setup(config) {
|
|
826
835
|
var _a2;
|
|
836
|
+
function destroyClient() {
|
|
837
|
+
const global10 = getGlobal11();
|
|
838
|
+
destroy();
|
|
839
|
+
BrowserClient.__client = null;
|
|
840
|
+
global10.__OHBUG__ = void 0;
|
|
841
|
+
}
|
|
827
842
|
if (BrowserClient.__client) {
|
|
828
|
-
(_a2 = BrowserClient.__client.__logger) == null ? void 0 : _a2.warn("
|
|
843
|
+
(_a2 = BrowserClient.__client.__logger) == null ? void 0 : _a2.warn("setup() has been called. Ignored.");
|
|
829
844
|
return BrowserClient.__client;
|
|
830
845
|
}
|
|
831
|
-
BrowserClient.__client = createClient(config);
|
|
846
|
+
BrowserClient.__client = createClient(config, destroyClient);
|
|
832
847
|
return BrowserClient.__client;
|
|
833
848
|
}
|
|
834
849
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ohbug/browser",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.1",
|
|
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
|
-
"
|
|
34
|
-
"@ohbug/
|
|
35
|
-
"@ohbug/
|
|
36
|
-
"
|
|
33
|
+
"error-stack-parser": "^2.1.4",
|
|
34
|
+
"@ohbug/core": "2.2.1",
|
|
35
|
+
"@ohbug/types": "2.2.1",
|
|
36
|
+
"@ohbug/utils": "2.0.8"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"build": "tsup",
|