@highlight-run/rrweb 2.0.1 → 2.0.4

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.
Files changed (117) hide show
  1. package/dist/plugins/console-record.js +408 -609
  2. package/dist/plugins/console-record.min.js +12 -15
  3. package/dist/plugins/console-record.min.js.map +1 -1
  4. package/dist/plugins/console-replay.js +142 -271
  5. package/dist/plugins/console-replay.min.js +4 -15
  6. package/dist/plugins/console-replay.min.js.map +1 -1
  7. package/dist/plugins/sequential-id-record.js +23 -26
  8. package/dist/plugins/sequential-id-record.min.js +1 -1
  9. package/dist/plugins/sequential-id-record.min.js.map +1 -1
  10. package/dist/plugins/sequential-id-replay.js +26 -30
  11. package/dist/plugins/sequential-id-replay.min.js +1 -1
  12. package/dist/plugins/sequential-id-replay.min.js.map +1 -1
  13. package/dist/record/rrweb-record-pack.js +63 -146
  14. package/dist/record/rrweb-record-pack.min.js +3 -15
  15. package/dist/record/rrweb-record-pack.min.js.map +1 -1
  16. package/dist/record/rrweb-record.js +3002 -3118
  17. package/dist/record/rrweb-record.min.js +4 -15
  18. package/dist/record/rrweb-record.min.js.map +1 -1
  19. package/dist/replay/rrweb-replay-unpack.js +4354 -4054
  20. package/dist/replay/rrweb-replay-unpack.min.js +5 -17
  21. package/dist/replay/rrweb-replay-unpack.min.js.map +1 -1
  22. package/dist/replay/rrweb-replay.js +4286 -3984
  23. package/dist/replay/rrweb-replay.min.js +5 -17
  24. package/dist/replay/rrweb-replay.min.js.map +1 -1
  25. package/dist/rrweb-all.js +7634 -7453
  26. package/dist/rrweb-all.min.js +16 -17
  27. package/dist/rrweb-all.min.js.map +1 -1
  28. package/dist/rrweb.js +7339 -7075
  29. package/dist/rrweb.min.js +6 -17
  30. package/dist/rrweb.min.js.map +1 -1
  31. package/es/rrweb/_virtual/_rollup-plugin-web-worker-loader__helper__auto__createBase64WorkerFactory.js +12 -0
  32. package/es/rrweb/_virtual/_rollup-plugin-web-worker-loader__helper__auto__isNodeJS.js +7 -0
  33. package/es/rrweb/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +31 -0
  34. package/es/rrweb/_virtual/_rollup-plugin-web-worker-loader__helper__node__WorkerClass.js +11 -0
  35. package/es/rrweb/_virtual/_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js +18 -0
  36. package/es/rrweb/_virtual/image-bitmap-data-url-worker.js +6 -0
  37. package/es/rrweb/ext/mitt/dist/mitt.es.js +1 -1
  38. package/es/rrweb/ext/tslib/tslib.es6.js +38 -0
  39. package/es/rrweb/packages/rrdom/es/virtual-dom.js +1099 -0
  40. package/es/rrweb/packages/rrweb/src/index.js +6 -4
  41. package/es/rrweb/packages/rrweb/src/packer/base.js +1 -1
  42. package/es/rrweb/packages/rrweb/src/packer/pack.js +4 -5
  43. package/es/rrweb/packages/rrweb/src/packer/unpack.js +24 -24
  44. package/es/rrweb/packages/rrweb/src/plugins/console/record/error-stack-parser.js +175 -176
  45. package/es/rrweb/packages/rrweb/src/plugins/console/record/index.js +109 -128
  46. package/es/rrweb/packages/rrweb/src/plugins/console/record/stringify.js +125 -138
  47. package/es/rrweb/packages/rrweb/src/plugins/console/replay/index.js +88 -105
  48. package/es/rrweb/packages/rrweb/src/plugins/sequential-id/record/index.js +19 -20
  49. package/es/rrweb/packages/rrweb/src/plugins/sequential-id/replay/index.js +25 -25
  50. package/es/rrweb/packages/rrweb/src/record/iframe-manager.js +29 -30
  51. package/es/rrweb/packages/rrweb/src/record/index.js +348 -373
  52. package/es/rrweb/packages/rrweb/src/record/mutation.js +487 -528
  53. package/es/rrweb/packages/rrweb/src/record/observer.js +584 -659
  54. package/es/rrweb/packages/rrweb/src/record/observers/canvas/2d.js +44 -73
  55. package/es/rrweb/packages/rrweb/src/record/observers/canvas/canvas-manager.js +166 -87
  56. package/es/rrweb/packages/rrweb/src/record/observers/canvas/canvas.js +21 -26
  57. package/es/rrweb/packages/rrweb/src/record/observers/canvas/serialize-args.js +119 -112
  58. package/es/rrweb/packages/rrweb/src/record/observers/canvas/webgl.js +53 -72
  59. package/es/rrweb/packages/rrweb/src/record/shadow-dom-manager.js +38 -40
  60. package/es/rrweb/packages/rrweb/src/record/stylesheet-manager.js +31 -0
  61. package/es/rrweb/packages/rrweb/src/replay/canvas/2d.js +27 -23
  62. package/es/rrweb/packages/rrweb/src/replay/canvas/deserialize-args.js +67 -0
  63. package/es/rrweb/packages/rrweb/src/replay/canvas/index.js +37 -29
  64. package/es/rrweb/packages/rrweb/src/replay/canvas/webgl.js +58 -120
  65. package/es/rrweb/packages/rrweb/src/replay/index.js +1545 -1854
  66. package/es/rrweb/packages/rrweb/src/replay/machine.js +275 -315
  67. package/es/rrweb/packages/rrweb/src/replay/smoothscroll.js +216 -218
  68. package/es/rrweb/packages/rrweb/src/replay/styles/inject-style.js +7 -7
  69. package/es/rrweb/packages/rrweb/src/replay/timer.js +87 -91
  70. package/es/rrweb/packages/rrweb/src/types.js +72 -72
  71. package/es/rrweb/packages/rrweb/src/utils.js +312 -506
  72. package/es/rrweb/packages/rrweb-snapshot/es/rrweb-snapshot.js +195 -71
  73. package/lib/plugins/console-record.js +469 -627
  74. package/lib/plugins/console-replay.js +198 -268
  75. package/lib/plugins/sequential-id-record.js +19 -20
  76. package/lib/plugins/sequential-id-replay.js +25 -25
  77. package/lib/record/rrweb-record-pack.js +184 -139
  78. package/lib/record/rrweb-record.js +2473 -2425
  79. package/lib/replay/rrweb-replay-unpack.js +3797 -3343
  80. package/lib/replay/rrweb-replay.js +3742 -3288
  81. package/lib/rrweb-all.js +6725 -6247
  82. package/lib/rrweb.js +6157 -5632
  83. package/package.json +14 -13
  84. package/typings/packer/base.d.ts +1 -1
  85. package/typings/plugins/console/record/index.d.ts +1 -1
  86. package/typings/plugins/console/record/stringify.d.ts +1 -1
  87. package/typings/plugins/sequential-id/record/index.d.ts +1 -1
  88. package/typings/plugins/sequential-id/replay/index.d.ts +1 -1
  89. package/typings/record/iframe-manager.d.ts +3 -3
  90. package/typings/record/index.d.ts +1 -1
  91. package/typings/record/mutation.d.ts +2 -1
  92. package/typings/record/observers/canvas/2d.d.ts +2 -1
  93. package/typings/record/observers/canvas/canvas-manager.d.ts +5 -2
  94. package/typings/record/observers/canvas/canvas.d.ts +1 -1
  95. package/typings/record/observers/canvas/serialize-args.d.ts +5 -5
  96. package/typings/record/observers/canvas/webgl.d.ts +2 -1
  97. package/typings/record/shadow-dom-manager.d.ts +2 -1
  98. package/typings/record/stylesheet-manager.d.ts +12 -0
  99. package/typings/record/workers/image-bitmap-data-url-worker.d.ts +5 -0
  100. package/typings/replay/canvas/2d.d.ts +3 -3
  101. package/typings/replay/canvas/deserialize-args.d.ts +7 -0
  102. package/typings/replay/canvas/index.d.ts +4 -3
  103. package/typings/replay/canvas/webgl.d.ts +3 -5
  104. package/typings/replay/index.d.ts +7 -10
  105. package/typings/types.d.ts +45 -17
  106. package/typings/utils.d.ts +17 -44
  107. package/dist/replay/rrweb-replay-unpack.min.css +0 -2
  108. package/dist/replay/rrweb-replay-unpack.min.css.map +0 -1
  109. package/dist/replay/rrweb-replay.min.css +0 -2
  110. package/dist/replay/rrweb-replay.min.css.map +0 -1
  111. package/dist/rrweb-all.min.css +0 -2
  112. package/dist/rrweb-all.min.css.map +0 -1
  113. package/dist/rrweb.min.css +0 -2
  114. package/dist/rrweb.min.css.map +0 -1
  115. package/es/rrweb/packages/rrweb/ext/tslib/tslib.es6.js +0 -78
  116. package/es/rrweb/packages/rrweb/src/replay/virtual-styles.js +0 -121
  117. package/typings/replay/virtual-styles.d.ts +0 -43
