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