@ohbug/browser 1.0.16 → 1.0.20
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/capture/action/captureClick.d.ts.map +1 -1
- package/dist/capture/action/captureUrlChange.d.ts.map +1 -1
- package/dist/capture/network/captureAjaxError.d.ts.map +1 -1
- package/dist/capture/network/captureFetchError.d.ts.map +1 -1
- package/dist/capture/network/captureWebSocketError.d.ts.map +1 -1
- package/dist/dispatch/networkDispatcher.d.ts.map +1 -1
- package/dist/handle/ajaxErrorHandler.d.ts.map +1 -1
- package/dist/handle/fetchErrorHandler.d.ts.map +1 -1
- package/dist/handle/resourceErrorHandler.d.ts.map +1 -1
- package/dist/handle/uncaughtErrorHandler.d.ts.map +1 -1
- package/dist/handle/unhandledrejectionErrorHandler.d.ts.map +1 -1
- package/dist/handle/unknownErrorHandler.d.ts.map +1 -1
- package/dist/handle/websocketErrorHandler.d.ts.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/ohbug-browser.es.js +59 -0
- package/dist/ohbug-browser.umd.js +59 -1535
- package/dist/version.d.ts +1 -1
- package/package.json +16 -11
- package/dist/ohbug-browser.cjs.js +0 -1529
- package/dist/ohbug-browser.esm.js +0 -1524
- package/dist/ohbug-browser.esm.min.js +0 -58
- package/dist/ohbug-browser.umd.min.js +0 -58
- package/dist/types.d.ts +0 -10
- package/dist/types.d.ts.map +0 -1
|
@@ -1,1529 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
/*! *****************************************************************************
|
|
6
|
-
Copyright (c) Microsoft Corporation.
|
|
7
|
-
|
|
8
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
9
|
-
purpose with or without fee is hereby granted.
|
|
10
|
-
|
|
11
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
12
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
13
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
14
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
15
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
16
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
17
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
18
|
-
***************************************************************************** */
|
|
19
|
-
|
|
20
|
-
var __assign$1 = function() {
|
|
21
|
-
__assign$1 = Object.assign || function __assign(t) {
|
|
22
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
23
|
-
s = arguments[i];
|
|
24
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
25
|
-
}
|
|
26
|
-
return t;
|
|
27
|
-
};
|
|
28
|
-
return __assign$1.apply(this, arguments);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
32
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
33
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
34
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
35
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
36
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
37
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function __generator(thisArg, body) {
|
|
42
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
43
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
44
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
45
|
-
function step(op) {
|
|
46
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
47
|
-
while (_) try {
|
|
48
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
49
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
50
|
-
switch (op[0]) {
|
|
51
|
-
case 0: case 1: t = op; break;
|
|
52
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
53
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
54
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
55
|
-
default:
|
|
56
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
57
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
58
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
59
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
60
|
-
if (t[2]) _.ops.pop();
|
|
61
|
-
_.trys.pop(); continue;
|
|
62
|
-
}
|
|
63
|
-
op = body.call(thisArg, _);
|
|
64
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
65
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function __spreadArray$1(to, from) {
|
|
70
|
-
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
71
|
-
to[j] = from[i];
|
|
72
|
-
return to;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/*! *****************************************************************************
|
|
76
|
-
Copyright (c) Microsoft Corporation.
|
|
77
|
-
|
|
78
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
79
|
-
purpose with or without fee is hereby granted.
|
|
80
|
-
|
|
81
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
82
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
83
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
84
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
85
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
86
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
87
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
88
|
-
***************************************************************************** */
|
|
89
|
-
|
|
90
|
-
function __spreadArray$2(to, from) {
|
|
91
|
-
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
92
|
-
to[j] = from[i];
|
|
93
|
-
return to;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
var prefix$1 = 'Ohbug';
|
|
97
|
-
var logger$1 = {
|
|
98
|
-
log: function () {
|
|
99
|
-
var args = [];
|
|
100
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
101
|
-
args[_i] = arguments[_i];
|
|
102
|
-
}
|
|
103
|
-
// eslint-disable-next-line no-console
|
|
104
|
-
console.log.apply(console, __spreadArray$2([prefix$1], args));
|
|
105
|
-
},
|
|
106
|
-
info: function () {
|
|
107
|
-
var args = [];
|
|
108
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
109
|
-
args[_i] = arguments[_i];
|
|
110
|
-
}
|
|
111
|
-
// eslint-disable-next-line no-console
|
|
112
|
-
console.info.apply(console, __spreadArray$2([prefix$1], args));
|
|
113
|
-
},
|
|
114
|
-
warn: function () {
|
|
115
|
-
var args = [];
|
|
116
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
117
|
-
args[_i] = arguments[_i];
|
|
118
|
-
}
|
|
119
|
-
console.warn.apply(console, __spreadArray$2([prefix$1], args));
|
|
120
|
-
},
|
|
121
|
-
error: function () {
|
|
122
|
-
var args = [];
|
|
123
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
124
|
-
args[_i] = arguments[_i];
|
|
125
|
-
}
|
|
126
|
-
console.error.apply(console, __spreadArray$2([prefix$1], args));
|
|
127
|
-
},
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
function isString(value) {
|
|
131
|
-
return typeof value === 'string';
|
|
132
|
-
}
|
|
133
|
-
function isNumber(value) {
|
|
134
|
-
return typeof value === 'number' && parseInt("" + value, 10) === value;
|
|
135
|
-
}
|
|
136
|
-
function isFunction(value) {
|
|
137
|
-
return typeof value === 'function';
|
|
138
|
-
}
|
|
139
|
-
function isObject(value) {
|
|
140
|
-
return Object.prototype.toString.call(value) === '[object Object]';
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
var schema = {
|
|
144
|
-
// base
|
|
145
|
-
apiKey: {
|
|
146
|
-
defaultValue: undefined,
|
|
147
|
-
message: 'is required',
|
|
148
|
-
validate: function (value) { return Boolean(value) && isString(value); },
|
|
149
|
-
},
|
|
150
|
-
appVersion: {
|
|
151
|
-
defaultValue: undefined,
|
|
152
|
-
message: 'should be a string',
|
|
153
|
-
validate: function (value) { return value === undefined || isString(value); },
|
|
154
|
-
},
|
|
155
|
-
appType: {
|
|
156
|
-
defaultValue: undefined,
|
|
157
|
-
message: 'should be a string',
|
|
158
|
-
validate: function (value) { return value === undefined || isString(value); },
|
|
159
|
-
},
|
|
160
|
-
releaseStage: {
|
|
161
|
-
defaultValue: 'production',
|
|
162
|
-
message: 'should be a string',
|
|
163
|
-
validate: function (value) { return value === undefined || isString(value); },
|
|
164
|
-
},
|
|
165
|
-
endpoint: {
|
|
166
|
-
defaultValue: 'http://localhost:6660/report',
|
|
167
|
-
message: 'should be a string',
|
|
168
|
-
validate: function (value) { return value === undefined || isString(value); },
|
|
169
|
-
},
|
|
170
|
-
maxActions: {
|
|
171
|
-
defaultValue: 30,
|
|
172
|
-
message: 'should be a number between 0 and 100',
|
|
173
|
-
validate: function (value) {
|
|
174
|
-
return value === undefined || (isNumber(value) && value >= 1 && value <= 100);
|
|
175
|
-
},
|
|
176
|
-
},
|
|
177
|
-
// hooks
|
|
178
|
-
created: {
|
|
179
|
-
defaultValue: function (event) { return event; },
|
|
180
|
-
message: 'should be a function',
|
|
181
|
-
validate: function (value) { return value === undefined || isFunction(value); },
|
|
182
|
-
},
|
|
183
|
-
notified: {
|
|
184
|
-
defaultValue: function () { },
|
|
185
|
-
message: 'should be a function',
|
|
186
|
-
validate: function (value) { return value === undefined || isFunction(value); },
|
|
187
|
-
},
|
|
188
|
-
// utils
|
|
189
|
-
logger: {
|
|
190
|
-
defaultValue: logger$1,
|
|
191
|
-
message: 'should be null or an object with methods { log, info, warn, error }',
|
|
192
|
-
validate: function (value) {
|
|
193
|
-
return value === undefined ||
|
|
194
|
-
(value &&
|
|
195
|
-
['log', 'info', 'warn', 'error'].reduce(function (accumulator, method) {
|
|
196
|
-
return accumulator && typeof value[method] === 'function';
|
|
197
|
-
}, true));
|
|
198
|
-
},
|
|
199
|
-
},
|
|
200
|
-
// data
|
|
201
|
-
user: {
|
|
202
|
-
defaultValue: undefined,
|
|
203
|
-
message: 'should be an object and have up to 6 attributes',
|
|
204
|
-
validate: function (value) {
|
|
205
|
-
return value === undefined ||
|
|
206
|
-
(isObject(value) && Object.keys(value).length <= 6);
|
|
207
|
-
},
|
|
208
|
-
},
|
|
209
|
-
metaData: {
|
|
210
|
-
defaultValue: undefined,
|
|
211
|
-
message: 'should be an object',
|
|
212
|
-
validate: function (value) { return value === undefined || isObject(value); },
|
|
213
|
-
},
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
function createExtension(extension) {
|
|
217
|
-
return extension;
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Extension loading and initialization
|
|
221
|
-
*
|
|
222
|
-
* @param extension
|
|
223
|
-
* @param client
|
|
224
|
-
* @param args
|
|
225
|
-
*/
|
|
226
|
-
function loadExtension(extension, client) {
|
|
227
|
-
var _a;
|
|
228
|
-
var args = [];
|
|
229
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
|
230
|
-
args[_i - 2] = arguments[_i];
|
|
231
|
-
}
|
|
232
|
-
var result = (_a = extension.init) === null || _a === void 0 ? void 0 : _a.call.apply(_a, __spreadArray$1([extension, client], args));
|
|
233
|
-
client._extensions.push(extension);
|
|
234
|
-
// @ts-ignore
|
|
235
|
-
// eslint-disable-next-line no-param-reassign
|
|
236
|
-
client._hooks.created = function (_event, _client) {
|
|
237
|
-
var _a, _b;
|
|
238
|
-
var funcs = __spreadArray$1([
|
|
239
|
-
_client._config.created
|
|
240
|
-
], _client._extensions
|
|
241
|
-
.filter(function (_a) {
|
|
242
|
-
var created = _a.created;
|
|
243
|
-
return isFunction(created);
|
|
244
|
-
})
|
|
245
|
-
.map(function (_a) {
|
|
246
|
-
var created = _a.created;
|
|
247
|
-
return created;
|
|
248
|
-
}));
|
|
249
|
-
if (funcs.length === 0)
|
|
250
|
-
return (function () {
|
|
251
|
-
var arg = [];
|
|
252
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
253
|
-
arg[_i] = arguments[_i];
|
|
254
|
-
}
|
|
255
|
-
return arg;
|
|
256
|
-
})(_event, _client);
|
|
257
|
-
if (funcs.length === 1)
|
|
258
|
-
return (_a = funcs[0]) === null || _a === void 0 ? void 0 : _a.call(funcs, _event, _client);
|
|
259
|
-
// @ts-ignore
|
|
260
|
-
return (_b = funcs.reduce(function (a, b) { return function (event) { return b(a(event, _client), _client); }; })) === null || _b === void 0 ? void 0 : _b(_event, _client);
|
|
261
|
-
};
|
|
262
|
-
// eslint-disable-next-line no-param-reassign
|
|
263
|
-
client._hooks.notified = function (_event, _client) {
|
|
264
|
-
return __spreadArray$1([
|
|
265
|
-
_client._config.notified
|
|
266
|
-
], _client._extensions
|
|
267
|
-
.filter(function (_a) {
|
|
268
|
-
var notified = _a.notified;
|
|
269
|
-
return isFunction(notified);
|
|
270
|
-
})
|
|
271
|
-
.map(function (_a) {
|
|
272
|
-
var notified = _a.notified;
|
|
273
|
-
return notified;
|
|
274
|
-
})).forEach(function (func) { return func === null || func === void 0 ? void 0 : func(_event, _client); });
|
|
275
|
-
};
|
|
276
|
-
return result || client;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
var Action = /** @class */ (function () {
|
|
280
|
-
function Action(message, data, type, timestamp) {
|
|
281
|
-
this.type = type;
|
|
282
|
-
this.timestamp = timestamp || new Date().toISOString();
|
|
283
|
-
this.message = message;
|
|
284
|
-
this.data = data;
|
|
285
|
-
}
|
|
286
|
-
return Action;
|
|
287
|
-
}());
|
|
288
|
-
|
|
289
|
-
function getConfigErrorMessage(errors, config) {
|
|
290
|
-
return new Error("Invalid configuration\n" + Object.keys(errors)
|
|
291
|
-
.map(
|
|
292
|
-
// @ts-ignore
|
|
293
|
-
function (key) { return "- " + key + " " + errors[key] + ", got " + JSON.stringify(config[key]); })
|
|
294
|
-
.join('\n') + "\n ");
|
|
295
|
-
}
|
|
296
|
-
function getErrorMessage(message, data) {
|
|
297
|
-
return new Error("Invalid data\n- " + message + ", got " + JSON.stringify(data));
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
function addMetaData(map, section, data) {
|
|
301
|
-
if (!section)
|
|
302
|
-
return;
|
|
303
|
-
map[section] = data;
|
|
304
|
-
}
|
|
305
|
-
function getMetaData(map, section) {
|
|
306
|
-
if (map[section]) {
|
|
307
|
-
return map[section];
|
|
308
|
-
}
|
|
309
|
-
return undefined;
|
|
310
|
-
}
|
|
311
|
-
function deleteMetaData(map, section) {
|
|
312
|
-
if (map[section]) {
|
|
313
|
-
return delete map[section];
|
|
314
|
-
}
|
|
315
|
-
return undefined;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
var Event = /** @class */ (function () {
|
|
319
|
-
function Event(values, client) {
|
|
320
|
-
var apiKey = values.apiKey, appVersion = values.appVersion, appType = values.appType, releaseStage = values.releaseStage, timestamp = values.timestamp, category = values.category, type = values.type, sdk = values.sdk, detail = values.detail, device = values.device, user = values.user, actions = values.actions, metaData = values.metaData;
|
|
321
|
-
this.apiKey = apiKey;
|
|
322
|
-
this.appVersion = appVersion;
|
|
323
|
-
this.appType = appType;
|
|
324
|
-
this.releaseStage = releaseStage;
|
|
325
|
-
this.timestamp = timestamp;
|
|
326
|
-
this.category = category;
|
|
327
|
-
this.type = type;
|
|
328
|
-
this.sdk = sdk;
|
|
329
|
-
this.detail = detail;
|
|
330
|
-
this.device = device;
|
|
331
|
-
this.user = user;
|
|
332
|
-
this.actions = actions;
|
|
333
|
-
this.metaData = metaData;
|
|
334
|
-
this._client = client;
|
|
335
|
-
}
|
|
336
|
-
Object.defineProperty(Event.prototype, "_isOhbugEvent", {
|
|
337
|
-
get: function () {
|
|
338
|
-
return true;
|
|
339
|
-
},
|
|
340
|
-
enumerable: false,
|
|
341
|
-
configurable: true
|
|
342
|
-
});
|
|
343
|
-
/**
|
|
344
|
-
* Add an action.
|
|
345
|
-
* Once the threshold is reached, the oldest breadcrumbs will be deleted.
|
|
346
|
-
* 新增一个动作。
|
|
347
|
-
* 一旦达到阈值,最老的 Action 将被删除。
|
|
348
|
-
*
|
|
349
|
-
* @param message
|
|
350
|
-
* @param data
|
|
351
|
-
* @param type
|
|
352
|
-
* @param timestamp
|
|
353
|
-
*/
|
|
354
|
-
Event.prototype.addAction = function (message, data, type, timestamp) {
|
|
355
|
-
var _a, _b;
|
|
356
|
-
var actions = this.actions;
|
|
357
|
-
var targetMessage = isString(message) ? message : '';
|
|
358
|
-
var targetData = data || {};
|
|
359
|
-
var targetType = isString(type) ? type : '';
|
|
360
|
-
var action = new Action(targetMessage, targetData, targetType, timestamp);
|
|
361
|
-
if (actions.length >= ((_b = (_a = this._client) === null || _a === void 0 ? void 0 : _a._config.maxActions) !== null && _b !== void 0 ? _b : 30)) {
|
|
362
|
-
actions.shift();
|
|
363
|
-
}
|
|
364
|
-
actions.push(action);
|
|
365
|
-
};
|
|
366
|
-
/**
|
|
367
|
-
* Get current user information
|
|
368
|
-
* 获取当前的用户信息
|
|
369
|
-
*/
|
|
370
|
-
Event.prototype.getUser = function () {
|
|
371
|
-
return this.user;
|
|
372
|
-
};
|
|
373
|
-
/**
|
|
374
|
-
* Set current user information
|
|
375
|
-
* 设置当前的用户信息
|
|
376
|
-
*/
|
|
377
|
-
Event.prototype.setUser = function (user) {
|
|
378
|
-
var _a;
|
|
379
|
-
if (isObject(user) && Object.keys(user).length <= 6) {
|
|
380
|
-
this.user = __assign$1(__assign$1({}, this.user), user);
|
|
381
|
-
return this.getUser();
|
|
382
|
-
}
|
|
383
|
-
(_a = this._client) === null || _a === void 0 ? void 0 : _a._logger.warn(getErrorMessage('setUser should be an object and have up to 6 attributes', user));
|
|
384
|
-
return undefined;
|
|
385
|
-
};
|
|
386
|
-
/**
|
|
387
|
-
* Add metaData
|
|
388
|
-
* 新增 metaData
|
|
389
|
-
*
|
|
390
|
-
* @param section
|
|
391
|
-
* @param data
|
|
392
|
-
*/
|
|
393
|
-
Event.prototype.addMetaData = function (section, data) {
|
|
394
|
-
return addMetaData(this.metaData, section, data);
|
|
395
|
-
};
|
|
396
|
-
/**
|
|
397
|
-
* Get metaData
|
|
398
|
-
* 获取 metaData
|
|
399
|
-
*
|
|
400
|
-
* @param section
|
|
401
|
-
*/
|
|
402
|
-
Event.prototype.getMetaData = function (section) {
|
|
403
|
-
return getMetaData(this.metaData, section);
|
|
404
|
-
};
|
|
405
|
-
/**
|
|
406
|
-
* Delete metaData
|
|
407
|
-
* 删除 metaData
|
|
408
|
-
*
|
|
409
|
-
* @param section
|
|
410
|
-
*/
|
|
411
|
-
Event.prototype.deleteMetaData = function (section) {
|
|
412
|
-
return deleteMetaData(this.metaData, section);
|
|
413
|
-
};
|
|
414
|
-
Event.prototype.toJSON = function () {
|
|
415
|
-
var _a = this, apiKey = _a.apiKey, appVersion = _a.appVersion, appType = _a.appType, timestamp = _a.timestamp, category = _a.category, type = _a.type, sdk = _a.sdk, device = _a.device, detail = _a.detail, user = _a.user, actions = _a.actions, metaData = _a.metaData, releaseStage = _a.releaseStage;
|
|
416
|
-
return {
|
|
417
|
-
apiKey: apiKey,
|
|
418
|
-
appVersion: appVersion,
|
|
419
|
-
appType: appType,
|
|
420
|
-
timestamp: timestamp,
|
|
421
|
-
category: category,
|
|
422
|
-
type: type,
|
|
423
|
-
sdk: sdk,
|
|
424
|
-
device: device,
|
|
425
|
-
detail: detail,
|
|
426
|
-
user: user,
|
|
427
|
-
actions: actions,
|
|
428
|
-
metaData: metaData,
|
|
429
|
-
releaseStage: releaseStage,
|
|
430
|
-
};
|
|
431
|
-
};
|
|
432
|
-
return Event;
|
|
433
|
-
}());
|
|
434
|
-
function createEvent(values, client) {
|
|
435
|
-
var _a = client._config, apiKey = _a.apiKey, appVersion = _a.appVersion, appType = _a.appType, releaseStage = _a.releaseStage;
|
|
436
|
-
var timestamp = new Date().toISOString();
|
|
437
|
-
var device = client._device(client);
|
|
438
|
-
var category;
|
|
439
|
-
var type;
|
|
440
|
-
var detail;
|
|
441
|
-
if (isObject(values) &&
|
|
442
|
-
Object.prototype.hasOwnProperty.call(values, 'type') &&
|
|
443
|
-
Object.prototype.hasOwnProperty.call(values, 'detail')) {
|
|
444
|
-
category = values.category || 'error';
|
|
445
|
-
type = values.type;
|
|
446
|
-
detail = values.detail;
|
|
447
|
-
}
|
|
448
|
-
else {
|
|
449
|
-
category = 'error';
|
|
450
|
-
type = 'unknownError';
|
|
451
|
-
detail = values;
|
|
452
|
-
}
|
|
453
|
-
return new Event({
|
|
454
|
-
apiKey: apiKey,
|
|
455
|
-
appVersion: appVersion,
|
|
456
|
-
appType: appType,
|
|
457
|
-
timestamp: timestamp,
|
|
458
|
-
category: category,
|
|
459
|
-
type: type,
|
|
460
|
-
sdk: client._sdk,
|
|
461
|
-
device: device,
|
|
462
|
-
user: client._user,
|
|
463
|
-
detail: detail,
|
|
464
|
-
actions: client._actions,
|
|
465
|
-
metaData: client._metaData,
|
|
466
|
-
releaseStage: releaseStage,
|
|
467
|
-
}, client);
|
|
468
|
-
}
|
|
469
|
-
function isEvent(eventLike) {
|
|
470
|
-
return Boolean(eventLike === null || eventLike === void 0 ? void 0 : eventLike._isOhbugEvent);
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
/**
|
|
474
|
-
* Used to control the timing of reporting events and the related life cycle.
|
|
475
|
-
*
|
|
476
|
-
* @param event
|
|
477
|
-
* @param client
|
|
478
|
-
*/
|
|
479
|
-
function notify(event, client) {
|
|
480
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
481
|
-
var result, e_1;
|
|
482
|
-
return __generator(this, function (_a) {
|
|
483
|
-
switch (_a.label) {
|
|
484
|
-
case 0:
|
|
485
|
-
_a.trys.push([0, 3, , 4]);
|
|
486
|
-
result = null;
|
|
487
|
-
if (!event) return [3 /*break*/, 2];
|
|
488
|
-
return [4 /*yield*/, client._notifier(event)];
|
|
489
|
-
case 1:
|
|
490
|
-
result = _a.sent();
|
|
491
|
-
_a.label = 2;
|
|
492
|
-
case 2:
|
|
493
|
-
if (isFunction(client._hooks.notified)) {
|
|
494
|
-
client._hooks.notified(event, client);
|
|
495
|
-
}
|
|
496
|
-
return [2 /*return*/, result];
|
|
497
|
-
case 3:
|
|
498
|
-
e_1 = _a.sent();
|
|
499
|
-
client._logger.error(e_1);
|
|
500
|
-
return [3 /*break*/, 4];
|
|
501
|
-
case 4: return [2 /*return*/];
|
|
502
|
-
}
|
|
503
|
-
});
|
|
504
|
-
});
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
function verifyConfig(config, schema) {
|
|
508
|
-
var keys = Object.keys(schema);
|
|
509
|
-
return keys.reduce(function (accumulator, key) {
|
|
510
|
-
var configValue = config[key];
|
|
511
|
-
var _a = schema[key], defaultValue = _a.defaultValue, message = _a.message, validate = _a.validate;
|
|
512
|
-
if (configValue !== undefined) {
|
|
513
|
-
var valid = validate(configValue);
|
|
514
|
-
if (valid) {
|
|
515
|
-
accumulator.config[key] = configValue;
|
|
516
|
-
}
|
|
517
|
-
else {
|
|
518
|
-
accumulator.config[key] = defaultValue;
|
|
519
|
-
accumulator.errors[key] = message;
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
else {
|
|
523
|
-
// if there is no corresponding configuration, use the default value
|
|
524
|
-
// 如果没有传入相应配置 使用默认值
|
|
525
|
-
accumulator.config[key] = defaultValue;
|
|
526
|
-
}
|
|
527
|
-
return accumulator;
|
|
528
|
-
}, {
|
|
529
|
-
config: {},
|
|
530
|
-
errors: {},
|
|
531
|
-
});
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
var Client = /** @class */ (function () {
|
|
535
|
-
function Client(_a) {
|
|
536
|
-
var _this = this;
|
|
537
|
-
var sdk = _a.sdk, baseConfig = _a.config, _b = _a.schema, schema$1 = _b === void 0 ? schema : _b, device = _a.device, notifier = _a.notifier;
|
|
538
|
-
var _c = verifyConfig(baseConfig, schema$1), config = _c.config, errors = _c.errors;
|
|
539
|
-
// initialization
|
|
540
|
-
this._sdk = sdk;
|
|
541
|
-
this._config = config;
|
|
542
|
-
this._logger = config.logger;
|
|
543
|
-
this._device = device;
|
|
544
|
-
this._notifier = notifier;
|
|
545
|
-
this._extensions = [];
|
|
546
|
-
this._hooks = {
|
|
547
|
-
created: config.created,
|
|
548
|
-
notified: config.notified,
|
|
549
|
-
};
|
|
550
|
-
this._actions = [];
|
|
551
|
-
this._user = config.user;
|
|
552
|
-
this._metaData = {};
|
|
553
|
-
if (isObject(config.metaData)) {
|
|
554
|
-
Object.keys(config.metaData).forEach(function (key) {
|
|
555
|
-
_this.addMetaData(key, config.metaData[key]);
|
|
556
|
-
});
|
|
557
|
-
}
|
|
558
|
-
if (Object.keys(errors).length) {
|
|
559
|
-
this._logger.warn(getConfigErrorMessage(errors, baseConfig));
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
/**
|
|
563
|
-
* Load extension
|
|
564
|
-
* 加载扩展
|
|
565
|
-
*
|
|
566
|
-
* @param extension
|
|
567
|
-
* @param args
|
|
568
|
-
*/
|
|
569
|
-
Client.prototype.use = function (extension) {
|
|
570
|
-
var args = [];
|
|
571
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
572
|
-
args[_i - 1] = arguments[_i];
|
|
573
|
-
}
|
|
574
|
-
return loadExtension.apply(void 0, __spreadArray$1([extension, this], args));
|
|
575
|
-
};
|
|
576
|
-
/**
|
|
577
|
-
* Create an event, you will get a data body containing device actions and other information
|
|
578
|
-
* 创建事件,将会得到一个含有 device actions 等信息的数据体
|
|
579
|
-
*
|
|
580
|
-
* @param value
|
|
581
|
-
*/
|
|
582
|
-
Client.prototype.createEvent = function (value) {
|
|
583
|
-
var event = createEvent(value, this);
|
|
584
|
-
if (isFunction(this._hooks.created)) {
|
|
585
|
-
// trigger created hook
|
|
586
|
-
return this._hooks.created(event, this);
|
|
587
|
-
}
|
|
588
|
-
return event;
|
|
589
|
-
};
|
|
590
|
-
/**
|
|
591
|
-
* Used to trigger the reporting interface
|
|
592
|
-
* 用于触发上报接口
|
|
593
|
-
*
|
|
594
|
-
* @param eventLike
|
|
595
|
-
* @param beforeNotify
|
|
596
|
-
*/
|
|
597
|
-
Client.prototype.notify = function (eventLike, beforeNotify) {
|
|
598
|
-
var event;
|
|
599
|
-
if (Boolean(eventLike) && !isEvent(eventLike)) {
|
|
600
|
-
event = this.createEvent(eventLike);
|
|
601
|
-
}
|
|
602
|
-
else {
|
|
603
|
-
event = eventLike;
|
|
604
|
-
}
|
|
605
|
-
if (beforeNotify)
|
|
606
|
-
event = beforeNotify(event);
|
|
607
|
-
return notify(event, this);
|
|
608
|
-
};
|
|
609
|
-
/**
|
|
610
|
-
* Add an action.
|
|
611
|
-
* Once the threshold is reached, the oldest breadcrumbs will be deleted.
|
|
612
|
-
* 新增一个动作。
|
|
613
|
-
* 一旦达到阈值,最老的 Action 将被删除。
|
|
614
|
-
*
|
|
615
|
-
* @param message
|
|
616
|
-
* @param data
|
|
617
|
-
* @param type
|
|
618
|
-
* @param timestamp
|
|
619
|
-
*/
|
|
620
|
-
Client.prototype.addAction = function (message, data, type, timestamp) {
|
|
621
|
-
var actions = this._actions;
|
|
622
|
-
var targetMessage = isString(message) ? message : '';
|
|
623
|
-
var targetData = data || {};
|
|
624
|
-
var targetType = isString(type) ? type : '';
|
|
625
|
-
var action = new Action(targetMessage, targetData, targetType, timestamp);
|
|
626
|
-
if (actions.length >= this._config.maxActions) {
|
|
627
|
-
actions.shift();
|
|
628
|
-
}
|
|
629
|
-
actions.push(action);
|
|
630
|
-
};
|
|
631
|
-
/**
|
|
632
|
-
* Get current user information
|
|
633
|
-
* 获取当前的用户信息
|
|
634
|
-
*/
|
|
635
|
-
Client.prototype.getUser = function () {
|
|
636
|
-
return this._user;
|
|
637
|
-
};
|
|
638
|
-
/**
|
|
639
|
-
* Set current user information
|
|
640
|
-
* 设置当前的用户信息
|
|
641
|
-
*/
|
|
642
|
-
Client.prototype.setUser = function (user) {
|
|
643
|
-
if (isObject(user) && Object.keys(user).length <= 6) {
|
|
644
|
-
this._user = __assign$1(__assign$1({}, this._user), user);
|
|
645
|
-
return this.getUser();
|
|
646
|
-
}
|
|
647
|
-
this._logger.warn(getErrorMessage('setUser should be an object and have up to 6 attributes', user));
|
|
648
|
-
return undefined;
|
|
649
|
-
};
|
|
650
|
-
/**
|
|
651
|
-
* Add metaData
|
|
652
|
-
* 新增 metaData
|
|
653
|
-
*
|
|
654
|
-
* @param section
|
|
655
|
-
* @param data
|
|
656
|
-
*/
|
|
657
|
-
Client.prototype.addMetaData = function (section, data) {
|
|
658
|
-
return addMetaData(this._metaData, section, data);
|
|
659
|
-
};
|
|
660
|
-
/**
|
|
661
|
-
* Get metaData
|
|
662
|
-
* 获取 metaData
|
|
663
|
-
*
|
|
664
|
-
* @param section
|
|
665
|
-
*/
|
|
666
|
-
Client.prototype.getMetaData = function (section) {
|
|
667
|
-
return getMetaData(this._metaData, section);
|
|
668
|
-
};
|
|
669
|
-
/**
|
|
670
|
-
* Delete metaData
|
|
671
|
-
* 删除 metaData
|
|
672
|
-
*
|
|
673
|
-
* @param section
|
|
674
|
-
*/
|
|
675
|
-
Client.prototype.deleteMetaData = function (section) {
|
|
676
|
-
return deleteMetaData(this._metaData, section);
|
|
677
|
-
};
|
|
678
|
-
return Client;
|
|
679
|
-
}());
|
|
680
|
-
|
|
681
|
-
/*! *****************************************************************************
|
|
682
|
-
Copyright (c) Microsoft Corporation.
|
|
683
|
-
|
|
684
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
685
|
-
purpose with or without fee is hereby granted.
|
|
686
|
-
|
|
687
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
688
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
689
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
690
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
691
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
692
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
693
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
694
|
-
***************************************************************************** */
|
|
695
|
-
|
|
696
|
-
function __spreadArray(to, from) {
|
|
697
|
-
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
698
|
-
to[j] = from[i];
|
|
699
|
-
return to;
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
var prefix = 'Ohbug';
|
|
703
|
-
var logger = {
|
|
704
|
-
log: function () {
|
|
705
|
-
var args = [];
|
|
706
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
707
|
-
args[_i] = arguments[_i];
|
|
708
|
-
}
|
|
709
|
-
// eslint-disable-next-line no-console
|
|
710
|
-
console.log.apply(console, __spreadArray([prefix], args));
|
|
711
|
-
},
|
|
712
|
-
info: function () {
|
|
713
|
-
var args = [];
|
|
714
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
715
|
-
args[_i] = arguments[_i];
|
|
716
|
-
}
|
|
717
|
-
// eslint-disable-next-line no-console
|
|
718
|
-
console.info.apply(console, __spreadArray([prefix], args));
|
|
719
|
-
},
|
|
720
|
-
warn: function () {
|
|
721
|
-
var args = [];
|
|
722
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
723
|
-
args[_i] = arguments[_i];
|
|
724
|
-
}
|
|
725
|
-
console.warn.apply(console, __spreadArray([prefix], args));
|
|
726
|
-
},
|
|
727
|
-
error: function () {
|
|
728
|
-
var args = [];
|
|
729
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
730
|
-
args[_i] = arguments[_i];
|
|
731
|
-
}
|
|
732
|
-
console.error.apply(console, __spreadArray([prefix], args));
|
|
733
|
-
},
|
|
734
|
-
};
|
|
735
|
-
|
|
736
|
-
function error(condition, format) {
|
|
737
|
-
var args = [];
|
|
738
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
|
739
|
-
args[_i - 2] = arguments[_i];
|
|
740
|
-
}
|
|
741
|
-
if (format === undefined) {
|
|
742
|
-
throw new Error('`Ohbug warning(condition, format, ...args)` requires a warning message argument');
|
|
743
|
-
}
|
|
744
|
-
if (!condition) {
|
|
745
|
-
var argIndex_1 = 0;
|
|
746
|
-
// eslint-disable-next-line no-plusplus
|
|
747
|
-
var message = format.replace(/%s/g, function () { return args[argIndex_1++]; });
|
|
748
|
-
throw new Error("Ohbug " + message);
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
function warning(condition, format) {
|
|
752
|
-
var args = [];
|
|
753
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
|
754
|
-
args[_i - 2] = arguments[_i];
|
|
755
|
-
}
|
|
756
|
-
try {
|
|
757
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
758
|
-
if (format === undefined) {
|
|
759
|
-
throw new Error('`Ohbug warning(condition, format, ...args)` requires a warning message argument');
|
|
760
|
-
}
|
|
761
|
-
if (!condition) {
|
|
762
|
-
var argIndex_2 = 0;
|
|
763
|
-
// eslint-disable-next-line no-plusplus
|
|
764
|
-
var message = format.replace(/%s/g, function () { return args[argIndex_2++]; });
|
|
765
|
-
logger.warn(message);
|
|
766
|
-
}
|
|
767
|
-
}
|
|
768
|
-
// eslint-disable-next-line no-empty
|
|
769
|
-
}
|
|
770
|
-
catch (e) { }
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
var fallbackGlobalObject = {};
|
|
774
|
-
function getGlobal() {
|
|
775
|
-
return (typeof window !== 'undefined'
|
|
776
|
-
? window
|
|
777
|
-
: typeof global !== 'undefined'
|
|
778
|
-
? global
|
|
779
|
-
: typeof self !== 'undefined'
|
|
780
|
-
? self
|
|
781
|
-
: fallbackGlobalObject);
|
|
782
|
-
}
|
|
783
|
-
function getOhbugObject() {
|
|
784
|
-
var global = getGlobal();
|
|
785
|
-
error(Boolean(global.__OHBUG__), 'Failed to get `OhbugObject`, please confirm if `Ohbug.init`');
|
|
786
|
-
return global.__OHBUG__;
|
|
787
|
-
}
|
|
788
|
-
|
|
789
|
-
function replace(source, name, behavior) {
|
|
790
|
-
if (!(name in source)) {
|
|
791
|
-
return;
|
|
792
|
-
}
|
|
793
|
-
var original = source[name];
|
|
794
|
-
var wrapped = behavior(original);
|
|
795
|
-
// eslint-disable-next-line no-param-reassign
|
|
796
|
-
source[name] = wrapped;
|
|
797
|
-
return original;
|
|
798
|
-
}
|
|
799
|
-
function parseUrl(url) {
|
|
800
|
-
if (typeof url !== 'string') {
|
|
801
|
-
return {};
|
|
802
|
-
}
|
|
803
|
-
// eslint-disable-next-line
|
|
804
|
-
var match = url.match(/^(([^:/?#]+):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/);
|
|
805
|
-
if (!match) {
|
|
806
|
-
return {};
|
|
807
|
-
}
|
|
808
|
-
var query = match[6] || '';
|
|
809
|
-
var fragment = match[8] || '';
|
|
810
|
-
return {
|
|
811
|
-
host: match[4],
|
|
812
|
-
path: match[5],
|
|
813
|
-
protocol: match[2],
|
|
814
|
-
relative: match[5] + query + fragment,
|
|
815
|
-
};
|
|
816
|
-
}
|
|
817
|
-
|
|
818
|
-
function getParentNode(node, path) {
|
|
819
|
-
if (node.parentNode) {
|
|
820
|
-
path.push(node.parentNode);
|
|
821
|
-
getParentNode(node.parentNode, path);
|
|
822
|
-
}
|
|
823
|
-
}
|
|
824
|
-
function getPath(node) {
|
|
825
|
-
var path = [];
|
|
826
|
-
path.push(node);
|
|
827
|
-
getParentNode(node, path);
|
|
828
|
-
return path;
|
|
829
|
-
}
|
|
830
|
-
var getSelector = function (event) {
|
|
831
|
-
var immutableTarget = (event.target || event.srcElement);
|
|
832
|
-
var target = (event.target || event.srcElement);
|
|
833
|
-
// 获取出错元素在同级元素的 index
|
|
834
|
-
// 储存错误元素前元素
|
|
835
|
-
var elements = [];
|
|
836
|
-
for (var i = 0; target &&
|
|
837
|
-
target.nodeType === Node.ELEMENT_NODE &&
|
|
838
|
-
target.nodeType !== Node.DOCUMENT_TYPE_NODE; target = target.previousSibling) {
|
|
839
|
-
if (i)
|
|
840
|
-
elements.push(target);
|
|
841
|
-
i += 1;
|
|
842
|
-
}
|
|
843
|
-
// error.path 只有 chrome 实现,需要 polyfill
|
|
844
|
-
var path =
|
|
845
|
-
// @ts-ignore
|
|
846
|
-
typeof event.path === 'undefined'
|
|
847
|
-
? getPath(event.target)
|
|
848
|
-
: // @ts-ignore
|
|
849
|
-
event.path;
|
|
850
|
-
var outerHTML = immutableTarget.outerHTML;
|
|
851
|
-
return path
|
|
852
|
-
.reverse()
|
|
853
|
-
.map(function (node) {
|
|
854
|
-
return (node.localName || '') +
|
|
855
|
-
(node.id ? "#" + node.id : '') +
|
|
856
|
-
(node.className ? "." + node.className : '') +
|
|
857
|
-
(node.outerHTML === outerHTML ? ":nth-child(" + elements.length + ")" : '');
|
|
858
|
-
})
|
|
859
|
-
.filter(function (v) { return Boolean(v); })
|
|
860
|
-
.join(' > ');
|
|
861
|
-
};
|
|
862
|
-
|
|
863
|
-
var getDevice = function () {
|
|
864
|
-
var device = {};
|
|
865
|
-
if (navigator) {
|
|
866
|
-
var language = navigator.language, userAgent = navigator.userAgent;
|
|
867
|
-
device.language = language;
|
|
868
|
-
device.userAgent = userAgent;
|
|
869
|
-
}
|
|
870
|
-
if (document) {
|
|
871
|
-
var title = document.title;
|
|
872
|
-
device.title = title;
|
|
873
|
-
}
|
|
874
|
-
if (window.location) {
|
|
875
|
-
var url = window.location.href;
|
|
876
|
-
device.url = url;
|
|
877
|
-
}
|
|
878
|
-
return device;
|
|
879
|
-
};
|
|
880
|
-
|
|
881
|
-
var version = '1.0.16';
|
|
882
|
-
|
|
883
|
-
var _a, _b;
|
|
884
|
-
var global$8 = getGlobal();
|
|
885
|
-
var lastHref;
|
|
886
|
-
function handleUrlChange(from, to) {
|
|
887
|
-
var _a;
|
|
888
|
-
var client = getOhbugObject().client;
|
|
889
|
-
var parsedHref = parseUrl((_a = global$8 === null || global$8 === void 0 ? void 0 : global$8.location) === null || _a === void 0 ? void 0 : _a.href);
|
|
890
|
-
var parsedFrom = parseUrl(from);
|
|
891
|
-
var parsedTo = parseUrl(to);
|
|
892
|
-
if (!parsedFrom.path) {
|
|
893
|
-
parsedFrom = parsedHref;
|
|
894
|
-
}
|
|
895
|
-
lastHref = to;
|
|
896
|
-
var targetFrom = from;
|
|
897
|
-
var targetTo = to;
|
|
898
|
-
if (parsedHref.protocol === parsedTo.protocol &&
|
|
899
|
-
parsedHref.host === parsedTo.host) {
|
|
900
|
-
targetTo = parsedTo.relative;
|
|
901
|
-
}
|
|
902
|
-
if (parsedHref.protocol === parsedFrom.protocol &&
|
|
903
|
-
parsedHref.host === parsedFrom.host) {
|
|
904
|
-
targetFrom = parsedFrom.relative;
|
|
905
|
-
}
|
|
906
|
-
if (targetFrom === targetTo)
|
|
907
|
-
return;
|
|
908
|
-
client.addAction("navigation to " + to, {
|
|
909
|
-
from: from,
|
|
910
|
-
to: to,
|
|
911
|
-
}, 'navigation');
|
|
912
|
-
}
|
|
913
|
-
function historyReplacement(original) {
|
|
914
|
-
return function call(data, title, url) {
|
|
915
|
-
if (url) {
|
|
916
|
-
handleUrlChange(lastHref, String(url));
|
|
917
|
-
}
|
|
918
|
-
return original.apply(this, [data, title, url]);
|
|
919
|
-
};
|
|
920
|
-
}
|
|
921
|
-
var historyOriginal = {
|
|
922
|
-
pushState: (_a = global$8 === null || global$8 === void 0 ? void 0 : global$8.history) === null || _a === void 0 ? void 0 : _a.pushState,
|
|
923
|
-
replaceState: (_b = global$8 === null || global$8 === void 0 ? void 0 : global$8.history) === null || _b === void 0 ? void 0 : _b.replaceState,
|
|
924
|
-
onpopstate: global$8 === null || global$8 === void 0 ? void 0 : global$8.onpopstate,
|
|
925
|
-
};
|
|
926
|
-
function historyListener() {
|
|
927
|
-
historyOriginal.pushState = replace(global$8 === null || global$8 === void 0 ? void 0 : global$8.history, 'pushState', historyReplacement);
|
|
928
|
-
historyOriginal.replaceState = replace(global$8 === null || global$8 === void 0 ? void 0 : global$8.history, 'replaceState', historyReplacement);
|
|
929
|
-
historyOriginal.onpopstate = replace(global$8, 'onpopstate', function () {
|
|
930
|
-
var _a;
|
|
931
|
-
var current = (_a = global$8 === null || global$8 === void 0 ? void 0 : global$8.location) === null || _a === void 0 ? void 0 : _a.href;
|
|
932
|
-
handleUrlChange(lastHref, current);
|
|
933
|
-
});
|
|
934
|
-
}
|
|
935
|
-
function hashListener(e) {
|
|
936
|
-
var oldURL = e.oldURL, newURL = e.newURL;
|
|
937
|
-
handleUrlChange(oldURL, newURL);
|
|
938
|
-
}
|
|
939
|
-
function captureUrlChange() {
|
|
940
|
-
var _a;
|
|
941
|
-
// history
|
|
942
|
-
historyListener();
|
|
943
|
-
// hash
|
|
944
|
-
(_a = global$8 === null || global$8 === void 0 ? void 0 : global$8.addEventListener) === null || _a === void 0 ? void 0 : _a.call(global$8, 'hashchange', hashListener, true);
|
|
945
|
-
}
|
|
946
|
-
function removeCaptureUrlChange() {
|
|
947
|
-
var _a;
|
|
948
|
-
// history
|
|
949
|
-
global$8.history.pushState = historyOriginal.pushState;
|
|
950
|
-
global$8.history.replaceState = historyOriginal.replaceState;
|
|
951
|
-
global$8.onpopstate = historyOriginal.onpopstate;
|
|
952
|
-
// hash
|
|
953
|
-
(_a = global$8 === null || global$8 === void 0 ? void 0 : global$8.removeEventListener) === null || _a === void 0 ? void 0 : _a.call(global$8, 'hashchange', hashListener, true);
|
|
954
|
-
}
|
|
955
|
-
|
|
956
|
-
var global$7 = getGlobal();
|
|
957
|
-
function listener$2(e) {
|
|
958
|
-
if (e.target) {
|
|
959
|
-
var client = getOhbugObject().client;
|
|
960
|
-
var _a = e.target, tagName = _a.tagName, id = _a.id, className = _a.className, name_1 = _a.name, src = _a.src, outerHTML = _a.outerHTML, nodeType = _a.nodeType;
|
|
961
|
-
var selector = getSelector(e);
|
|
962
|
-
client.addAction('click node', {
|
|
963
|
-
tagName: tagName,
|
|
964
|
-
id: id,
|
|
965
|
-
className: className,
|
|
966
|
-
name: name_1,
|
|
967
|
-
src: src,
|
|
968
|
-
outerHTML: outerHTML,
|
|
969
|
-
nodeType: nodeType,
|
|
970
|
-
selector: selector,
|
|
971
|
-
}, 'click');
|
|
972
|
-
}
|
|
973
|
-
}
|
|
974
|
-
function captureClick() {
|
|
975
|
-
var _a, _b;
|
|
976
|
-
(_b = (_a = global$7 === null || global$7 === void 0 ? void 0 : global$7.document) === null || _a === void 0 ? void 0 : _a.addEventListener) === null || _b === void 0 ? void 0 : _b.call(_a, 'click', listener$2);
|
|
977
|
-
}
|
|
978
|
-
function removeCaptureClick() {
|
|
979
|
-
var _a, _b;
|
|
980
|
-
(_b = (_a = global$7 === null || global$7 === void 0 ? void 0 : global$7.document) === null || _a === void 0 ? void 0 : _a.removeEventListener) === null || _b === void 0 ? void 0 : _b.call(_a, 'click', listener$2);
|
|
981
|
-
}
|
|
982
|
-
|
|
983
|
-
/*! *****************************************************************************
|
|
984
|
-
Copyright (c) Microsoft Corporation.
|
|
985
|
-
|
|
986
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
987
|
-
purpose with or without fee is hereby granted.
|
|
988
|
-
|
|
989
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
990
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
991
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
992
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
993
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
994
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
995
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
996
|
-
***************************************************************************** */
|
|
997
|
-
|
|
998
|
-
var __assign = function() {
|
|
999
|
-
__assign = Object.assign || function __assign(t) {
|
|
1000
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
1001
|
-
s = arguments[i];
|
|
1002
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
1003
|
-
}
|
|
1004
|
-
return t;
|
|
1005
|
-
};
|
|
1006
|
-
return __assign.apply(this, arguments);
|
|
1007
|
-
};
|
|
1008
|
-
|
|
1009
|
-
/* eslint-disable no-console */
|
|
1010
|
-
var levels = ['log', 'info', 'warn', 'error'];
|
|
1011
|
-
var consoleOriginal = Object.keys(levels).reduce(function (acc, cur) {
|
|
1012
|
-
var _a;
|
|
1013
|
-
return (__assign(__assign({}, acc), (_a = {}, _a[cur] = console[cur], _a)));
|
|
1014
|
-
}, {
|
|
1015
|
-
log: null,
|
|
1016
|
-
info: null,
|
|
1017
|
-
warn: null,
|
|
1018
|
-
error: null,
|
|
1019
|
-
});
|
|
1020
|
-
function captureConsole() {
|
|
1021
|
-
var client = getOhbugObject().client;
|
|
1022
|
-
levels.forEach(function (level) {
|
|
1023
|
-
consoleOriginal[level] = replace(console, level, function (origin) {
|
|
1024
|
-
return function call() {
|
|
1025
|
-
var args = [];
|
|
1026
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1027
|
-
args[_i] = arguments[_i];
|
|
1028
|
-
}
|
|
1029
|
-
var isOhbugConsole = args.some(function (arg) { return typeof arg === 'string' && arg.includes('Ohbug'); });
|
|
1030
|
-
if (!isOhbugConsole) {
|
|
1031
|
-
client.addAction("console." + level, args, 'console');
|
|
1032
|
-
}
|
|
1033
|
-
return origin.apply(this, args);
|
|
1034
|
-
};
|
|
1035
|
-
});
|
|
1036
|
-
});
|
|
1037
|
-
}
|
|
1038
|
-
function removeCaptureConsole() {
|
|
1039
|
-
if (console) {
|
|
1040
|
-
levels.forEach(function (level) {
|
|
1041
|
-
console[level] = consoleOriginal[level];
|
|
1042
|
-
});
|
|
1043
|
-
}
|
|
1044
|
-
}
|
|
1045
|
-
|
|
1046
|
-
// error
|
|
1047
|
-
var UNCAUGHT_ERROR$1 = 'uncaughtError'; // 意料之外的错误
|
|
1048
|
-
var RESOURCE_ERROR$1 = 'resourceError'; // 资源加载错误
|
|
1049
|
-
var UNHANDLEDREJECTION_ERROR$1 = 'unhandledrejectionError'; // unhandledrejection 错误,可能包含 Promise, react render 等错误
|
|
1050
|
-
var AJAX_ERROR$3 = 'ajaxError'; // ajax 错误
|
|
1051
|
-
var FETCH_ERROR$3 = 'fetchError'; // fetch 错误
|
|
1052
|
-
var WEBSOCKET_ERROR$3 = 'websocketError'; // websocket 错误
|
|
1053
|
-
var UNKNOWN_ERROR$1 = 'unknownError'; // 未知错误
|
|
1054
|
-
// message
|
|
1055
|
-
var MESSAGE = 'message'; // 主动上报的信息
|
|
1056
|
-
// view
|
|
1057
|
-
var VIEW = 'view'; // 用于计算 PV/UV
|
|
1058
|
-
|
|
1059
|
-
var types = /*#__PURE__*/Object.freeze({
|
|
1060
|
-
__proto__: null,
|
|
1061
|
-
UNCAUGHT_ERROR: UNCAUGHT_ERROR$1,
|
|
1062
|
-
RESOURCE_ERROR: RESOURCE_ERROR$1,
|
|
1063
|
-
UNHANDLEDREJECTION_ERROR: UNHANDLEDREJECTION_ERROR$1,
|
|
1064
|
-
AJAX_ERROR: AJAX_ERROR$3,
|
|
1065
|
-
FETCH_ERROR: FETCH_ERROR$3,
|
|
1066
|
-
WEBSOCKET_ERROR: WEBSOCKET_ERROR$3,
|
|
1067
|
-
UNKNOWN_ERROR: UNKNOWN_ERROR$1,
|
|
1068
|
-
MESSAGE: MESSAGE,
|
|
1069
|
-
VIEW: VIEW
|
|
1070
|
-
});
|
|
1071
|
-
|
|
1072
|
-
var UNCAUGHT_ERROR = UNCAUGHT_ERROR$1;
|
|
1073
|
-
function uncaughtErrorHandler(error) {
|
|
1074
|
-
var message = error.message, filename = error.filename, lineno = error.lineno, colno = error.colno, _a = error.error, stack = _a.stack, name = _a.name;
|
|
1075
|
-
var detail = {
|
|
1076
|
-
name: name,
|
|
1077
|
-
message: message,
|
|
1078
|
-
filename: filename,
|
|
1079
|
-
lineno: lineno,
|
|
1080
|
-
colno: colno,
|
|
1081
|
-
stack: stack,
|
|
1082
|
-
};
|
|
1083
|
-
var client = getOhbugObject().client;
|
|
1084
|
-
var event = client.createEvent({
|
|
1085
|
-
category: 'error',
|
|
1086
|
-
type: UNCAUGHT_ERROR,
|
|
1087
|
-
detail: detail,
|
|
1088
|
-
});
|
|
1089
|
-
client.notify(event);
|
|
1090
|
-
}
|
|
1091
|
-
|
|
1092
|
-
var RESOURCE_ERROR = RESOURCE_ERROR$1;
|
|
1093
|
-
function resourceErrorHandler(error) {
|
|
1094
|
-
var target = (error.target || error.srcElement);
|
|
1095
|
-
var outerHTML = target.outerHTML;
|
|
1096
|
-
var selector = getSelector(error);
|
|
1097
|
-
var detail = {
|
|
1098
|
-
outerHTML: outerHTML,
|
|
1099
|
-
src: target && target.src,
|
|
1100
|
-
tagName: target && target.tagName,
|
|
1101
|
-
id: target && target.id,
|
|
1102
|
-
className: target && target.className,
|
|
1103
|
-
name: target && target.name,
|
|
1104
|
-
// https://developer.mozilla.org/zh-CN/docs/Web/API/Node/nodeType
|
|
1105
|
-
nodeType: target && target.nodeType,
|
|
1106
|
-
selector: selector,
|
|
1107
|
-
};
|
|
1108
|
-
var client = getOhbugObject().client;
|
|
1109
|
-
var event = client.createEvent({
|
|
1110
|
-
category: 'error',
|
|
1111
|
-
type: RESOURCE_ERROR,
|
|
1112
|
-
detail: detail,
|
|
1113
|
-
});
|
|
1114
|
-
client.notify(event);
|
|
1115
|
-
}
|
|
1116
|
-
|
|
1117
|
-
var UNHANDLEDREJECTION_ERROR = UNHANDLEDREJECTION_ERROR$1;
|
|
1118
|
-
function unhandledrejectionErrorHandler(error) {
|
|
1119
|
-
var detail = {
|
|
1120
|
-
message: error.reason.message || error.reason,
|
|
1121
|
-
stack: error.reason.stack,
|
|
1122
|
-
};
|
|
1123
|
-
var client = getOhbugObject().client;
|
|
1124
|
-
var event = client.createEvent({
|
|
1125
|
-
category: 'error',
|
|
1126
|
-
type: UNHANDLEDREJECTION_ERROR,
|
|
1127
|
-
detail: detail,
|
|
1128
|
-
});
|
|
1129
|
-
client.notify(event);
|
|
1130
|
-
}
|
|
1131
|
-
|
|
1132
|
-
var UNKNOWN_ERROR = UNKNOWN_ERROR$1;
|
|
1133
|
-
function unknownErrorHandler(error) {
|
|
1134
|
-
var detail = error.message
|
|
1135
|
-
? error
|
|
1136
|
-
: {
|
|
1137
|
-
message: error,
|
|
1138
|
-
};
|
|
1139
|
-
var client = getOhbugObject().client;
|
|
1140
|
-
var event = client.createEvent({
|
|
1141
|
-
category: 'error',
|
|
1142
|
-
type: UNKNOWN_ERROR,
|
|
1143
|
-
detail: detail,
|
|
1144
|
-
});
|
|
1145
|
-
client.notify(event);
|
|
1146
|
-
}
|
|
1147
|
-
|
|
1148
|
-
var AJAX_ERROR$2 = AJAX_ERROR$3;
|
|
1149
|
-
function ajaxErrorHandler(detail) {
|
|
1150
|
-
var client = getOhbugObject().client;
|
|
1151
|
-
var event = client.createEvent({
|
|
1152
|
-
category: 'error',
|
|
1153
|
-
type: AJAX_ERROR$2,
|
|
1154
|
-
detail: detail,
|
|
1155
|
-
});
|
|
1156
|
-
client.notify(event);
|
|
1157
|
-
}
|
|
1158
|
-
|
|
1159
|
-
var FETCH_ERROR$2 = FETCH_ERROR$3;
|
|
1160
|
-
function fetchErrorHandler(detail) {
|
|
1161
|
-
var client = getOhbugObject().client;
|
|
1162
|
-
var event = client.createEvent({
|
|
1163
|
-
category: 'error',
|
|
1164
|
-
type: FETCH_ERROR$2,
|
|
1165
|
-
detail: detail,
|
|
1166
|
-
});
|
|
1167
|
-
client.notify(event);
|
|
1168
|
-
}
|
|
1169
|
-
|
|
1170
|
-
var WEBSOCKET_ERROR$2 = WEBSOCKET_ERROR$3;
|
|
1171
|
-
function websocketErrorHandler(detail) {
|
|
1172
|
-
var client = getOhbugObject().client;
|
|
1173
|
-
var event = client.createEvent({
|
|
1174
|
-
category: 'error',
|
|
1175
|
-
type: WEBSOCKET_ERROR$2,
|
|
1176
|
-
detail: detail,
|
|
1177
|
-
});
|
|
1178
|
-
client.notify(event);
|
|
1179
|
-
}
|
|
1180
|
-
|
|
1181
|
-
function scriptDispatcher(e) {
|
|
1182
|
-
try {
|
|
1183
|
-
var type = e.type;
|
|
1184
|
-
if (type === 'error') {
|
|
1185
|
-
var targetEvent = e;
|
|
1186
|
-
var message = targetEvent.message, error = targetEvent.error;
|
|
1187
|
-
var immutableTarget = e.target || e.srcElement;
|
|
1188
|
-
if (message && error) {
|
|
1189
|
-
uncaughtErrorHandler(targetEvent);
|
|
1190
|
-
}
|
|
1191
|
-
else if (immutableTarget) {
|
|
1192
|
-
resourceErrorHandler(targetEvent);
|
|
1193
|
-
}
|
|
1194
|
-
}
|
|
1195
|
-
else if (type === 'unhandledrejection') {
|
|
1196
|
-
unhandledrejectionErrorHandler(e);
|
|
1197
|
-
}
|
|
1198
|
-
else {
|
|
1199
|
-
unknownErrorHandler(e);
|
|
1200
|
-
}
|
|
1201
|
-
}
|
|
1202
|
-
catch (error) {
|
|
1203
|
-
unknownErrorHandler(error);
|
|
1204
|
-
}
|
|
1205
|
-
}
|
|
1206
|
-
|
|
1207
|
-
var AJAX_ERROR$1 = AJAX_ERROR$3, FETCH_ERROR$1 = FETCH_ERROR$3, WEBSOCKET_ERROR$1 = WEBSOCKET_ERROR$3;
|
|
1208
|
-
function networkDispatcher(type, detail) {
|
|
1209
|
-
try {
|
|
1210
|
-
switch (type) {
|
|
1211
|
-
case AJAX_ERROR$1:
|
|
1212
|
-
ajaxErrorHandler(detail);
|
|
1213
|
-
break;
|
|
1214
|
-
case FETCH_ERROR$1:
|
|
1215
|
-
fetchErrorHandler(detail);
|
|
1216
|
-
break;
|
|
1217
|
-
case WEBSOCKET_ERROR$1:
|
|
1218
|
-
websocketErrorHandler(detail);
|
|
1219
|
-
break;
|
|
1220
|
-
default:
|
|
1221
|
-
break;
|
|
1222
|
-
}
|
|
1223
|
-
}
|
|
1224
|
-
catch (error) {
|
|
1225
|
-
unknownErrorHandler(error);
|
|
1226
|
-
}
|
|
1227
|
-
}
|
|
1228
|
-
|
|
1229
|
-
var global$6 = getGlobal();
|
|
1230
|
-
var AJAX_ERROR = AJAX_ERROR$3;
|
|
1231
|
-
var access$1 = 'XMLHttpRequest' in global$6;
|
|
1232
|
-
var xhrOriginal = access$1
|
|
1233
|
-
? {
|
|
1234
|
-
open: XMLHttpRequest.prototype.open,
|
|
1235
|
-
send: XMLHttpRequest.prototype.send,
|
|
1236
|
-
}
|
|
1237
|
-
: {};
|
|
1238
|
-
/**
|
|
1239
|
-
* capture AJAX_ERROR
|
|
1240
|
-
*/
|
|
1241
|
-
function captureAjaxError() {
|
|
1242
|
-
warning(access$1, 'Binding `AJAX` monitoring failed, the current environment did not find the object `XMLHttpRequest`');
|
|
1243
|
-
if (!access$1)
|
|
1244
|
-
return;
|
|
1245
|
-
var client = getOhbugObject().client;
|
|
1246
|
-
var desc = {
|
|
1247
|
-
method: '',
|
|
1248
|
-
url: '',
|
|
1249
|
-
};
|
|
1250
|
-
var xhrProto = XMLHttpRequest === null || XMLHttpRequest === void 0 ? void 0 : XMLHttpRequest.prototype;
|
|
1251
|
-
xhrOriginal.open = replace(xhrProto, 'open', function (origin) {
|
|
1252
|
-
return function call() {
|
|
1253
|
-
var args = [];
|
|
1254
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1255
|
-
args[_i] = arguments[_i];
|
|
1256
|
-
}
|
|
1257
|
-
var method = args[0], url = args[1];
|
|
1258
|
-
desc.method = method;
|
|
1259
|
-
desc.url = url;
|
|
1260
|
-
return origin.apply(this, args);
|
|
1261
|
-
};
|
|
1262
|
-
});
|
|
1263
|
-
xhrOriginal.send = replace(xhrProto, 'send', function (origin) {
|
|
1264
|
-
return function call() {
|
|
1265
|
-
var args = [];
|
|
1266
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1267
|
-
args[_i] = arguments[_i];
|
|
1268
|
-
}
|
|
1269
|
-
this.addEventListener('readystatechange', function handle() {
|
|
1270
|
-
if (this.readyState === 4) {
|
|
1271
|
-
if (desc.url !== client._config.endpoint) {
|
|
1272
|
-
var detail = {
|
|
1273
|
-
req: {
|
|
1274
|
-
url: desc.url,
|
|
1275
|
-
method: desc.method,
|
|
1276
|
-
data: args[0] || {},
|
|
1277
|
-
},
|
|
1278
|
-
res: {
|
|
1279
|
-
status: this.status,
|
|
1280
|
-
statusText: this.statusText,
|
|
1281
|
-
response: this.response,
|
|
1282
|
-
},
|
|
1283
|
-
};
|
|
1284
|
-
client.addAction('ajax', detail, 'ajax');
|
|
1285
|
-
if (!this.status || this.status >= 400) {
|
|
1286
|
-
networkDispatcher(AJAX_ERROR, detail);
|
|
1287
|
-
}
|
|
1288
|
-
}
|
|
1289
|
-
}
|
|
1290
|
-
});
|
|
1291
|
-
return origin.apply(this, args);
|
|
1292
|
-
};
|
|
1293
|
-
});
|
|
1294
|
-
}
|
|
1295
|
-
function removeCaptureAjaxError() {
|
|
1296
|
-
if (access$1 && xhrOriginal.open && xhrOriginal.send) {
|
|
1297
|
-
var xhrProto = XMLHttpRequest === null || XMLHttpRequest === void 0 ? void 0 : XMLHttpRequest.prototype;
|
|
1298
|
-
xhrProto.open = xhrOriginal.open;
|
|
1299
|
-
xhrProto.send = xhrOriginal.send;
|
|
1300
|
-
}
|
|
1301
|
-
}
|
|
1302
|
-
|
|
1303
|
-
var global$5 = getGlobal();
|
|
1304
|
-
var FETCH_ERROR = FETCH_ERROR$3;
|
|
1305
|
-
var access = 'fetch' in global$5;
|
|
1306
|
-
var fetchOriginal = access ? global$5.fetch : null;
|
|
1307
|
-
/**
|
|
1308
|
-
* capture FETCH_ERROR
|
|
1309
|
-
*/
|
|
1310
|
-
function captureFetchError() {
|
|
1311
|
-
warning(access, 'Binding `fetch` monitoring failed, the current environment did not find the object `fetch`');
|
|
1312
|
-
if (!access)
|
|
1313
|
-
return;
|
|
1314
|
-
var client = getOhbugObject().client;
|
|
1315
|
-
fetchOriginal = replace(global$5, 'fetch', function (origin) {
|
|
1316
|
-
return function call() {
|
|
1317
|
-
var args = [];
|
|
1318
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1319
|
-
args[_i] = arguments[_i];
|
|
1320
|
-
}
|
|
1321
|
-
return origin
|
|
1322
|
-
.apply(this, args)
|
|
1323
|
-
.then(function (res) {
|
|
1324
|
-
var url = args[0], conf = args[1];
|
|
1325
|
-
var detail = {
|
|
1326
|
-
req: {
|
|
1327
|
-
url: url,
|
|
1328
|
-
method: conf && conf.method,
|
|
1329
|
-
data: (conf && conf.body) || {},
|
|
1330
|
-
},
|
|
1331
|
-
res: {
|
|
1332
|
-
status: res.status,
|
|
1333
|
-
statusText: res.statusText,
|
|
1334
|
-
},
|
|
1335
|
-
};
|
|
1336
|
-
client.addAction('fetch', detail, 'fetch');
|
|
1337
|
-
if (!res.status || res.status >= 400) {
|
|
1338
|
-
networkDispatcher(FETCH_ERROR, detail);
|
|
1339
|
-
}
|
|
1340
|
-
return res;
|
|
1341
|
-
})
|
|
1342
|
-
.catch(function (err) {
|
|
1343
|
-
networkDispatcher(FETCH_ERROR, err);
|
|
1344
|
-
});
|
|
1345
|
-
};
|
|
1346
|
-
});
|
|
1347
|
-
}
|
|
1348
|
-
function removeCaptureFetchError() {
|
|
1349
|
-
if (access && fetchOriginal) {
|
|
1350
|
-
global$5.fetch = fetchOriginal;
|
|
1351
|
-
}
|
|
1352
|
-
}
|
|
1353
|
-
|
|
1354
|
-
var global$4 = getGlobal();
|
|
1355
|
-
var WEBSOCKET_ERROR = WEBSOCKET_ERROR$3;
|
|
1356
|
-
/**
|
|
1357
|
-
* capture WEBSOCKET_ERROR
|
|
1358
|
-
*/
|
|
1359
|
-
function captureWebSocketError() {
|
|
1360
|
-
warning('WebSocket' in global$4, 'Binding `WebSocket` monitoring failed, the current environment did not find the object `WebSocket`');
|
|
1361
|
-
if (!('WebSocket' in global$4))
|
|
1362
|
-
return;
|
|
1363
|
-
var wsProto = WebSocket === null || WebSocket === void 0 ? void 0 : WebSocket.prototype;
|
|
1364
|
-
var backup = Object.getOwnPropertyDescriptor(wsProto, 'onerror');
|
|
1365
|
-
Object.defineProperty(wsProto, 'onerror', {
|
|
1366
|
-
set: function () {
|
|
1367
|
-
var _a;
|
|
1368
|
-
// eslint-disable-next-line prefer-rest-params
|
|
1369
|
-
var arg = arguments[0];
|
|
1370
|
-
(_a = backup === null || backup === void 0 ? void 0 : backup.set) === null || _a === void 0 ? void 0 : _a.call(this, function call(e) {
|
|
1371
|
-
var _a = e.target, url = _a.url, readyState = _a.readyState, protocol = _a.protocol, extensions = _a.extensions, binaryType = _a.binaryType, bufferedAmount = _a.bufferedAmount, timeStamp = e.timeStamp;
|
|
1372
|
-
var detail = {
|
|
1373
|
-
url: url,
|
|
1374
|
-
timeStamp: timeStamp,
|
|
1375
|
-
readyState: readyState,
|
|
1376
|
-
protocol: protocol,
|
|
1377
|
-
extensions: extensions,
|
|
1378
|
-
binaryType: binaryType,
|
|
1379
|
-
bufferedAmount: bufferedAmount,
|
|
1380
|
-
};
|
|
1381
|
-
networkDispatcher(WEBSOCKET_ERROR, detail);
|
|
1382
|
-
// eslint-disable-next-line prefer-rest-params
|
|
1383
|
-
arg.apply(this, arguments);
|
|
1384
|
-
});
|
|
1385
|
-
},
|
|
1386
|
-
});
|
|
1387
|
-
}
|
|
1388
|
-
|
|
1389
|
-
var global$3 = getGlobal();
|
|
1390
|
-
function listener$1(e) {
|
|
1391
|
-
scriptDispatcher(e);
|
|
1392
|
-
}
|
|
1393
|
-
/**
|
|
1394
|
-
* capture UNCAUGHT_ERROR RESOURCE_ERROR
|
|
1395
|
-
*/
|
|
1396
|
-
function captureUncaughtError() {
|
|
1397
|
-
var _a;
|
|
1398
|
-
(_a = global$3 === null || global$3 === void 0 ? void 0 : global$3.addEventListener) === null || _a === void 0 ? void 0 : _a.call(global$3, 'error', listener$1, true);
|
|
1399
|
-
}
|
|
1400
|
-
function removeCaptureUncaughtError() {
|
|
1401
|
-
var _a;
|
|
1402
|
-
(_a = global$3 === null || global$3 === void 0 ? void 0 : global$3.removeEventListener) === null || _a === void 0 ? void 0 : _a.call(global$3, 'error', listener$1, true);
|
|
1403
|
-
}
|
|
1404
|
-
|
|
1405
|
-
var global$2 = getGlobal();
|
|
1406
|
-
function listener(e) {
|
|
1407
|
-
scriptDispatcher(e);
|
|
1408
|
-
}
|
|
1409
|
-
/**
|
|
1410
|
-
* capture UNHANDLEDREJECTION_ERROR
|
|
1411
|
-
*/
|
|
1412
|
-
function captureUnhandledrejectionError() {
|
|
1413
|
-
var _a;
|
|
1414
|
-
(_a = global$2 === null || global$2 === void 0 ? void 0 : global$2.addEventListener) === null || _a === void 0 ? void 0 : _a.call(global$2, 'unhandledrejection', listener, true);
|
|
1415
|
-
}
|
|
1416
|
-
function removeCaptureUnhandledrejectionError() {
|
|
1417
|
-
var _a;
|
|
1418
|
-
(_a = global$2 === null || global$2 === void 0 ? void 0 : global$2.removeEventListener) === null || _a === void 0 ? void 0 : _a.call(global$2, 'unhandledrejection', listener, true);
|
|
1419
|
-
}
|
|
1420
|
-
|
|
1421
|
-
function captureAction() {
|
|
1422
|
-
captureUrlChange();
|
|
1423
|
-
captureClick();
|
|
1424
|
-
}
|
|
1425
|
-
function removeCaptureAction() {
|
|
1426
|
-
removeCaptureUrlChange();
|
|
1427
|
-
removeCaptureClick();
|
|
1428
|
-
}
|
|
1429
|
-
function captureNetwork() {
|
|
1430
|
-
captureAjaxError();
|
|
1431
|
-
captureFetchError();
|
|
1432
|
-
captureWebSocketError();
|
|
1433
|
-
}
|
|
1434
|
-
function removeCaptureNetwork() {
|
|
1435
|
-
removeCaptureAjaxError();
|
|
1436
|
-
removeCaptureFetchError();
|
|
1437
|
-
}
|
|
1438
|
-
function captureScript() {
|
|
1439
|
-
var global = getGlobal();
|
|
1440
|
-
warning(Boolean(global.addEventListener), 'Binding script monitoring failed, the current environment did not find the object `addEventListener`');
|
|
1441
|
-
if (!global.addEventListener)
|
|
1442
|
-
return;
|
|
1443
|
-
captureUncaughtError();
|
|
1444
|
-
captureUnhandledrejectionError();
|
|
1445
|
-
}
|
|
1446
|
-
function removeCaptureScript() {
|
|
1447
|
-
removeCaptureUncaughtError();
|
|
1448
|
-
removeCaptureUnhandledrejectionError();
|
|
1449
|
-
}
|
|
1450
|
-
function handleCapture() {
|
|
1451
|
-
captureScript();
|
|
1452
|
-
captureNetwork();
|
|
1453
|
-
captureAction();
|
|
1454
|
-
captureConsole();
|
|
1455
|
-
}
|
|
1456
|
-
|
|
1457
|
-
var global$1 = getGlobal();
|
|
1458
|
-
function handleDestroy() {
|
|
1459
|
-
var _a;
|
|
1460
|
-
(_a = global$1 === null || global$1 === void 0 ? void 0 : global$1.addEventListener) === null || _a === void 0 ? void 0 : _a.call(global$1, 'unload', function () {
|
|
1461
|
-
removeCaptureScript();
|
|
1462
|
-
removeCaptureNetwork();
|
|
1463
|
-
removeCaptureAction();
|
|
1464
|
-
removeCaptureConsole();
|
|
1465
|
-
}, true);
|
|
1466
|
-
}
|
|
1467
|
-
|
|
1468
|
-
var extension = createExtension({
|
|
1469
|
-
name: 'OhbugBrowser',
|
|
1470
|
-
init: function () {
|
|
1471
|
-
handleCapture();
|
|
1472
|
-
handleDestroy();
|
|
1473
|
-
},
|
|
1474
|
-
});
|
|
1475
|
-
|
|
1476
|
-
function notifier(event) {
|
|
1477
|
-
var client = getOhbugObject().client;
|
|
1478
|
-
var url = client._config.endpoint;
|
|
1479
|
-
return new Promise(function (resolve, reject) {
|
|
1480
|
-
var json = JSON.stringify(event);
|
|
1481
|
-
if (navigator.sendBeacon) {
|
|
1482
|
-
var result = navigator.sendBeacon(url, json);
|
|
1483
|
-
resolve(result);
|
|
1484
|
-
}
|
|
1485
|
-
else {
|
|
1486
|
-
var xhr_1 = new XMLHttpRequest();
|
|
1487
|
-
xhr_1.onreadystatechange = function () {
|
|
1488
|
-
if (xhr_1.readyState === XMLHttpRequest.DONE) {
|
|
1489
|
-
if (xhr_1.status >= 200 && xhr_1.status < 300)
|
|
1490
|
-
return resolve(xhr_1.response);
|
|
1491
|
-
reject(xhr_1);
|
|
1492
|
-
}
|
|
1493
|
-
};
|
|
1494
|
-
xhr_1.open('POST', url);
|
|
1495
|
-
xhr_1.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
|
|
1496
|
-
xhr_1.send(json);
|
|
1497
|
-
}
|
|
1498
|
-
});
|
|
1499
|
-
}
|
|
1500
|
-
|
|
1501
|
-
function createClient(config) {
|
|
1502
|
-
var global = getGlobal();
|
|
1503
|
-
var sdk = {
|
|
1504
|
-
platform: 'ohbug-browser',
|
|
1505
|
-
version: version,
|
|
1506
|
-
};
|
|
1507
|
-
var client = new Client({ sdk: sdk, config: config, device: getDevice, notifier: notifier });
|
|
1508
|
-
global.__OHBUG__ = { client: client };
|
|
1509
|
-
client.use(extension);
|
|
1510
|
-
// eslint-disable-next-line no-console
|
|
1511
|
-
console.log("%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');
|
|
1512
|
-
return client;
|
|
1513
|
-
}
|
|
1514
|
-
var BrowserClient = {
|
|
1515
|
-
_client: null,
|
|
1516
|
-
init: function (config) {
|
|
1517
|
-
var _a;
|
|
1518
|
-
if (BrowserClient._client) {
|
|
1519
|
-
(_a = BrowserClient._client._logger) === null || _a === void 0 ? void 0 : _a.log('init() has been called. Ignored.');
|
|
1520
|
-
return BrowserClient._client;
|
|
1521
|
-
}
|
|
1522
|
-
BrowserClient._client = createClient(config);
|
|
1523
|
-
return BrowserClient._client;
|
|
1524
|
-
},
|
|
1525
|
-
};
|
|
1526
|
-
|
|
1527
|
-
exports.Client = BrowserClient;
|
|
1528
|
-
exports.default = BrowserClient;
|
|
1529
|
-
exports.types = types;
|