@@ -2,134 +2,6 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
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
- function __values(o) {
21
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
22
- if (m) return m.call(o);
23
- if (o && typeof o.length === "number") return {
24
- next: function () {
25
- if (o && i >= o.length) o = void 0;
26
- return { value: o && o[i++], done: !o };
27
- }
28
- };
29
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
30
- }
31
-
32
- function __read(o, n) {
33
- var m = typeof Symbol === "function" && o[Symbol.iterator];
34
- if (!m) return o;
35
- var i = m.call(o), r, ar = [], e;
36
- try {
37
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
38
- }
39
- catch (error) { e = { error: error }; }
40
- finally {
41
- try {
42
- if (r && !r.done && (m = i["return"])) m.call(i);
43
- }
44
- finally { if (e) throw e.error; }
45
- }
46
- return ar;
47
- }
48
-
49
- function __spreadArray(to, from, pack) {
50
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
51
- if (ar || !(i in from)) {
52
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
53
- ar[i] = from[i];
54
- }
55
- }
56
- return to.concat(ar || Array.prototype.slice.call(from));
57
- }
58
-
59
- var EventType;
60
- (function (EventType) {
61
- EventType[EventType["DomContentLoaded"] = 0] = "DomContentLoaded";
62
- EventType[EventType["Load"] = 1] = "Load";
63
- EventType[EventType["FullSnapshot"] = 2] = "FullSnapshot";
64
- EventType[EventType["IncrementalSnapshot"] = 3] = "IncrementalSnapshot";
65
- EventType[EventType["Meta"] = 4] = "Meta";
66
- EventType[EventType["Custom"] = 5] = "Custom";
67
- EventType[EventType["Plugin"] = 6] = "Plugin";
68
- })(EventType || (EventType = {}));
69
- var IncrementalSource;
70
- (function (IncrementalSource) {
71
- IncrementalSource[IncrementalSource["Mutation"] = 0] = "Mutation";
72
- IncrementalSource[IncrementalSource["MouseMove"] = 1] = "MouseMove";
73
- IncrementalSource[IncrementalSource["MouseInteraction"] = 2] = "MouseInteraction";
74
- IncrementalSource[IncrementalSource["Scroll"] = 3] = "Scroll";
75
- IncrementalSource[IncrementalSource["ViewportResize"] = 4] = "ViewportResize";
76
- IncrementalSource[IncrementalSource["Input"] = 5] = "Input";
77
- IncrementalSource[IncrementalSource["TouchMove"] = 6] = "TouchMove";
78
- IncrementalSource[IncrementalSource["MediaInteraction"] = 7] = "MediaInteraction";
79
- IncrementalSource[IncrementalSource["StyleSheetRule"] = 8] = "StyleSheetRule";
80
- IncrementalSource[IncrementalSource["CanvasMutation"] = 9] = "CanvasMutation";
81
- IncrementalSource[IncrementalSource["Font"] = 10] = "Font";
82
- IncrementalSource[IncrementalSource["Log"] = 11] = "Log";
83
- IncrementalSource[IncrementalSource["Drag"] = 12] = "Drag";
84
- IncrementalSource[IncrementalSource["StyleDeclaration"] = 13] = "StyleDeclaration";
85
- })(IncrementalSource || (IncrementalSource = {}));
86
- var MouseInteractions;
87
- (function (MouseInteractions) {
88
- MouseInteractions[MouseInteractions["MouseUp"] = 0] = "MouseUp";
89
- MouseInteractions[MouseInteractions["MouseDown"] = 1] = "MouseDown";
90
- MouseInteractions[MouseInteractions["Click"] = 2] = "Click";
91
- MouseInteractions[MouseInteractions["ContextMenu"] = 3] = "ContextMenu";
92
- MouseInteractions[MouseInteractions["DblClick"] = 4] = "DblClick";
93
- MouseInteractions[MouseInteractions["Focus"] = 5] = "Focus";
94
- MouseInteractions[MouseInteractions["Blur"] = 6] = "Blur";
95
- MouseInteractions[MouseInteractions["TouchStart"] = 7] = "TouchStart";
96
- MouseInteractions[MouseInteractions["TouchMove_Departed"] = 8] = "TouchMove_Departed";
97
- MouseInteractions[MouseInteractions["TouchEnd"] = 9] = "TouchEnd";
98
- MouseInteractions[MouseInteractions["TouchCancel"] = 10] = "TouchCancel";
99
- })(MouseInteractions || (MouseInteractions = {}));
100
- var CanvasContext;
101
- (function (CanvasContext) {
102
- CanvasContext[CanvasContext["2D"] = 0] = "2D";
103
- CanvasContext[CanvasContext["WebGL"] = 1] = "WebGL";
104
- CanvasContext[CanvasContext["WebGL2"] = 2] = "WebGL2";
105
- })(CanvasContext || (CanvasContext = {}));
106
- var MediaInteractions;
107
- (function (MediaInteractions) {
108
- MediaInteractions[MediaInteractions["Play"] = 0] = "Play";
109
- MediaInteractions[MediaInteractions["Pause"] = 1] = "Pause";
110
- MediaInteractions[MediaInteractions["Seeked"] = 2] = "Seeked";
111
- MediaInteractions[MediaInteractions["VolumeChange"] = 3] = "VolumeChange";
112
- })(MediaInteractions || (MediaInteractions = {}));
113
- var ReplayerEvents;
114
- (function (ReplayerEvents) {
115
- ReplayerEvents["Start"] = "start";
116
- ReplayerEvents["Pause"] = "pause";
117
- ReplayerEvents["Resume"] = "resume";
118
- ReplayerEvents["Resize"] = "resize";
119
- ReplayerEvents["Finish"] = "finish";
120
- ReplayerEvents["FullsnapshotRebuilded"] = "fullsnapshot-rebuilded";
121
- ReplayerEvents["LoadStylesheetStart"] = "load-stylesheet-start";
122
- ReplayerEvents["LoadStylesheetEnd"] = "load-stylesheet-end";
123
- ReplayerEvents["SkipStart"] = "skip-start";
124
- ReplayerEvents["SkipEnd"] = "skip-end";
125
- ReplayerEvents["MouseInteraction"] = "mouse-interaction";
126
- ReplayerEvents["EventCast"] = "event-cast";
127
- ReplayerEvents["CustomEvent"] = "custom-event";
128
- ReplayerEvents["Flush"] = "flush";
129
- ReplayerEvents["StateChange"] = "state-change";
130
- ReplayerEvents["PlayBack"] = "play-back";
131
- })(ReplayerEvents || (ReplayerEvents = {}));
132
-
133
5
  var NodeType;
