@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/README.md +2 -2
- package/dist/index.d.mts +72 -63
- package/dist/index.mjs +603 -788
- package/dist/index.mjs.map +1 -0
- package/package.json +19 -20
- package/dist/index.d.ts +0 -81
- package/dist/index.js +0 -885
package/dist/index.mjs
CHANGED
|
@@ -1,855 +1,670 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
-
|
|
166
|
-
|
|
95
|
+
const { oldURL, newURL } = e;
|
|
96
|
+
handleUrlChange(oldURL, newURL);
|
|
167
97
|
}
|
|
168
98
|
function captureUrlChange() {
|
|
169
|
-
|
|
170
|
-
|
|
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
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
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
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
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
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
});
|
|
251
|
-
}
|
|
135
|
+
if (console) levels.forEach((level) => {
|
|
136
|
+
console[level] = consoleOriginal[level];
|
|
137
|
+
});
|
|
252
138
|
}
|
|
253
|
-
|
|
254
|
-
|
|
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
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
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
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
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
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
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
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
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
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
|
|
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
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
|
|
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
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
|
|
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
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
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
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
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
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
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
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
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
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
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
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
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
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
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
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
509
|
+
//#endregion
|
|
510
|
+
//#region src/capture/index.ts
|
|
708
511
|
function captureAction() {
|
|
709
|
-
|
|
710
|
-
|
|
512
|
+
captureUrlChange();
|
|
513
|
+
captureClick();
|
|
711
514
|
}
|
|
712
515
|
function removeCaptureAction() {
|
|
713
|
-
|
|
714
|
-
|
|
516
|
+
removeCaptureUrlChange();
|
|
517
|
+
removeCaptureClick();
|
|
715
518
|
}
|
|
716
519
|
function captureNetwork() {
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
520
|
+
captureAjaxError();
|
|
521
|
+
captureFetchError();
|
|
522
|
+
captureWebSocketError();
|
|
720
523
|
}
|
|
721
524
|
function removeCaptureNetwork() {
|
|
722
|
-
|
|
723
|
-
|
|
525
|
+
removeCaptureAjaxError();
|
|
526
|
+
removeCaptureFetchError();
|
|
724
527
|
}
|
|
725
528
|
function captureScript() {
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
captureUncaughtError();
|
|
730
|
-
captureUnhandledrejectionError();
|
|
529
|
+
if (!getGlobal().addEventListener) return;
|
|
530
|
+
captureUncaughtError();
|
|
531
|
+
captureUnhandledrejectionError();
|
|
731
532
|
}
|
|
732
533
|
function removeCaptureScript() {
|
|
733
|
-
|
|
734
|
-
|
|
534
|
+
removeCaptureUncaughtError();
|
|
535
|
+
removeCaptureUnhandledrejectionError();
|
|
735
536
|
}
|
|
736
537
|
function handleCapture() {
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
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
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
548
|
+
removeReplaceAddEventListener();
|
|
549
|
+
removeCaptureScript();
|
|
550
|
+
removeCaptureNetwork();
|
|
551
|
+
removeCaptureAction();
|
|
552
|
+
removeCaptureConsole();
|
|
753
553
|
}
|
|
754
554
|
function handleDestroy() {
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
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
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
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
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
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
|
-
|
|
664
|
+
//#endregion
|
|
665
|
+
//#region src/index.ts
|
|
852
666
|
var src_default = BrowserClient;
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
667
|
+
//#endregion
|
|
668
|
+
export { src_default as default };
|
|
669
|
+
|
|
670
|
+
//# sourceMappingURL=index.mjs.map
|