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