134
6
  (function (NodeType) {
135
7
  NodeType[NodeType["Document"] = 0] = "Document";
@@ -140,511 +12,481 @@ var NodeType;
140
12
  NodeType[NodeType["Comment"] = 5] = "Comment";
141
13
  })(NodeType || (NodeType = {}));
142
14
 
143
- var DEPARTED_MIRROR_ACCESS_WARNING = 'Please stop import mirror directly. Instead of that,' +
144
- '\r\n' +
145
- 'now you can use replayer.getMirror() to access the mirror instance of a replayer,' +
146
- '\r\n' +
147
- 'or you can use record.mirror to access the mirror instance during recording.';
148
- var _mirror = {
149
- map: {},
150
- getId: function () {
151
- console.error(DEPARTED_MIRROR_ACCESS_WARNING);
152
- return -1;
153
- },
154
- getNode: function () {
155
- console.error(DEPARTED_MIRROR_ACCESS_WARNING);
156
- return null;
157
- },
158
- removeNodeFromMap: function () {
159
- console.error(DEPARTED_MIRROR_ACCESS_WARNING);
160
- },
161
- has: function () {
162
- console.error(DEPARTED_MIRROR_ACCESS_WARNING);
163
- return false;
164
- },
165
- reset: function () {
166
- console.error(DEPARTED_MIRROR_ACCESS_WARNING);
167
- },
168
- };
169
- if (typeof window !== 'undefined' && window.Proxy && window.Reflect) {
170
- _mirror = new Proxy(_mirror, {
171
- get: function (target, prop, receiver) {
172
- if (prop === 'map') {
173
- console.error(DEPARTED_MIRROR_ACCESS_WARNING);
174
- }
175
- return Reflect.get(target, prop, receiver);
176
- },
177
- });
178
- }
179
- function patch(source, name, replacement) {
180
- try {
181
- if (!(name in source)) {
182
- return function () { };
183
- }
184
- var original_1 = source[name];
185
- var wrapped = replacement(original_1);
186
- if (typeof wrapped === 'function') {
187
- wrapped.prototype = wrapped.prototype || {};
188
- Object.defineProperties(wrapped, {
189
- __rrweb_original__: {
190
- enumerable: false,
191
- value: original_1,
192
- },
193
- });
194
- }
195
- source[name] = wrapped;
196
- return function () {
197
- source[name] = original_1;
198
- };
199
- }
200
- catch (_a) {
201
- return function () { };
202
- }
15
+ const DEPARTED_MIRROR_ACCESS_WARNING = 'Please stop import mirror directly. Instead of that,' +
16
+ '\r\n' +
17
+ 'now you can use replayer.getMirror() to access the mirror instance of a replayer,' +
18
+ '\r\n' +
19
+ 'or you can use record.mirror to access the mirror instance during recording.';
20
+ let _mirror = {
21
+ map: {},
22
+ getId() {
23
+ console.error(DEPARTED_MIRROR_ACCESS_WARNING);
24
+ return -1;
25
+ },
26
+ getNode() {
27
+ console.error(DEPARTED_MIRROR_ACCESS_WARNING);
28
+ return null;
29
+ },
30
+ removeNodeFromMap() {
31
+ console.error(DEPARTED_MIRROR_ACCESS_WARNING);
32
+ },
33
+ has() {
34
+ console.error(DEPARTED_MIRROR_ACCESS_WARNING);
35
+ return false;
36
+ },
37
+ reset() {
38
+ console.error(DEPARTED_MIRROR_ACCESS_WARNING);
39
+ },
40
+ };
41
+ if (typeof window !== 'undefined' && window.Proxy && window.Reflect) {
42
+ _mirror = new Proxy(_mirror, {
43
+ get(target, prop, receiver) {
44
+ if (prop === 'map') {
45
+ console.error(DEPARTED_MIRROR_ACCESS_WARNING);
46
+ }
47
+ return Reflect.get(target, prop, receiver);
48
+ },
49
+ });
50
+ }
51
+ function patch(source, name, replacement) {
52
+ try {
53
+ if (!(name in source)) {
54
+ return () => { };
55
+ }
56
+ const original = source[name];
57
+ const wrapped = replacement(original);
58
+ if (typeof wrapped === 'function') {
59
+ wrapped.prototype = wrapped.prototype || {};
60
+ Object.defineProperties(wrapped, {
61
+ __rrweb_original__: {
62
+ enumerable: false,
63
+ value: original,
64
+ },
65
+ });
66
+ }
67
+ source[name] = wrapped;
68
+ return () => {
69
+ source[name] = original;
70
+ };
71
+ }
72
+ catch (_a) {
73
+ return () => { };
74
+ }
203
75
  }
204
76
 
205
- var StackFrame = (function () {
206
- function StackFrame(obj) {
207
- this.fileName = obj.fileName || '';
208
- this.functionName = obj.functionName || '';
209
- this.lineNumber = obj.lineNumber;
210
- this.columnNumber = obj.columnNumber;
211
- }
212
- StackFrame.prototype.toString = function () {
213
- var lineNumber = this.lineNumber || '';
214
- var columnNumber = this.columnNumber || '';
215
- if (this.functionName) {
216
- return (this.functionName +
217
- ' (' +
218
- this.fileName +
219
- ':' +
220
- lineNumber +
221
- ':' +
222
- columnNumber +
223
- ')');
224
- }
225
- return this.fileName + ':' + lineNumber + ':' + columnNumber;
226
- };
227
- return StackFrame;
228
- }());
229
- var FIREFOX_SAFARI_STACK_REGEXP = /(^|@)\S+:\d+/;
230
- var CHROME_IE_STACK_REGEXP = /^\s*at .*(\S+:\d+|\(native\))/m;
231
- var SAFARI_NATIVE_CODE_REGEXP = /^(eval@)?(\[native code])?$/;
232
- var ErrorStackParser = {
233
- parse: function (error) {
234
- if (!error) {
235
- return [];
236
- }
237
- if (typeof error.stacktrace !== 'undefined' ||
238
- typeof error['opera#sourceloc'] !== 'undefined') {
239
- return this.parseOpera(error);
240
- }
241
- else if (error.stack && error.stack.match(CHROME_IE_STACK_REGEXP)) {
242
- return this.parseV8OrIE(error);
243
- }
244
- else if (error.stack) {
245
- return this.parseFFOrSafari(error);
246
- }
247
- else {
248
- throw new Error('Cannot parse given Error object');
249
- }
250
- },
251
- extractLocation: function (urlLike) {
252
- if (urlLike.indexOf(':') === -1) {
253
- return [urlLike];
254
- }
255
- var regExp = /(.+?)(?::(\d+))?(?::(\d+))?$/;
256
- var parts = regExp.exec(urlLike.replace(/[()]/g, ''));
257
- if (!parts)
258
- throw new Error("Cannot parse given url: ".concat(urlLike));
259
- return [parts[1], parts[2] || undefined, parts[3] || undefined];
260
- },
261
- parseV8OrIE: function (error) {
262
- var filtered = error.stack.split('\n').filter(function (line) {
263
- return !!line.match(CHROME_IE_STACK_REGEXP);
264
- }, this);
265
- return filtered.map(function (line) {
266
- if (line.indexOf('(eval ') > -1) {
267
- line = line
268
- .replace(/eval code/g, 'eval')
269
- .replace(/(\(eval at [^()]*)|(\),.*$)/g, '');
270
- }
271
- var sanitizedLine = line.replace(/^\s+/, '').replace(/\(eval code/g, '(');
272
- var location = sanitizedLine.match(/ (\((.+):(\d+):(\d+)\)$)/);
273
- sanitizedLine = location
274
- ? sanitizedLine.replace(location[0], '')
275
- : sanitizedLine;
276
- var tokens = sanitizedLine.split(/\s+/).slice(1);
277
- var locationParts = this.extractLocation(location ? location[1] : tokens.pop());
278
- var functionName = tokens.join(' ') || undefined;
279
- var fileName = ['eval', '<anonymous>'].indexOf(locationParts[0]) > -1
280
- ? undefined
281
- : locationParts[0];
282
- return new StackFrame({
283
- functionName: functionName,
284
- fileName: fileName,
285
- lineNumber: locationParts[1],
286
- columnNumber: locationParts[2],
287
- });
288
- }, this);
289
- },
290
- parseFFOrSafari: function (error) {
291
- var filtered = error.stack.split('\n').filter(function (line) {
292
- return !line.match(SAFARI_NATIVE_CODE_REGEXP);
293
- }, this);
294
- return filtered.map(function (line) {
295
- if (line.indexOf(' > eval') > -1) {
296
- line = line.replace(/ line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g, ':$1');
297
- }
298
- if (line.indexOf('@') === -1 && line.indexOf(':') === -1) {
299
- return new StackFrame({
300
- functionName: line,
301
- });
302
- }
303
- else {
304
- var functionNameRegex = /((.*".+"[^@]*)?[^@]*)(?:@)/;
305
- var matches = line.match(functionNameRegex);
306
- var functionName = matches && matches[1] ? matches[1] : undefined;
307
- var locationParts = this.extractLocation(line.replace(functionNameRegex, ''));
308
- return new StackFrame({
309
- functionName: functionName,
310
- fileName: locationParts[0],
311
- lineNumber: locationParts[1],
312
- columnNumber: locationParts[2],
313
- });
314
- }
315
- }, this);
316
- },
317
- parseOpera: function (e) {
318
- if (!e.stacktrace ||
319
- (e.message.indexOf('\n') > -1 &&
320
- e.message.split('\n').length > e.stacktrace.split('\n').length)) {
321
- return this.parseOpera9(e);
322
- }
323
- else if (!e.stack) {
324
- return this.parseOpera10(e);
325
- }
326
- else {
327
- return this.parseOpera11(e);
328
- }
329
- },
330
- parseOpera9: function (e) {
331
- var lineRE = /Line (\d+).*script (?:in )?(\S+)/i;
332
- var lines = e.message.split('\n');
333
- var result = [];
334
- for (var i = 2, len = lines.length; i < len; i += 2) {
335
- var match = lineRE.exec(lines[i]);
336
- if (match) {
337
- result.push(new StackFrame({
338
- fileName: match[2],
339
- lineNumber: parseFloat(match[1]),
340
- }));
341
- }
342
- }
343
- return result;
344
- },
345
- parseOpera10: function (e) {
346
- var lineRE = /Line (\d+).*script (?:in )?(\S+)(?:: In function (\S+))?$/i;
347
- var lines = e.stacktrace.split('\n');
348
- var result = [];
349
- for (var i = 0, len = lines.length; i < len; i += 2) {
350
- var match = lineRE.exec(lines[i]);
351
- if (match) {
352
- result.push(new StackFrame({
353
- functionName: match[3] || undefined,
354
- fileName: match[2],
355
- lineNumber: parseFloat(match[1]),
356
- }));
357
- }
358
- }
359
- return result;
360
- },
361
- parseOpera11: function (error) {
362
- var filtered = error.stack.split('\n').filter(function (line) {
363
- return (!!line.match(FIREFOX_SAFARI_STACK_REGEXP) &&
364
- !line.match(/^Error created at/));
365
- }, this);
366
- return filtered.map(function (line) {
367
- var tokens = line.split('@');
368
- var locationParts = this.extractLocation(tokens.pop());
369
- var functionCall = tokens.shift() || '';
370
- var functionName = functionCall
371
- .replace(/<anonymous function(: (\w+))?>/, '$2')
372
- .replace(/\([^)]*\)/g, '') || undefined;
373
- return new StackFrame({
374
- functionName: functionName,
375
- fileName: locationParts[0],
376
- lineNumber: locationParts[1],
377
- columnNumber: locationParts[2],
378
- });
379
- }, this);
380
- },
77
+ class StackFrame {
78
+ constructor(obj) {
79
+ this.fileName = obj.fileName || '';
80
+ this.functionName = obj.functionName || '';
81
+ this.lineNumber = obj.lineNumber;
82
+ this.columnNumber = obj.columnNumber;
83
+ }
84
+ toString() {
85
+ const lineNumber = this.lineNumber || '';
86
+ const columnNumber = this.columnNumber || '';
87
+ if (this.functionName) {
88
+ return (this.functionName +
89
+ ' (' +
90
+ this.fileName +
91
+ ':' +
92
+ lineNumber +
93
+ ':' +
94
+ columnNumber +
95
+ ')');
96
+ }
97
+ return this.fileName + ':' + lineNumber + ':' + columnNumber;
98
+ }
99
+ }
100
+ const FIREFOX_SAFARI_STACK_REGEXP = /(^|@)\S+:\d+/;
101
+ const CHROME_IE_STACK_REGEXP = /^\s*at .*(\S+:\d+|\(native\))/m;
102
+ const SAFARI_NATIVE_CODE_REGEXP = /^(eval@)?(\[native code])?$/;
103
+ const ErrorStackParser = {
104
+ parse: function (error) {
105
+ if (!error) {
106
+ return [];
107
+ }
108
+ if (typeof error.stacktrace !== 'undefined' ||
109
+ typeof error['opera#sourceloc'] !== 'undefined') {
110
+ return this.parseOpera(error);
111
+ }
112
+ else if (error.stack && error.stack.match(CHROME_IE_STACK_REGEXP)) {
113
+ return this.parseV8OrIE(error);
114
+ }
115
+ else if (error.stack) {
116
+ return this.parseFFOrSafari(error);
117
+ }
118
+ else {
119
+ throw new Error('Cannot parse given Error object');
120
+ }
121
+ },
122
+ extractLocation: function (urlLike) {
123
+ if (urlLike.indexOf(':') === -1) {
124
+ return [urlLike];
125
+ }
126
+ const regExp = /(.+?)(?::(\d+))?(?::(\d+))?$/;
127
+ const parts = regExp.exec(urlLike.replace(/[()]/g, ''));
128
+ if (!parts)
129
+ throw new Error(`Cannot parse given url: ${urlLike}`);
130
+ return [parts[1], parts[2] || undefined, parts[3] || undefined];
131
+ },
132
+ parseV8OrIE: function (error) {
133
+ const filtered = error.stack.split('\n').filter(function (line) {
134
+ return !!line.match(CHROME_IE_STACK_REGEXP);
135
+ }, this);
136
+ return filtered.map(function (line) {
137
+ if (line.indexOf('(eval ') > -1) {
138
+ line = line
139
+ .replace(/eval code/g, 'eval')
140
+ .replace(/(\(eval at [^()]*)|(\),.*$)/g, '');
141
+ }
142
+ let sanitizedLine = line.replace(/^\s+/, '').replace(/\(eval code/g, '(');
143
+ const location = sanitizedLine.match(/ (\((.+):(\d+):(\d+)\)$)/);
144
+ sanitizedLine = location
145
+ ? sanitizedLine.replace(location[0], '')
146
+ : sanitizedLine;
147
+ const tokens = sanitizedLine.split(/\s+/).slice(1);
148
+ const locationParts = this.extractLocation(location ? location[1] : tokens.pop());
149
+ const functionName = tokens.join(' ') || undefined;
150
+ const fileName = ['eval', '<anonymous>'].indexOf(locationParts[0]) > -1
151
+ ? undefined
152
+ : locationParts[0];
153
+ return new StackFrame({
154
+ functionName,
155
+ fileName,
156
+ lineNumber: locationParts[1],
157
+ columnNumber: locationParts[2],
158
+ });
159
+ }, this);
160
+ },
161
+ parseFFOrSafari: function (error) {
162
+ const filtered = error.stack.split('\n').filter(function (line) {
163
+ return !line.match(SAFARI_NATIVE_CODE_REGEXP);
164
+ }, this);
165
+ return filtered.map(function (line) {
166
+ if (line.indexOf(' > eval') > -1) {
167
+ line = line.replace(/ line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g, ':$1');
168
+ }
169
+ if (line.indexOf('@') === -1 && line.indexOf(':') === -1) {
170
+ return new StackFrame({
171
+ functionName: line,
172
+ });
173
+ }
174
+ else {
175
+ const functionNameRegex = /((.*".+"[^@]*)?[^@]*)(?:@)/;
176
+ const matches = line.match(functionNameRegex);
177
+ const functionName = matches && matches[1] ? matches[1] : undefined;
178
+ const locationParts = this.extractLocation(line.replace(functionNameRegex, ''));
179
+ return new StackFrame({
180
+ functionName,
181
+ fileName: locationParts[0],
182
+ lineNumber: locationParts[1],
183
+ columnNumber: locationParts[2],
184
+ });
185
+ }
186
+ }, this);
187
+ },
188
+ parseOpera: function (e) {
189
+ if (!e.stacktrace ||
190
+ (e.message.indexOf('\n') > -1 &&
191
+ e.message.split('\n').length > e.stacktrace.split('\n').length)) {
192
+ return this.parseOpera9(e);
193
+ }
194
+ else if (!e.stack) {
195
+ return this.parseOpera10(e);
196
+ }
197
+ else {
198
+ return this.parseOpera11(e);
199
+ }
200
+ },
201
+ parseOpera9: function (e) {
202
+ const lineRE = /Line (\d+).*script (?:in )?(\S+)/i;
203
+ const lines = e.message.split('\n');
204
+ const result = [];
205
+ for (let i = 2, len = lines.length; i < len; i += 2) {
206
+ const match = lineRE.exec(lines[i]);
207
+ if (match) {
208
+ result.push(new StackFrame({
209
+ fileName: match[2],
210
+ lineNumber: parseFloat(match[1]),
211
+ }));
212
+ }
213
+ }
214
+ return result;
215
+ },
216
+ parseOpera10: function (e) {
217
+ const lineRE = /Line (\d+).*script (?:in )?(\S+)(?:: In function (\S+))?$/i;
218
+ const lines = e.stacktrace.split('\n');
219
+ const result = [];
220
+ for (let i = 0, len = lines.length; i < len; i += 2) {
221
+ const match = lineRE.exec(lines[i]);
222
+ if (match) {
223
+ result.push(new StackFrame({
224
+ functionName: match[3] || undefined,
225
+ fileName: match[2],
226
+ lineNumber: parseFloat(match[1]),
227
+ }));
228
+ }
229
+ }
230
+ return result;
231
+ },
232
+ parseOpera11: function (error) {
233
+ const filtered = error.stack.split('\n').filter(function (line) {
234
+ return (!!line.match(FIREFOX_SAFARI_STACK_REGEXP) &&
235
+ !line.match(/^Error created at/));
236
+ }, this);
237
+ return filtered.map(function (line) {
238
+ const tokens = line.split('@');
239
+ const locationParts = this.extractLocation(tokens.pop());
240
+ const functionCall = tokens.shift() || '';
241
+ const functionName = functionCall
242
+ .replace(/<anonymous function(: (\w+))?>/, '$2')
243
+ .replace(/\([^)]*\)/g, '') || undefined;
244
+ return new StackFrame({
245
+ functionName,
246
+ fileName: locationParts[0],
247
+ lineNumber: locationParts[1],
248
+ columnNumber: locationParts[2],
249
+ });
250
+ }, this);
251
+ },
381
252
  };
382
253
 
383
- function pathToSelector(node) {
384
- if (!node || !node.outerHTML) {
385
- return '';
386
- }
387
- var path = '';
388
- while (node.parentElement) {
389
- var name_1 = node.localName;
390
- if (!name_1) {
391
- break;
392
- }
393
- name_1 = name_1.toLowerCase();
394
- var parent_1 = node.parentElement;
395
- var domSiblings = [];
396
- if (parent_1.children && parent_1.children.length > 0) {
397
- for (var i = 0; i < parent_1.children.length; i++) {
398
- var sibling = parent_1.children[i];
399
- if (sibling.localName && sibling.localName.toLowerCase) {
400
- if (sibling.localName.toLowerCase() === name_1) {
401
- domSiblings.push(sibling);
402
- }
403
- }
404
- }
405
- }
406
- if (domSiblings.length > 1) {
407
- name_1 += ':eq(' + domSiblings.indexOf(node) + ')';
408
- }
409
- path = name_1 + (path ? '>' + path : '');
410
- node = parent_1;
411
- }
412
- return path;
413
- }
414
- function isObject(obj) {
415
- return Object.prototype.toString.call(obj) === '[object Object]';
416
- }
417
- function isObjTooDeep(obj, limit) {
418
- var e_1, _a;
419
- if (limit === 0) {
420
- return true;
421
- }
422
- var keys = Object.keys(obj);
423
- try {
424
- for (var keys_1 = __values(keys), keys_1_1 = keys_1.next(); !keys_1_1.done; keys_1_1 = keys_1.next()) {
425
- var key = keys_1_1.value;
426
- if (isObject(obj[key]) && isObjTooDeep(obj[key], limit - 1)) {
427
- return true;
428
- }
429
- }
430
- }
431
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
432
- finally {
433
- try {
434
- if (keys_1_1 && !keys_1_1.done && (_a = keys_1.return)) _a.call(keys_1);
435
- }
436
- finally { if (e_1) throw e_1.error; }
437
- }
438
- return false;
439
- }
440
- function stringify(obj, stringifyOptions) {
441
- var options = {
442
- numOfKeysLimit: 50,
443
- depthOfLimit: 4,
444
- };
445
- Object.assign(options, stringifyOptions);
446
- var stack = [];
447
- var keys = [];
448
- return JSON.stringify(obj, function (key, value) {
449
- if (stack.length > 0) {
450
- var thisPos = stack.indexOf(this);
451
- ~thisPos ? stack.splice(thisPos + 1) : stack.push(this);
452
- ~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key);
453
- if (~stack.indexOf(value)) {
454
- if (stack[0] === value) {
455
- value = '[Circular ~]';
456
- }
457
- else {
458
- value =
459
- '[Circular ~.' +
460
- keys.slice(0, stack.indexOf(value)).join('.') +
461
- ']';
462
- }
463
- }
464
- }
465
- else {
466
- stack.push(value);
467
- }
468
- if (value === null || value === undefined) {
469
- return value;
470
- }
471
- if (shouldIgnore(value)) {
472
- return toString(value);
473
- }
474
- if (value instanceof Event) {
475
- var eventResult = {};
476
- for (var eventKey in value) {
477
- var eventValue = value[eventKey];
478
- if (Array.isArray(eventValue)) {
479
- eventResult[eventKey] = pathToSelector(eventValue.length ? eventValue[0] : null);
480
- }
481
- else {
482
- eventResult[eventKey] = eventValue;
483
- }
484
- }
485
- return eventResult;
486
- }
487
- else if (value instanceof Node) {
488
- if (value instanceof HTMLElement) {
489
- return value ? value.outerHTML : '';
490
- }
491
- return value.nodeName;
492
- }
493
- else if (value instanceof Error) {
494
- return value.stack
495
- ? value.stack + '\nEnd of stack for Error object'
496
- : value.name + ': ' + value.message;
497
- }
498
- return value;
499
- });
500
- function shouldIgnore(_obj) {
501
- if (isObject(_obj) && Object.keys(_obj).length > options.numOfKeysLimit) {
502
- return true;
503
- }
504
- if (typeof _obj === 'function') {
505
- return true;
506
- }
507
- if (isObject(_obj) && isObjTooDeep(_obj, options.depthOfLimit)) {
508
- return true;
509
- }
510
- return false;
511
- }
512
- function toString(_obj) {
513
- var str = _obj.toString();
514
- if (options.stringLengthLimit && str.length > options.stringLengthLimit) {
515
- str = "".concat(str.slice(0, options.stringLengthLimit), "...");
516
- }
517
- return str;
518
- }
254
+ function pathToSelector(node) {
255
+ if (!node || !node.outerHTML) {
256
+ return '';
257
+ }
258
+ let path = '';
259
+ while (node.parentElement) {
260
+ let name = node.localName;
261
+ if (!name) {
262
+ break;
263
+ }
264
+ name = name.toLowerCase();
265
+ const parent = node.parentElement;
266
+ const domSiblings = [];
267
+ if (parent.children && parent.children.length > 0) {
268
+ for (let i = 0; i < parent.children.length; i++) {
269
+ const sibling = parent.children[i];
270
+ if (sibling.localName && sibling.localName.toLowerCase) {
271
+ if (sibling.localName.toLowerCase() === name) {
272
+ domSiblings.push(sibling);
273
+ }
274
+ }
275
+ }
276
+ }
277
+ if (domSiblings.length > 1) {
278
+ name += ':eq(' + domSiblings.indexOf(node) + ')';
279
+ }
280
+ path = name + (path ? '>' + path : '');
281
+ node = parent;
282
+ }
283
+ return path;
284
+ }
285
+ function isObject(obj) {
286
+ return Object.prototype.toString.call(obj) === '[object Object]';
287
+ }
288
+ function isObjTooDeep(obj, limit) {
289
+ if (limit === 0) {
290
+ return true;
291
+ }
292
+ const keys = Object.keys(obj);
293
+ for (const key of keys) {
294
+ if (isObject(obj[key]) && isObjTooDeep(obj[key], limit - 1)) {
295
+ return true;
296
+ }
297
+ }
298
+ return false;
299
+ }
300
+ function stringify(obj, stringifyOptions) {
301
+ const options = {
302
+ numOfKeysLimit: 50,
303
+ depthOfLimit: 4,
304
+ };
305
+ Object.assign(options, stringifyOptions);
306
+ const stack = [];
307
+ const keys = [];
308
+ return JSON.stringify(obj, function (key, value) {
309
+ if (stack.length > 0) {
310
+ const thisPos = stack.indexOf(this);
311
+ ~thisPos ? stack.splice(thisPos + 1) : stack.push(this);
312
+ ~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key);
313
+ if (~stack.indexOf(value)) {
314
+ if (stack[0] === value) {
315
+ value = '[Circular ~]';
316
+ }
317
+ else {
318
+ value =
319
+ '[Circular ~.' +
320
+ keys.slice(0, stack.indexOf(value)).join('.') +
321
+ ']';
322
+ }
323
+ }
324
+ }
325
+ else {
326
+ stack.push(value);
327
+ }
328
+ if (value === null || value === undefined) {
329
+ return value;
330
+ }
331
+ if (shouldIgnore(value)) {
332
+ return toString(value);
333
+ }
334
+ if (value instanceof Event) {
335
+ const eventResult = {};
336
+ for (const eventKey in value) {
337
+ const eventValue = value[eventKey];
338
+ if (Array.isArray(eventValue)) {
339
+ eventResult[eventKey] = pathToSelector(eventValue.length ? eventValue[0] : null);
340
+ }
341
+ else {
342
+ eventResult[eventKey] = eventValue;
343
+ }
344
+ }
345
+ return eventResult;
346
+ }
347
+ else if (value instanceof Node) {
348
+ if (value instanceof HTMLElement) {
349
+ return value ? value.outerHTML : '';
350
+ }
351
+ return value.nodeName;
352
+ }
353
+ else if (value instanceof Error) {
354
+ return value.stack
355
+ ? value.stack + '\nEnd of stack for Error object'
356
+ : value.name + ': ' + value.message;
357
+ }
358
+ return value;
359
+ });
360
+ function shouldIgnore(_obj) {
361
+ if (isObject(_obj) && Object.keys(_obj).length > options.numOfKeysLimit) {
362
+ return true;
363
+ }
364
+ if (typeof _obj === 'function') {
365
+ return true;
366
+ }
367
+ if (isObject(_obj) && isObjTooDeep(_obj, options.depthOfLimit)) {
368
+ return true;
369
+ }
370
+ return false;
371
+ }
372
+ function toString(_obj) {
373
+ let str = _obj.toString();
374
+ if (options.stringLengthLimit && str.length > options.stringLengthLimit) {
375
+ str = `${str.slice(0, options.stringLengthLimit)}...`;
376
+ }
377
+ return str;
378
+ }
519
379
  }
520
380
 
521
- var defaultLogOptions = {
522
- level: [
523
- 'assert',
524
- 'clear',
525
- 'count',
526
- 'countReset',
527
- 'debug',
528
- 'dir',
529
- 'dirxml',
530
- 'error',
531
- 'group',
532
- 'groupCollapsed',
533
- 'groupEnd',
534
- 'info',
535
- 'log',
536
- 'table',
537
- 'time',
538
- 'timeEnd',
539
- 'timeLog',
540
- 'trace',
541
- 'warn',
542
- ],
543
- lengthThreshold: 1000,
544
- logger: 'console',
545
- };
546
- function initLogObserver(cb, win, logOptions) {
547
- var e_1, _a;
548
- var loggerType = logOptions.logger;
549
- if (!loggerType) {
550
- return function () { };
551
- }
552
- var logger;
553
- if (typeof loggerType === 'string') {
554
- logger = win[loggerType];
555
- }
556
- else {
557
- logger = loggerType;
558
- }
559
- var logCount = 0;
560
- var cancelHandlers = [];
561
- if (logOptions.level.includes('error')) {
562
- if (window) {
563
- var errorHandler_1 = function (event) {
564
- var message = event.message, error = event.error;
565
- var trace = ErrorStackParser.parse(error).map(function (stackFrame) { return stackFrame.toString(); });
566
- var payload = [stringify(message, logOptions.stringifyOptions)];
567
- cb({
568
- level: 'error',
569
- trace: trace,
570
- payload: payload,
571
- });
572
- };
573
- window.addEventListener('error', errorHandler_1);
574
- cancelHandlers.push(function () {
575
- if (window)
576
- window.removeEventListener('error', errorHandler_1);
577
- });
578
- }
579
- }
580
- try {
581
- for (var _b = __values(logOptions.level), _c = _b.next(); !_c.done; _c = _b.next()) {
582
- var levelType = _c.value;
583
- cancelHandlers.push(replace(logger, levelType));
584
- }
585
- }
586
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
587
- finally {
588
- try {
589
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
590
- }
591
- finally { if (e_1) throw e_1.error; }
592
- }
593
- return function () {
594
- cancelHandlers.forEach(function (h) { return h(); });
595
- };
596
- function replace(_logger, level) {
597
- var _this = this;
598
- if (!_logger[level]) {
599
- return function () { };
600
- }
601
- return patch(_logger, level, function (original) {
602
- return function () {
603
- var args = [];
604
- for (var _i = 0; _i < arguments.length; _i++) {
605
- args[_i] = arguments[_i];
606
- }
607
- original.apply(_this, args);
608
- try {
609
- var trace = ErrorStackParser.parse(new Error())
610
- .map(function (stackFrame) { return stackFrame.toString(); })
611
- .splice(1);
612
- var payload = args.map(function (s) {
613
- return stringify(s, logOptions.stringifyOptions);
614
- });
615
- logCount++;
616
- if (logCount < logOptions.lengthThreshold) {
617
- cb({
618
- level: level,
619
- trace: trace,
620
- payload: payload,
621
- });
622
- }
623
- else if (logCount === logOptions.lengthThreshold) {
624
- cb({
625
- level: 'warn',
626
- trace: [],
627
- payload: [
628
- stringify('The number of log records reached the threshold.'),
629
- ],
630
- });
631
- }
632
- }
633
- catch (error) {
634
- original.apply(void 0, __spreadArray(['rrweb logger error:', error], __read(args), false));
635
- }
636
- };
637
- });
638
- }
639
- }
640
- var PLUGIN_NAME = 'rrweb/console@1';
641
- var getRecordConsolePlugin = function (options) { return ({
642
- name: PLUGIN_NAME,
643
- observer: initLogObserver,
644
- options: options
645
- ? Object.assign({}, defaultLogOptions, options)
646
- : defaultLogOptions,
647
- }); };
381
+ const defaultLogOptions = {
382
+ level: [
383
+ 'assert',
384
+ 'clear',
385
+ 'count',
386
+ 'countReset',
387
+ 'debug',
388
+ 'dir',
389
+ 'dirxml',
390
+ 'error',
391
+ 'group',
392
+ 'groupCollapsed',
393
+ 'groupEnd',
394
+ 'info',
395
+ 'log',
396
+ 'table',
397
+ 'time',
398
+ 'timeEnd',
399
+ 'timeLog',
400
+ 'trace',
401
+ 'warn',
402
+ ],
403
+ lengthThreshold: 1000,
404
+ logger: 'console',
405
+ };
406
+ function initLogObserver(cb, win, logOptions) {
407
+ const loggerType = logOptions.logger;
408
+ if (!loggerType) {
409
+ return () => { };
410
+ }
411
+ let logger;
412
+ if (typeof loggerType === 'string') {
413
+ logger = win[loggerType];
414
+ }
415
+ else {
416
+ logger = loggerType;
417
+ }
418
+ let logCount = 0;
419
+ const cancelHandlers = [];
420
+ if (logOptions.level.includes('error')) {
421
+ if (window) {
422
+ const errorHandler = (event) => {
423
+ const { message, error } = event;
424
+ const trace = ErrorStackParser.parse(error).map((stackFrame) => stackFrame.toString());
425
+ const payload = [stringify(message, logOptions.stringifyOptions)];
426
+ cb({
427
+ level: 'error',
428
+ trace,
429
+ payload,
430
+ });
431
+ };
432
+ window.addEventListener('error', errorHandler);
433
+ cancelHandlers.push(() => {
434
+ if (window)
435
+ window.removeEventListener('error', errorHandler);
436
+ });
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
+ return patch(_logger, level, (original) => {
450
+ return (...args) => {
451
+ original.apply(this, args);
452
+ try {
453
+ const trace = ErrorStackParser.parse(new Error())
454
+ .map((stackFrame) => stackFrame.toString())
455
+ .splice(1);
456
+ const payload = args.map((s) => stringify(s, logOptions.stringifyOptions));
457
+ logCount++;
458
+ if (logCount < logOptions.lengthThreshold) {
459
+ cb({
460
+ level,
461
+ trace,
462
+ payload,
463
+ });
464
+ }
465
+ else if (logCount === logOptions.lengthThreshold) {
466
+ cb({
467
+ level: 'warn',
468
+ trace: [],
469
+ payload: [
470
+ stringify('The number of log records reached the threshold.'),
471
+ ],
472
+ });
473
+ }
474
+ }
475
+ catch (error) {
476
+ original('rrweb logger error:', error, ...args);
477
+ }
478
+ };
479
+ });
480
+ }
481
+ }
482
+ const PLUGIN_NAME = 'rrweb/console@1';
483
+ const getRecordConsolePlugin = (options) => ({
484
+ name: PLUGIN_NAME,
485
+ observer: initLogObserver,
486
+ options: options
487
+ ? Object.assign({}, defaultLogOptions, options)
488
+ : defaultLogOptions,
489
+ });
648
490
 
649
491
  exports.PLUGIN_NAME = PLUGIN_NAME;
650
492
  exports.getRecordConsolePlugin = getRecordConsolePlugin;