@betterbugs/rrweb-plugin-console-record 2.0.0-alpha.19 → 2.0.0-alpha.21
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/rrweb-plugin-console-record.cjs.map +1 -1
- package/dist/rrweb-plugin-console-record.js.map +1 -1
- package/dist/rrweb-plugin-console-record.umd.cjs.map +2 -2
- package/dist/rrweb-plugin-console-record.umd.min.cjs.map +2 -2
- package/package.json +6 -5
- package/umd/rrweb-plugin-console-record.js +520 -0
- package/umd/rrweb-plugin-console-record.min.js +41 -0
|
@@ -0,0 +1,520 @@
|
|
|
1
|
+
(function (g, f) {
|
|
2
|
+
if ("object" == typeof exports && "object" == typeof module) {
|
|
3
|
+
module.exports = f();
|
|
4
|
+
} else if ("function" == typeof define && define.amd) {
|
|
5
|
+
define("rrwebPluginConsoleRecord", [], f);
|
|
6
|
+
} else if ("object" == typeof exports) {
|
|
7
|
+
exports["rrwebPluginConsoleRecord"] = f();
|
|
8
|
+
} else {
|
|
9
|
+
g["rrwebPluginConsoleRecord"] = f();
|
|
10
|
+
}
|
|
11
|
+
}(this, () => {
|
|
12
|
+
var exports = {};
|
|
13
|
+
var module = { exports };
|
|
14
|
+
"use strict";
|
|
15
|
+
var __defProp = Object.defineProperty;
|
|
16
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
17
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
18
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
19
|
+
function patch(source, name, replacement) {
|
|
20
|
+
try {
|
|
21
|
+
if (!(name in source)) {
|
|
22
|
+
return () => {
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
const original = source[name];
|
|
26
|
+
const wrapped = replacement(original);
|
|
27
|
+
if (typeof wrapped === "function") {
|
|
28
|
+
wrapped.prototype = wrapped.prototype || {};
|
|
29
|
+
Object.defineProperties(wrapped, {
|
|
30
|
+
__rrweb_original__: {
|
|
31
|
+
enumerable: false,
|
|
32
|
+
value: original
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
source[name] = wrapped;
|
|
37
|
+
return () => {
|
|
38
|
+
source[name] = original;
|
|
39
|
+
};
|
|
40
|
+
} catch (e) {
|
|
41
|
+
return () => {
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
class StackFrame {
|
|
46
|
+
constructor(obj) {
|
|
47
|
+
__publicField(this, "fileName");
|
|
48
|
+
__publicField(this, "functionName");
|
|
49
|
+
__publicField(this, "lineNumber");
|
|
50
|
+
__publicField(this, "columnNumber");
|
|
51
|
+
this.fileName = obj.fileName || "";
|
|
52
|
+
this.functionName = obj.functionName || "";
|
|
53
|
+
this.lineNumber = obj.lineNumber;
|
|
54
|
+
this.columnNumber = obj.columnNumber;
|
|
55
|
+
}
|
|
56
|
+
toString() {
|
|
57
|
+
const lineNumber = this.lineNumber || "";
|
|
58
|
+
const columnNumber = this.columnNumber || "";
|
|
59
|
+
if (this.functionName)
|
|
60
|
+
return `${this.functionName} (${this.fileName}:${lineNumber}:${columnNumber})`;
|
|
61
|
+
return `${this.fileName}:${lineNumber}:${columnNumber}`;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const FIREFOX_SAFARI_STACK_REGEXP = /(^|@)\S+:\d+/;
|
|
65
|
+
const CHROME_IE_STACK_REGEXP = /^\s*at .*(\S+:\d+|\(native\))/m;
|
|
66
|
+
const SAFARI_NATIVE_CODE_REGEXP = /^(eval@)?(\[native code])?$/;
|
|
67
|
+
const ErrorStackParser = {
|
|
68
|
+
/**
|
|
69
|
+
* Given an Error object, extract the most information from it.
|
|
70
|
+
*/
|
|
71
|
+
parse: function(error) {
|
|
72
|
+
if (!error) {
|
|
73
|
+
return [];
|
|
74
|
+
}
|
|
75
|
+
if (
|
|
76
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
77
|
+
// @ts-ignore
|
|
78
|
+
typeof error.stacktrace !== "undefined" || // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
79
|
+
// @ts-ignore
|
|
80
|
+
typeof error["opera#sourceloc"] !== "undefined"
|
|
81
|
+
) {
|
|
82
|
+
return this.parseOpera(
|
|
83
|
+
error
|
|
84
|
+
);
|
|
85
|
+
} else if (error.stack && error.stack.match(CHROME_IE_STACK_REGEXP)) {
|
|
86
|
+
return this.parseV8OrIE(error);
|
|
87
|
+
} else if (error.stack) {
|
|
88
|
+
return this.parseFFOrSafari(error);
|
|
89
|
+
} else {
|
|
90
|
+
console.warn(
|
|
91
|
+
"[console-record-plugin]: Failed to parse error object:",
|
|
92
|
+
error
|
|
93
|
+
);
|
|
94
|
+
return [];
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
// Separate line and column numbers from a string of the form: (URI:Line:Column)
|
|
98
|
+
extractLocation: function(urlLike) {
|
|
99
|
+
if (urlLike.indexOf(":") === -1) {
|
|
100
|
+
return [urlLike];
|
|
101
|
+
}
|
|
102
|
+
const regExp = /(.+?)(?::(\d+))?(?::(\d+))?$/;
|
|
103
|
+
const parts = regExp.exec(urlLike.replace(/[()]/g, ""));
|
|
104
|
+
if (!parts) throw new Error(`Cannot parse given url: ${urlLike}`);
|
|
105
|
+
return [parts[1], parts[2] || void 0, parts[3] || void 0];
|
|
106
|
+
},
|
|
107
|
+
parseV8OrIE: function(error) {
|
|
108
|
+
const filtered = error.stack.split("\n").filter(function(line) {
|
|
109
|
+
return !!line.match(CHROME_IE_STACK_REGEXP);
|
|
110
|
+
}, this);
|
|
111
|
+
return filtered.map(function(line) {
|
|
112
|
+
if (line.indexOf("(eval ") > -1) {
|
|
113
|
+
line = line.replace(/eval code/g, "eval").replace(/(\(eval at [^()]*)|(\),.*$)/g, "");
|
|
114
|
+
}
|
|
115
|
+
let sanitizedLine = line.replace(/^\s+/, "").replace(/\(eval code/g, "(");
|
|
116
|
+
const location = sanitizedLine.match(/ (\((.+):(\d+):(\d+)\)$)/);
|
|
117
|
+
sanitizedLine = location ? sanitizedLine.replace(location[0], "") : sanitizedLine;
|
|
118
|
+
const tokens = sanitizedLine.split(/\s+/).slice(1);
|
|
119
|
+
const locationParts = this.extractLocation(
|
|
120
|
+
location ? location[1] : tokens.pop()
|
|
121
|
+
);
|
|
122
|
+
const functionName = tokens.join(" ") || void 0;
|
|
123
|
+
const fileName = ["eval", "<anonymous>"].indexOf(locationParts[0]) > -1 ? void 0 : locationParts[0];
|
|
124
|
+
return new StackFrame({
|
|
125
|
+
functionName,
|
|
126
|
+
fileName,
|
|
127
|
+
lineNumber: locationParts[1],
|
|
128
|
+
columnNumber: locationParts[2]
|
|
129
|
+
});
|
|
130
|
+
}, this);
|
|
131
|
+
},
|
|
132
|
+
parseFFOrSafari: function(error) {
|
|
133
|
+
const filtered = error.stack.split("\n").filter(function(line) {
|
|
134
|
+
return !line.match(SAFARI_NATIVE_CODE_REGEXP);
|
|
135
|
+
}, this);
|
|
136
|
+
return filtered.map(function(line) {
|
|
137
|
+
if (line.indexOf(" > eval") > -1) {
|
|
138
|
+
line = line.replace(
|
|
139
|
+
/ line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g,
|
|
140
|
+
":$1"
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
if (line.indexOf("@") === -1 && line.indexOf(":") === -1) {
|
|
144
|
+
return new StackFrame({
|
|
145
|
+
functionName: line
|
|
146
|
+
});
|
|
147
|
+
} else {
|
|
148
|
+
const functionNameRegex = /((.*".+"[^@]*)?[^@]*)(?:@)/;
|
|
149
|
+
const matches = line.match(functionNameRegex);
|
|
150
|
+
const functionName = matches && matches[1] ? matches[1] : void 0;
|
|
151
|
+
const locationParts = this.extractLocation(
|
|
152
|
+
line.replace(functionNameRegex, "")
|
|
153
|
+
);
|
|
154
|
+
return new StackFrame({
|
|
155
|
+
functionName,
|
|
156
|
+
fileName: locationParts[0],
|
|
157
|
+
lineNumber: locationParts[1],
|
|
158
|
+
columnNumber: locationParts[2]
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}, this);
|
|
162
|
+
},
|
|
163
|
+
parseOpera: function(e) {
|
|
164
|
+
if (!e.stacktrace || e.message.indexOf("\n") > -1 && e.message.split("\n").length > e.stacktrace.split("\n").length) {
|
|
165
|
+
return this.parseOpera9(e);
|
|
166
|
+
} else if (!e.stack) {
|
|
167
|
+
return this.parseOpera10(e);
|
|
168
|
+
} else {
|
|
169
|
+
return this.parseOpera11(e);
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
parseOpera9: function(e) {
|
|
173
|
+
const lineRE = /Line (\d+).*script (?:in )?(\S+)/i;
|
|
174
|
+
const lines = e.message.split("\n");
|
|
175
|
+
const result = [];
|
|
176
|
+
for (let i = 2, len = lines.length; i < len; i += 2) {
|
|
177
|
+
const match = lineRE.exec(lines[i]);
|
|
178
|
+
if (match) {
|
|
179
|
+
result.push(
|
|
180
|
+
new StackFrame({
|
|
181
|
+
fileName: match[2],
|
|
182
|
+
lineNumber: parseFloat(match[1])
|
|
183
|
+
})
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return result;
|
|
188
|
+
},
|
|
189
|
+
parseOpera10: function(e) {
|
|
190
|
+
const lineRE = /Line (\d+).*script (?:in )?(\S+)(?:: In function (\S+))?$/i;
|
|
191
|
+
const lines = e.stacktrace.split("\n");
|
|
192
|
+
const result = [];
|
|
193
|
+
for (let i = 0, len = lines.length; i < len; i += 2) {
|
|
194
|
+
const match = lineRE.exec(lines[i]);
|
|
195
|
+
if (match) {
|
|
196
|
+
result.push(
|
|
197
|
+
new StackFrame({
|
|
198
|
+
functionName: match[3] || void 0,
|
|
199
|
+
fileName: match[2],
|
|
200
|
+
lineNumber: parseFloat(match[1])
|
|
201
|
+
})
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return result;
|
|
206
|
+
},
|
|
207
|
+
// Opera 10.65+ Error.stack very similar to FF/Safari
|
|
208
|
+
parseOpera11: function(error) {
|
|
209
|
+
const filtered = error.stack.split("\n").filter(function(line) {
|
|
210
|
+
return !!line.match(FIREFOX_SAFARI_STACK_REGEXP) && !line.match(/^Error created at/);
|
|
211
|
+
}, this);
|
|
212
|
+
return filtered.map(function(line) {
|
|
213
|
+
const tokens = line.split("@");
|
|
214
|
+
const locationParts = this.extractLocation(tokens.pop());
|
|
215
|
+
const functionCall = tokens.shift() || "";
|
|
216
|
+
const functionName = functionCall.replace(/<anonymous function(: (\w+))?>/, "$2").replace(/\([^)]*\)/g, "") || void 0;
|
|
217
|
+
return new StackFrame({
|
|
218
|
+
functionName,
|
|
219
|
+
fileName: locationParts[0],
|
|
220
|
+
lineNumber: locationParts[1],
|
|
221
|
+
columnNumber: locationParts[2]
|
|
222
|
+
});
|
|
223
|
+
}, this);
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
function pathToSelector(node) {
|
|
227
|
+
if (!node || !node.outerHTML) {
|
|
228
|
+
return "";
|
|
229
|
+
}
|
|
230
|
+
let path = "";
|
|
231
|
+
while (node.parentElement) {
|
|
232
|
+
let name = node.localName;
|
|
233
|
+
if (!name) {
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
name = name.toLowerCase();
|
|
237
|
+
const parent = node.parentElement;
|
|
238
|
+
const domSiblings = [];
|
|
239
|
+
if (parent.children && parent.children.length > 0) {
|
|
240
|
+
for (let i = 0; i < parent.children.length; i++) {
|
|
241
|
+
const sibling = parent.children[i];
|
|
242
|
+
if (sibling.localName && sibling.localName.toLowerCase) {
|
|
243
|
+
if (sibling.localName.toLowerCase() === name) {
|
|
244
|
+
domSiblings.push(sibling);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
if (domSiblings.length > 1) {
|
|
250
|
+
name += `:eq(${domSiblings.indexOf(node)})`;
|
|
251
|
+
}
|
|
252
|
+
path = name + (path ? ">" + path : "");
|
|
253
|
+
node = parent;
|
|
254
|
+
}
|
|
255
|
+
return path;
|
|
256
|
+
}
|
|
257
|
+
function isObject(obj) {
|
|
258
|
+
return Object.prototype.toString.call(obj) === "[object Object]";
|
|
259
|
+
}
|
|
260
|
+
function isObjTooDeep(obj, limit) {
|
|
261
|
+
if (limit === 0) {
|
|
262
|
+
return true;
|
|
263
|
+
}
|
|
264
|
+
const keys = Object.keys(obj);
|
|
265
|
+
for (const key of keys) {
|
|
266
|
+
if (isObject(obj[key]) && isObjTooDeep(obj[key], limit - 1)) {
|
|
267
|
+
return true;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return false;
|
|
271
|
+
}
|
|
272
|
+
function stringify(obj, stringifyOptions) {
|
|
273
|
+
const options = {
|
|
274
|
+
numOfKeysLimit: 50,
|
|
275
|
+
depthOfLimit: 4
|
|
276
|
+
};
|
|
277
|
+
Object.assign(options, stringifyOptions);
|
|
278
|
+
const stack = [];
|
|
279
|
+
const keys = [];
|
|
280
|
+
return JSON.stringify(
|
|
281
|
+
obj,
|
|
282
|
+
function(key, value) {
|
|
283
|
+
if (stack.length > 0) {
|
|
284
|
+
const thisPos = stack.indexOf(this);
|
|
285
|
+
~thisPos ? stack.splice(thisPos + 1) : stack.push(this);
|
|
286
|
+
~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key);
|
|
287
|
+
if (~stack.indexOf(value)) {
|
|
288
|
+
if (stack[0] === value) {
|
|
289
|
+
value = "[Circular ~]";
|
|
290
|
+
} else {
|
|
291
|
+
value = "[Circular ~." + keys.slice(0, stack.indexOf(value)).join(".") + "]";
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
} else {
|
|
295
|
+
stack.push(value);
|
|
296
|
+
}
|
|
297
|
+
if (value === null) return value;
|
|
298
|
+
if (value === void 0) return "undefined";
|
|
299
|
+
if (shouldIgnore(value)) {
|
|
300
|
+
return toString(value);
|
|
301
|
+
}
|
|
302
|
+
if (typeof value === "bigint") {
|
|
303
|
+
return value.toString() + "n";
|
|
304
|
+
}
|
|
305
|
+
if (value instanceof Event) {
|
|
306
|
+
const eventResult = {};
|
|
307
|
+
for (const eventKey in value) {
|
|
308
|
+
const eventValue = value[eventKey];
|
|
309
|
+
if (Array.isArray(eventValue)) {
|
|
310
|
+
eventResult[eventKey] = pathToSelector(
|
|
311
|
+
eventValue.length ? eventValue[0] : null
|
|
312
|
+
);
|
|
313
|
+
} else {
|
|
314
|
+
eventResult[eventKey] = eventValue;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
return eventResult;
|
|
318
|
+
} else if (value instanceof Node) {
|
|
319
|
+
if (value instanceof HTMLElement) {
|
|
320
|
+
return value ? value.outerHTML : "";
|
|
321
|
+
}
|
|
322
|
+
return value.nodeName;
|
|
323
|
+
} else if (value instanceof Error) {
|
|
324
|
+
return value.stack ? value.stack + "\nEnd of stack for Error object" : value.name + ": " + value.message;
|
|
325
|
+
}
|
|
326
|
+
return value;
|
|
327
|
+
}
|
|
328
|
+
);
|
|
329
|
+
function shouldIgnore(_obj) {
|
|
330
|
+
if (isObject(_obj) && Object.keys(_obj).length > options.numOfKeysLimit) {
|
|
331
|
+
return true;
|
|
332
|
+
}
|
|
333
|
+
if (typeof _obj === "function") {
|
|
334
|
+
return true;
|
|
335
|
+
}
|
|
336
|
+
if (isObject(_obj) && isObjTooDeep(_obj, options.depthOfLimit)) {
|
|
337
|
+
return true;
|
|
338
|
+
}
|
|
339
|
+
return false;
|
|
340
|
+
}
|
|
341
|
+
function toString(_obj) {
|
|
342
|
+
let str = _obj.toString();
|
|
343
|
+
if (options.stringLengthLimit && str.length > options.stringLengthLimit) {
|
|
344
|
+
str = `${str.slice(0, options.stringLengthLimit)}...`;
|
|
345
|
+
}
|
|
346
|
+
return str;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
const defaultLogOptions = {
|
|
350
|
+
level: [
|
|
351
|
+
"assert",
|
|
352
|
+
"clear",
|
|
353
|
+
"count",
|
|
354
|
+
"countReset",
|
|
355
|
+
"debug",
|
|
356
|
+
"dir",
|
|
357
|
+
"dirxml",
|
|
358
|
+
"error",
|
|
359
|
+
"group",
|
|
360
|
+
"groupCollapsed",
|
|
361
|
+
"groupEnd",
|
|
362
|
+
"info",
|
|
363
|
+
"log",
|
|
364
|
+
"table",
|
|
365
|
+
"time",
|
|
366
|
+
"timeEnd",
|
|
367
|
+
"timeLog",
|
|
368
|
+
"trace",
|
|
369
|
+
"warn"
|
|
370
|
+
],
|
|
371
|
+
lengthThreshold: 1e3,
|
|
372
|
+
logger: "console"
|
|
373
|
+
};
|
|
374
|
+
function initLogObserver(cb, win, options) {
|
|
375
|
+
const logOptions = options ? Object.assign({}, defaultLogOptions, options) : defaultLogOptions;
|
|
376
|
+
const loggerType = logOptions.logger;
|
|
377
|
+
if (!loggerType) {
|
|
378
|
+
return () => {
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
let logger;
|
|
382
|
+
if (typeof loggerType === "string") {
|
|
383
|
+
logger = win[loggerType];
|
|
384
|
+
} else {
|
|
385
|
+
logger = loggerType;
|
|
386
|
+
}
|
|
387
|
+
let logCount = 0;
|
|
388
|
+
let inStack = false;
|
|
389
|
+
const cancelHandlers = [];
|
|
390
|
+
if (logOptions.level.includes("error")) {
|
|
391
|
+
const errorHandler = (event) => {
|
|
392
|
+
const message = event.message, error = event.error;
|
|
393
|
+
const trace = ErrorStackParser.parse(error).map(
|
|
394
|
+
(stackFrame) => stackFrame.toString()
|
|
395
|
+
);
|
|
396
|
+
const payload = [stringify(message, logOptions.stringifyOptions)];
|
|
397
|
+
cb({
|
|
398
|
+
level: "error",
|
|
399
|
+
trace,
|
|
400
|
+
payload
|
|
401
|
+
});
|
|
402
|
+
};
|
|
403
|
+
win.addEventListener("error", errorHandler);
|
|
404
|
+
cancelHandlers.push(() => {
|
|
405
|
+
win.removeEventListener("error", errorHandler);
|
|
406
|
+
});
|
|
407
|
+
const unhandledrejectionHandler = (event) => {
|
|
408
|
+
let error;
|
|
409
|
+
let payload;
|
|
410
|
+
if (event.reason instanceof Error) {
|
|
411
|
+
error = event.reason;
|
|
412
|
+
payload = [
|
|
413
|
+
stringify(
|
|
414
|
+
`Uncaught (in promise) ${error.name}: ${error.message}`,
|
|
415
|
+
logOptions.stringifyOptions
|
|
416
|
+
)
|
|
417
|
+
];
|
|
418
|
+
} else {
|
|
419
|
+
error = new Error();
|
|
420
|
+
payload = [
|
|
421
|
+
stringify("Uncaught (in promise)", logOptions.stringifyOptions),
|
|
422
|
+
stringify(event.reason, logOptions.stringifyOptions)
|
|
423
|
+
];
|
|
424
|
+
}
|
|
425
|
+
const trace = ErrorStackParser.parse(error).map(
|
|
426
|
+
(stackFrame) => stackFrame.toString()
|
|
427
|
+
);
|
|
428
|
+
cb({
|
|
429
|
+
level: "error",
|
|
430
|
+
trace,
|
|
431
|
+
payload
|
|
432
|
+
});
|
|
433
|
+
};
|
|
434
|
+
win.addEventListener("unhandledrejection", unhandledrejectionHandler);
|
|
435
|
+
cancelHandlers.push(() => {
|
|
436
|
+
win.removeEventListener("unhandledrejection", unhandledrejectionHandler);
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
for (const levelType of logOptions.level) {
|
|
440
|
+
cancelHandlers.push(replace(logger, levelType));
|
|
441
|
+
}
|
|
442
|
+
return () => {
|
|
443
|
+
cancelHandlers.forEach((h) => h());
|
|
444
|
+
};
|
|
445
|
+
function replace(_logger, level) {
|
|
446
|
+
if (!_logger[level]) {
|
|
447
|
+
return () => {
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
return patch(
|
|
451
|
+
_logger,
|
|
452
|
+
level,
|
|
453
|
+
(original) => {
|
|
454
|
+
return (...args) => {
|
|
455
|
+
original.apply(this, args);
|
|
456
|
+
if (level === "assert" && !!args[0]) {
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
if (inStack) {
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
inStack = true;
|
|
463
|
+
try {
|
|
464
|
+
const trace = ErrorStackParser.parse(new Error()).map((stackFrame) => stackFrame.toString()).splice(1);
|
|
465
|
+
const argsForPayload = level === "assert" ? args.slice(1) : args;
|
|
466
|
+
const payload = argsForPayload.map(
|
|
467
|
+
(s) => stringify(s, logOptions.stringifyOptions)
|
|
468
|
+
);
|
|
469
|
+
logCount++;
|
|
470
|
+
if (logCount < logOptions.lengthThreshold) {
|
|
471
|
+
cb({
|
|
472
|
+
level,
|
|
473
|
+
trace,
|
|
474
|
+
payload
|
|
475
|
+
});
|
|
476
|
+
} else if (logCount === logOptions.lengthThreshold) {
|
|
477
|
+
cb({
|
|
478
|
+
level: "warn",
|
|
479
|
+
trace: [],
|
|
480
|
+
payload: [
|
|
481
|
+
stringify("The number of log records reached the threshold.")
|
|
482
|
+
]
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
} catch (error) {
|
|
486
|
+
original("rrweb logger error:", error, ...args);
|
|
487
|
+
} finally {
|
|
488
|
+
inStack = false;
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
const PLUGIN_NAME = "rrweb/console@1";
|
|
496
|
+
const getRecordConsolePlugin = (options) => ({
|
|
497
|
+
name: PLUGIN_NAME,
|
|
498
|
+
observer: initLogObserver,
|
|
499
|
+
options
|
|
500
|
+
});
|
|
501
|
+
exports.PLUGIN_NAME = PLUGIN_NAME;
|
|
502
|
+
exports.getRecordConsolePlugin = getRecordConsolePlugin;
|
|
503
|
+
if (typeof module.exports == "object" && typeof exports == "object") {
|
|
504
|
+
var __cp = (to, from, except, desc) => {
|
|
505
|
+
if ((from && typeof from === "object") || typeof from === "function") {
|
|
506
|
+
for (let key of Object.getOwnPropertyNames(from)) {
|
|
507
|
+
if (!Object.prototype.hasOwnProperty.call(to, key) && key !== except)
|
|
508
|
+
Object.defineProperty(to, key, {
|
|
509
|
+
get: () => from[key],
|
|
510
|
+
enumerable: !(desc = Object.getOwnPropertyDescriptor(from, key)) || desc.enumerable,
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
return to;
|
|
515
|
+
};
|
|
516
|
+
module.exports = __cp(module.exports, exports);
|
|
517
|
+
}
|
|
518
|
+
return module.exports;
|
|
519
|
+
}))
|
|
520
|
+
//# sourceMappingURL=rrweb-plugin-console-record.umd.cjs.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
(function (g, f) {
|
|
2
|
+
if ("object" == typeof exports && "object" == typeof module) {
|
|
3
|
+
module.exports = f();
|
|
4
|
+
} else if ("function" == typeof define && define.amd) {
|
|
5
|
+
define("rrwebPluginConsoleRecord", [], f);
|
|
6
|
+
} else if ("object" == typeof exports) {
|
|
7
|
+
exports["rrwebPluginConsoleRecord"] = f();
|
|
8
|
+
} else {
|
|
9
|
+
g["rrwebPluginConsoleRecord"] = f();
|
|
10
|
+
}
|
|
11
|
+
}(this, () => {
|
|
12
|
+
var exports = {};
|
|
13
|
+
var module = { exports };
|
|
14
|
+
"use strict";var $=Object.defineProperty,k=(e,r,t)=>r in e?$(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,E=(e,r,t)=>k(e,typeof r!="symbol"?r+"":r,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function _(e,r,t){try{if(!(r in e))return()=>{};const n=e[r],i=t(n);return typeof i=="function"&&(i.prototype=i.prototype||{},Object.defineProperties(i,{__rrweb_original__:{enumerable:!1,value:n}})),e[r]=i,()=>{e[r]=n}}catch(n){return()=>{}}}class d{constructor(r){E(this,"fileName"),E(this,"functionName"),E(this,"lineNumber"),E(this,"columnNumber"),this.fileName=r.fileName||"",this.functionName=r.functionName||"",this.lineNumber=r.lineNumber,this.columnNumber=r.columnNumber}toString(){const r=this.lineNumber||"",t=this.columnNumber||"";return this.functionName?`${this.functionName} (${this.fileName}:${r}:${t})`:`${this.fileName}:${r}:${t}`}}const C=/(^|@)\S+:\d+/,S=/^\s*at .*(\S+:\d+|\(native\))/m,F=/^(eval@)?(\[native code])?$/,b={parse:function(e){return e?typeof e.stacktrace!="undefined"||typeof e["opera#sourceloc"]!="undefined"?this.parseOpera(e):e.stack&&e.stack.match(S)?this.parseV8OrIE(e):e.stack?this.parseFFOrSafari(e):(console.warn("[console-record-plugin]: Failed to parse error object:",e),[]):[]},extractLocation:function(e){if(e.indexOf(":")===-1)return[e];const t=/(.+?)(?::(\d+))?(?::(\d+))?$/.exec(e.replace(/[()]/g,""));if(!t)throw new Error(`Cannot parse given url: ${e}`);return[t[1],t[2]||void 0,t[3]||void 0]},parseV8OrIE:function(e){return e.stack.split(`
|
|
15
|
+
`).filter(function(t){return!!t.match(S)},this).map(function(t){t.indexOf("(eval ")>-1&&(t=t.replace(/eval code/g,"eval").replace(/(\(eval at [^()]*)|(\),.*$)/g,""));let n=t.replace(/^\s+/,"").replace(/\(eval code/g,"(");const i=n.match(/ (\((.+):(\d+):(\d+)\)$)/);n=i?n.replace(i[0],""):n;const c=n.split(/\s+/).slice(1),s=this.extractLocation(i?i[1]:c.pop()),a=c.join(" ")||void 0,o=["eval","<anonymous>"].indexOf(s[0])>-1?void 0:s[0];return new d({functionName:a,fileName:o,lineNumber:s[1],columnNumber:s[2]})},this)},parseFFOrSafari:function(e){return e.stack.split(`
|
|
16
|
+
`).filter(function(t){return!t.match(F)},this).map(function(t){if(t.indexOf(" > eval")>-1&&(t=t.replace(/ line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g,":$1")),t.indexOf("@")===-1&&t.indexOf(":")===-1)return new d({functionName:t});{const n=/((.*".+"[^@]*)?[^@]*)(?:@)/,i=t.match(n),c=i&&i[1]?i[1]:void 0,s=this.extractLocation(t.replace(n,""));return new d({functionName:c,fileName:s[0],lineNumber:s[1],columnNumber:s[2]})}},this)},parseOpera:function(e){return!e.stacktrace||e.message.indexOf(`
|
|
17
|
+
`)>-1&&e.message.split(`
|
|
18
|
+
`).length>e.stacktrace.split(`
|
|
19
|
+
`).length?this.parseOpera9(e):e.stack?this.parseOpera11(e):this.parseOpera10(e)},parseOpera9:function(e){const r=/Line (\d+).*script (?:in )?(\S+)/i,t=e.message.split(`
|
|
20
|
+
`),n=[];for(let i=2,c=t.length;i<c;i+=2){const s=r.exec(t[i]);s&&n.push(new d({fileName:s[2],lineNumber:parseFloat(s[1])}))}return n},parseOpera10:function(e){const r=/Line (\d+).*script (?:in )?(\S+)(?:: In function (\S+))?$/i,t=e.stacktrace.split(`
|
|
21
|
+
`),n=[];for(let i=0,c=t.length;i<c;i+=2){const s=r.exec(t[i]);s&&n.push(new d({functionName:s[3]||void 0,fileName:s[2],lineNumber:parseFloat(s[1])}))}return n},parseOpera11:function(e){return e.stack.split(`
|
|
22
|
+
`).filter(function(t){return!!t.match(C)&&!t.match(/^Error created at/)},this).map(function(t){const n=t.split("@"),i=this.extractLocation(n.pop()),s=(n.shift()||"").replace(/<anonymous function(: (\w+))?>/,"$2").replace(/\([^)]*\)/g,"")||void 0;return new d({functionName:s,fileName:i[0],lineNumber:i[1],columnNumber:i[2]})},this)}};function T(e){if(!e||!e.outerHTML)return"";let r="";for(;e.parentElement;){let t=e.localName;if(!t)break;t=t.toLowerCase();const n=e.parentElement,i=[];if(n.children&&n.children.length>0)for(let c=0;c<n.children.length;c++){const s=n.children[c];s.localName&&s.localName.toLowerCase&&s.localName.toLowerCase()===t&&i.push(s)}i.length>1&&(t+=`:eq(${i.indexOf(e)})`),r=t+(r?">"+r:""),e=n}return r}function L(e){return Object.prototype.toString.call(e)==="[object Object]"}function w(e,r){if(r===0)return!0;const t=Object.keys(e);for(const n of t)if(L(e[n])&&w(e[n],r-1))return!0;return!1}function g(e,r){const t={numOfKeysLimit:50,depthOfLimit:4};Object.assign(t,r);const n=[],i=[];return JSON.stringify(e,function(a,o){if(n.length>0){const p=n.indexOf(this);~p?n.splice(p+1):n.push(this),~p?i.splice(p,1/0,a):i.push(a),~n.indexOf(o)&&(n[0]===o?o="[Circular ~]":o="[Circular ~."+i.slice(0,n.indexOf(o)).join(".")+"]")}else n.push(o);if(o===null)return o;if(o===void 0)return"undefined";if(c(o))return s(o);if(typeof o=="bigint")return o.toString()+"n";if(o instanceof Event){const p={};for(const l in o){const f=o[l];Array.isArray(f)?p[l]=T(f.length?f[0]:null):p[l]=f}return p}else{if(o instanceof Node)return o instanceof HTMLElement?o?o.outerHTML:"":o.nodeName;if(o instanceof Error)return o.stack?o.stack+`
|
|
23
|
+
End of stack for Error object`:o.name+": "+o.message}return o});function c(a){return!!(L(a)&&Object.keys(a).length>t.numOfKeysLimit||typeof a=="function"||L(a)&&w(a,t.depthOfLimit))}function s(a){let o=a.toString();return t.stringLengthLimit&&o.length>t.stringLengthLimit&&(o=`${o.slice(0,t.stringLengthLimit)}...`),o}}const x={level:["assert","clear","count","countReset","debug","dir","dirxml","error","group","groupCollapsed","groupEnd","info","log","table","time","timeEnd","timeLog","trace","warn"],lengthThreshold:1e3,logger:"console"};function R(e,r,t){const n=t?Object.assign({},x,t):x,i=n.logger;if(!i)return()=>{};let c;typeof i=="string"?c=r[i]:c=i;let s=0,a=!1;const o=[];if(n.level.includes("error")){const l=m=>{const u=m.message,h=m.error,y=b.parse(h).map(O=>O.toString()),N=[g(u,n.stringifyOptions)];e({level:"error",trace:y,payload:N})};r.addEventListener("error",l),o.push(()=>{r.removeEventListener("error",l)});const f=m=>{let u,h;m.reason instanceof Error?(u=m.reason,h=[g(`Uncaught (in promise) ${u.name}: ${u.message}`,n.stringifyOptions)]):(u=new Error,h=[g("Uncaught (in promise)",n.stringifyOptions),g(m.reason,n.stringifyOptions)]);const y=b.parse(u).map(N=>N.toString());e({level:"error",trace:y,payload:h})};r.addEventListener("unhandledrejection",f),o.push(()=>{r.removeEventListener("unhandledrejection",f)})}for(const l of n.level)o.push(p(c,l));return()=>{o.forEach(l=>l())};function p(l,f){return l[f]?_(l,f,m=>(...u)=>{if(m.apply(this,u),!(f==="assert"&&u[0])&&!a){a=!0;try{const h=b.parse(new Error).map(O=>O.toString()).splice(1),N=(f==="assert"?u.slice(1):u).map(O=>g(O,n.stringifyOptions));s++,s<n.lengthThreshold?e({level:f,trace:h,payload:N}):s===n.lengthThreshold&&e({level:"warn",trace:[],payload:[g("The number of log records reached the threshold.")]})}catch(h){m("rrweb logger error:",h,...u)}finally{a=!1}}}):()=>{}}}const P="rrweb/console@1",I=e=>({name:P,observer:R,options:e});exports.PLUGIN_NAME=P;exports.getRecordConsolePlugin=I;
|
|
24
|
+
if (typeof module.exports == "object" && typeof exports == "object") {
|
|
25
|
+
var __cp = (to, from, except, desc) => {
|
|
26
|
+
if ((from && typeof from === "object") || typeof from === "function") {
|
|
27
|
+
for (let key of Object.getOwnPropertyNames(from)) {
|
|
28
|
+
if (!Object.prototype.hasOwnProperty.call(to, key) && key !== except)
|
|
29
|
+
Object.defineProperty(to, key, {
|
|
30
|
+
get: () => from[key],
|
|
31
|
+
enumerable: !(desc = Object.getOwnPropertyDescriptor(from, key)) || desc.enumerable,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return to;
|
|
36
|
+
};
|
|
37
|
+
module.exports = __cp(module.exports, exports);
|
|
38
|
+
}
|
|
39
|
+
return module.exports;
|
|
40
|
+
}))
|
|
41
|
+
//# sourceMappingURL=rrweb-plugin-console-record.umd.min.cjs.map
|