@highlight-run/rrweb 2.0.12 → 2.0.16

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 (37) hide show
  1. package/dist/plugins/console-record.min.js.map +1 -1
  2. package/dist/plugins/console-replay.min.js.map +1 -1
  3. package/dist/record/rrweb-record-pack.min.js.map +1 -1
  4. package/dist/record/rrweb-record.js +3 -3
  5. package/dist/record/rrweb-record.min.js +3 -3
  6. package/dist/record/rrweb-record.min.js.map +1 -1
  7. package/dist/replay/rrweb-replay-unpack.js +4 -4
  8. package/dist/replay/rrweb-replay-unpack.min.js +4 -4
  9. package/dist/replay/rrweb-replay-unpack.min.js.map +1 -1
  10. package/dist/replay/rrweb-replay.js +4 -4
  11. package/dist/replay/rrweb-replay.min.js +4 -4
  12. package/dist/replay/rrweb-replay.min.js.map +1 -1
  13. package/dist/rrweb-all.js +8 -8
  14. package/dist/rrweb-all.min.js +8 -8
  15. package/dist/rrweb-all.min.js.map +1 -1
  16. package/dist/rrweb.js +5 -5
  17. package/dist/rrweb.min.js +5 -5
  18. package/dist/rrweb.min.js.map +1 -1
  19. package/es/rrweb/packages/rrdom/es/{virtual-dom.js → rrdom.js} +104 -114
  20. package/es/rrweb/packages/rrweb/src/index.js +1 -1
  21. package/es/rrweb/packages/rrweb/src/record/index.js +2 -0
  22. package/es/rrweb/packages/rrweb/src/record/mutation.js +12 -1
  23. package/es/rrweb/packages/rrweb/src/replay/index.js +3 -3
  24. package/es/rrweb/packages/rrweb-snapshot/es/rrweb-snapshot.js +1860 -1861
  25. package/lib/plugins/console-record.js +8 -8
  26. package/lib/plugins/console-replay.js +8 -8
  27. package/lib/record/rrweb-record-pack.js +8 -8
  28. package/lib/record/rrweb-record.js +1055 -1043
  29. package/lib/replay/rrweb-replay-unpack.js +988 -998
  30. package/lib/replay/rrweb-replay.js +988 -998
  31. package/lib/rrweb-all.js +1980 -1978
  32. package/lib/rrweb.js +1980 -1978
  33. package/package.json +5 -5
  34. package/typings/record/mutation.d.ts +1 -0
  35. package/typings/replay/index.d.ts +1 -1
  36. package/typings/types.d.ts +3 -2
  37. package/typings/utils.d.ts +1 -1
package/lib/rrweb.js CHANGED
@@ -2,1874 +2,1873 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var NodeType$2;
6
- (function (NodeType) {
7
- NodeType[NodeType["Document"] = 0] = "Document";
8
- NodeType[NodeType["DocumentType"] = 1] = "DocumentType";
9
- NodeType[NodeType["Element"] = 2] = "Element";
10
- NodeType[NodeType["Text"] = 3] = "Text";
11
- NodeType[NodeType["CDATA"] = 4] = "CDATA";
12
- NodeType[NodeType["Comment"] = 5] = "Comment";
5
+ var NodeType$2;
6
+ (function (NodeType) {
7
+ NodeType[NodeType["Document"] = 0] = "Document";
8
+ NodeType[NodeType["DocumentType"] = 1] = "DocumentType";
9
+ NodeType[NodeType["Element"] = 2] = "Element";
10
+ NodeType[NodeType["Text"] = 3] = "Text";
11
+ NodeType[NodeType["CDATA"] = 4] = "CDATA";
12
+ NodeType[NodeType["Comment"] = 5] = "Comment";
13
13
  })(NodeType$2 || (NodeType$2 = {}));
14
14
 
15
- function isElement(n) {
16
- return n.nodeType === n.ELEMENT_NODE;
17
- }
18
- function isShadowRoot(n) {
19
- var _a;
20
- var host = (_a = n) === null || _a === void 0 ? void 0 : _a.host;
21
- return Boolean((host === null || host === void 0 ? void 0 : host.shadowRoot) === n);
22
- }
23
- var Mirror$2 = (function () {
24
- function Mirror() {
25
- this.idNodeMap = new Map();
26
- this.nodeMetaMap = new WeakMap();
27
- }
28
- Mirror.prototype.getId = function (n) {
29
- var _a;
30
- if (!n)
31
- return -1;
32
- var id = (_a = this.getMeta(n)) === null || _a === void 0 ? void 0 : _a.id;
33
- return id !== null && id !== void 0 ? id : -1;
34
- };
35
- Mirror.prototype.getNode = function (id) {
36
- return this.idNodeMap.get(id) || null;
37
- };
38
- Mirror.prototype.getIds = function () {
39
- return Array.from(this.idNodeMap.keys());
40
- };
41
- Mirror.prototype.getMeta = function (n) {
42
- return this.nodeMetaMap.get(n) || null;
43
- };
44
- Mirror.prototype.removeNodeFromMap = function (n) {
45
- var _this = this;
46
- var id = this.getId(n);
47
- this.idNodeMap["delete"](id);
48
- if (n.childNodes) {
49
- n.childNodes.forEach(function (childNode) {
50
- return _this.removeNodeFromMap(childNode);
51
- });
52
- }
53
- };
54
- Mirror.prototype.has = function (id) {
55
- return this.idNodeMap.has(id);
56
- };
57
- Mirror.prototype.hasNode = function (node) {
58
- return this.nodeMetaMap.has(node);
59
- };
60
- Mirror.prototype.add = function (n, meta) {
61
- var id = meta.id;
62
- this.idNodeMap.set(id, n);
63
- this.nodeMetaMap.set(n, meta);
64
- };
65
- Mirror.prototype.replace = function (id, n) {
66
- this.idNodeMap.set(id, n);
67
- };
68
- Mirror.prototype.reset = function () {
69
- this.idNodeMap = new Map();
70
- this.nodeMetaMap = new WeakMap();
71
- };
72
- return Mirror;
73
- }());
74
- function createMirror$2() {
75
- return new Mirror$2();
76
- }
77
- function maskInputValue(_a) {
78
- var maskInputOptions = _a.maskInputOptions, tagName = _a.tagName, type = _a.type, value = _a.value, maskInputFn = _a.maskInputFn;
79
- var text = value || '';
80
- if (maskInputOptions[tagName.toLowerCase()] ||
81
- maskInputOptions[type]) {
82
- if (maskInputFn) {
83
- text = maskInputFn(text);
84
- }
85
- else {
86
- text = '*'.repeat(text.length);
87
- }
88
- }
89
- return text;
90
- }
91
- var ORIGINAL_ATTRIBUTE_NAME = '__rrweb_original__';
92
- function is2DCanvasBlank(canvas) {
93
- var ctx = canvas.getContext('2d');
94
- if (!ctx)
95
- return true;
96
- var chunkSize = 50;
97
- for (var x = 0; x < canvas.width; x += chunkSize) {
98
- for (var y = 0; y < canvas.height; y += chunkSize) {
99
- var getImageData = ctx.getImageData;
100
- var originalGetImageData = ORIGINAL_ATTRIBUTE_NAME in getImageData
101
- ? getImageData[ORIGINAL_ATTRIBUTE_NAME]
102
- : getImageData;
103
- var pixelBuffer = new Uint32Array(originalGetImageData.call(ctx, x, y, Math.min(chunkSize, canvas.width - x), Math.min(chunkSize, canvas.height - y)).data.buffer);
104
- if (pixelBuffer.some(function (pixel) { return pixel !== 0; }))
105
- return false;
106
- }
107
- }
108
- return true;
109
- }
110
- function obfuscateText(text) {
111
- text = text.replace(/[^ -~]+/g, '');
112
- text =
113
- (text === null || text === void 0 ? void 0 : text.split(' ').map(function (word) { return Math.random().toString(20).substr(2, word.length); }).join(' ')) || '';
114
- return text;
115
- }
116
-
117
- var _id = 1;
118
- var tagNameRegex = new RegExp('[^a-z0-9-_:]');
119
- var IGNORED_NODE = -2;
120
- function genId() {
121
- return _id++;
122
- }
123
- function getValidTagName$1(element) {
124
- if (element instanceof HTMLFormElement) {
125
- return 'form';
126
- }
127
- var processedTagName = element.tagName.toLowerCase().trim();
128
- if (tagNameRegex.test(processedTagName)) {
129
- return 'div';
130
- }
131
- return processedTagName;
132
- }
133
- function getCssRulesString(s) {
134
- try {
135
- var rules = s.rules || s.cssRules;
136
- return rules ? Array.from(rules).map(getCssRuleString).join('') : null;
137
- }
138
- catch (error) {
139
- return null;
140
- }
141
- }
142
- function getCssRuleString(rule) {
143
- var cssStringified = rule.cssText;
144
- if (isCSSImportRule(rule)) {
145
- try {
146
- cssStringified = getCssRulesString(rule.styleSheet) || cssStringified;
147
- }
148
- catch (_a) {
149
- }
150
- }
151
- return cssStringified;
152
- }
153
- function isCSSImportRule(rule) {
154
- return 'styleSheet' in rule;
155
- }
156
- function stringifyStyleSheet(sheet) {
157
- return sheet.cssRules
158
- ? Array.from(sheet.cssRules)
159
- .map(function (rule) { return rule.cssText || ''; })
160
- .join('')
161
- : '';
162
- }
163
- function extractOrigin(url) {
164
- var origin = '';
165
- if (url.indexOf('//') > -1) {
166
- origin = url.split('/').slice(0, 3).join('/');
167
- }
168
- else {
169
- origin = url.split('/')[0];
170
- }
171
- origin = origin.split('?')[0];
172
- return origin;
173
- }
174
- var canvasService;
175
- var canvasCtx;
176
- var URL_IN_CSS_REF = /url\((?:(')([^']*)'|(")(.*?)"|([^)]*))\)/gm;
177
- var RELATIVE_PATH = /^(?!www\.|(?:http|ftp)s?:\/\/|[A-Za-z]:\\|\/\/|#).*/;
178
- var DATA_URI = /^(data:)([^,]*),(.*)/i;
179
- function absoluteToStylesheet(cssText, href) {
180
- return (cssText || '').replace(URL_IN_CSS_REF, function (origin, quote1, path1, quote2, path2, path3) {
181
- var filePath = path1 || path2 || path3;
182
- var maybeQuote = quote1 || quote2 || '';
183
- if (!filePath) {
184
- return origin;
185
- }
186
- if (!RELATIVE_PATH.test(filePath)) {
187
- return "url(" + maybeQuote + filePath + maybeQuote + ")";
188
- }
189
- if (DATA_URI.test(filePath)) {
190
- return "url(" + maybeQuote + filePath + maybeQuote + ")";
191
- }
192
- if (filePath[0] === '/') {
193
- return "url(" + maybeQuote + (extractOrigin(href) + filePath) + maybeQuote + ")";
194
- }
195
- var stack = href.split('/');
196
- var parts = filePath.split('/');
197
- stack.pop();
198
- for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
199
- var part = parts_1[_i];
200
- if (part === '.') {
201
- continue;
202
- }
203
- else if (part === '..') {
204
- stack.pop();
205
- }
206
- else {
207
- stack.push(part);
208
- }
209
- }
210
- return "url(" + maybeQuote + stack.join('/') + maybeQuote + ")";
211
- });
212
- }
213
- var SRCSET_NOT_SPACES = /^[^ \t\n\r\u000c]+/;
214
- var SRCSET_COMMAS_OR_SPACES = /^[, \t\n\r\u000c]+/;
215
- function getAbsoluteSrcsetString(doc, attributeValue) {
216
- if (attributeValue.trim() === '') {
217
- return attributeValue;
218
- }
219
- var pos = 0;
220
- function collectCharacters(regEx) {
221
- var chars;
222
- var match = regEx.exec(attributeValue.substring(pos));
223
- if (match) {
224
- chars = match[0];
225
- pos += chars.length;
226
- return chars;
227
- }
228
- return '';
229
- }
230
- var output = [];
231
- while (true) {
232
- collectCharacters(SRCSET_COMMAS_OR_SPACES);
233
- if (pos >= attributeValue.length) {
234
- break;
235
- }
236
- var url = collectCharacters(SRCSET_NOT_SPACES);
237
- if (url.slice(-1) === ',') {
238
- url = absoluteToDoc(doc, url.substring(0, url.length - 1));
239
- output.push(url);
240
- }
241
- else {
242
- var descriptorsStr = '';
243
- url = absoluteToDoc(doc, url);
244
- var inParens = false;
245
- while (true) {
246
- var c = attributeValue.charAt(pos);
247
- if (c === '') {
248
- output.push((url + descriptorsStr).trim());
249
- break;
250
- }
251
- else if (!inParens) {
252
- if (c === ',') {
253
- pos += 1;
254
- output.push((url + descriptorsStr).trim());
255
- break;
256
- }
257
- else if (c === '(') {
258
- inParens = true;
259
- }
260
- }
261
- else {
262
- if (c === ')') {
263
- inParens = false;
264
- }
265
- }
266
- descriptorsStr += c;
267
- pos += 1;
268
- }
269
- }
270
- }
271
- return output.join(', ');
272
- }
273
- function absoluteToDoc(doc, attributeValue) {
274
- if (!attributeValue || attributeValue.trim() === '') {
275
- return attributeValue;
276
- }
277
- var a = doc.createElement('a');
278
- a.href = attributeValue;
279
- return a.href;
280
- }
281
- function isSVGElement(el) {
282
- return Boolean(el.tagName === 'svg' || el.ownerSVGElement);
283
- }
284
- function getHref() {
285
- var a = document.createElement('a');
286
- a.href = '';
287
- return a.href;
288
- }
289
- function transformAttribute(doc, tagName, name, value) {
290
- if (name === 'src' || (name === 'href' && value)) {
291
- return absoluteToDoc(doc, value);
292
- }
293
- else if (name === 'xlink:href' && value && value[0] !== '#') {
294
- return absoluteToDoc(doc, value);
295
- }
296
- else if (name === 'background' &&
297
- value &&
298
- (tagName === 'table' || tagName === 'td' || tagName === 'th')) {
299
- return absoluteToDoc(doc, value);
300
- }
301
- else if (name === 'srcset' && value) {
302
- return getAbsoluteSrcsetString(doc, value);
303
- }
304
- else if (name === 'style' && value) {
305
- return absoluteToStylesheet(value, getHref());
306
- }
307
- else if (tagName === 'object' && name === 'data' && value) {
308
- return absoluteToDoc(doc, value);
309
- }
310
- else {
311
- return value;
312
- }
313
- }
314
- function _isBlockedElement(element, blockClass, blockSelector) {
315
- if (typeof blockClass === 'string') {
316
- if (element.classList.contains(blockClass)) {
317
- return true;
318
- }
319
- }
320
- else {
321
- for (var eIndex = element.classList.length; eIndex--;) {
322
- var className = element.classList[eIndex];
323
- if (blockClass.test(className)) {
324
- return true;
325
- }
326
- }
327
- }
328
- if (blockSelector) {
329
- return element.matches(blockSelector);
330
- }
331
- return false;
332
- }
333
- function classMatchesRegex(node, regex, checkAncestors) {
334
- if (!node)
335
- return false;
336
- if (node.nodeType !== node.ELEMENT_NODE) {
337
- if (!checkAncestors)
338
- return false;
339
- return classMatchesRegex(node.parentNode, regex, checkAncestors);
340
- }
341
- for (var eIndex = node.classList.length; eIndex--;) {
342
- var className = node.classList[eIndex];
343
- if (regex.test(className)) {
344
- return true;
345
- }
346
- }
347
- if (!checkAncestors)
348
- return false;
349
- return classMatchesRegex(node.parentNode, regex, checkAncestors);
350
- }
351
- function needMaskingText(node, maskTextClass, maskTextSelector) {
352
- var el = node.nodeType === node.ELEMENT_NODE
353
- ? node
354
- : node.parentElement;
355
- if (el === null)
356
- return false;
357
- if (typeof maskTextClass === 'string') {
358
- if (el.classList.contains(maskTextClass))
359
- return true;
360
- if (el.closest("." + maskTextClass))
361
- return true;
362
- }
363
- else {
364
- if (classMatchesRegex(el, maskTextClass, true))
365
- return true;
366
- }
367
- if (maskTextSelector) {
368
- if (el.matches(maskTextSelector))
369
- return true;
370
- if (el.closest(maskTextSelector))
371
- return true;
372
- }
373
- return false;
374
- }
375
- function onceIframeLoaded(iframeEl, listener, iframeLoadTimeout) {
376
- var win = iframeEl.contentWindow;
377
- if (!win) {
378
- return;
379
- }
380
- var fired = false;
381
- var readyState;
382
- try {
383
- readyState = win.document.readyState;
384
- }
385
- catch (error) {
386
- return;
387
- }
388
- if (readyState !== 'complete') {
389
- var timer_1 = setTimeout(function () {
390
- if (!fired) {
391
- listener();
392
- fired = true;
393
- }
394
- }, iframeLoadTimeout);
395
- iframeEl.addEventListener('load', function () {
396
- clearTimeout(timer_1);
397
- fired = true;
398
- listener();
399
- });
400
- return;
401
- }
402
- var blankUrl = 'about:blank';
403
- if (win.location.href !== blankUrl ||
404
- iframeEl.src === blankUrl ||
405
- iframeEl.src === '') {
406
- setTimeout(listener, 0);
407
- return;
408
- }
409
- iframeEl.addEventListener('load', listener);
410
- }
411
- function isStylesheetLoaded(link) {
412
- if (!link.getAttribute('href'))
413
- return true;
414
- return link.sheet !== null;
415
- }
416
- function onceStylesheetLoaded(link, listener, iframeLoadTimeout) {
417
- var fired = false;
418
- var styleSheetLoaded;
419
- try {
420
- styleSheetLoaded = link.sheet;
421
- }
422
- catch (error) {
423
- return;
424
- }
425
- if (styleSheetLoaded)
426
- return;
427
- var timer = setTimeout(function () {
428
- if (!fired) {
429
- listener();
430
- fired = true;
431
- }
432
- }, iframeLoadTimeout);
433
- link.addEventListener('load', function () {
434
- clearTimeout(timer);
435
- fired = true;
436
- listener();
437
- });
438
- }
439
- function serializeNode(n, options) {
440
- var doc = options.doc, mirror = options.mirror, blockClass = options.blockClass, blockSelector = options.blockSelector, maskTextClass = options.maskTextClass, maskTextSelector = options.maskTextSelector, inlineStylesheet = options.inlineStylesheet, _a = options.maskInputOptions, maskInputOptions = _a === void 0 ? {} : _a, maskTextFn = options.maskTextFn, maskInputFn = options.maskInputFn, _b = options.dataURLOptions, dataURLOptions = _b === void 0 ? {} : _b, inlineImages = options.inlineImages, recordCanvas = options.recordCanvas, keepIframeSrcFn = options.keepIframeSrcFn, _c = options.newlyAddedElement, newlyAddedElement = _c === void 0 ? false : _c, enableStrictPrivacy = options.enableStrictPrivacy;
441
- var rootId = getRootId(doc, mirror);
442
- switch (n.nodeType) {
443
- case n.DOCUMENT_NODE:
444
- if (n.compatMode !== 'CSS1Compat') {
445
- return {
446
- type: NodeType$2.Document,
447
- childNodes: [],
448
- compatMode: n.compatMode,
449
- rootId: rootId
450
- };
451
- }
452
- else {
453
- return {
454
- type: NodeType$2.Document,
455
- childNodes: [],
456
- rootId: rootId
457
- };
458
- }
459
- case n.DOCUMENT_TYPE_NODE:
460
- return {
461
- type: NodeType$2.DocumentType,
462
- name: n.name,
463
- publicId: n.publicId,
464
- systemId: n.systemId,
465
- rootId: rootId
466
- };
467
- case n.ELEMENT_NODE:
468
- return serializeElementNode(n, {
469
- doc: doc,
470
- blockClass: blockClass,
471
- blockSelector: blockSelector,
472
- inlineStylesheet: inlineStylesheet,
473
- maskInputOptions: maskInputOptions,
474
- maskInputFn: maskInputFn,
475
- dataURLOptions: dataURLOptions,
476
- inlineImages: inlineImages,
477
- recordCanvas: recordCanvas,
478
- keepIframeSrcFn: keepIframeSrcFn,
479
- newlyAddedElement: newlyAddedElement,
480
- enableStrictPrivacy: enableStrictPrivacy,
481
- rootId: rootId
482
- });
483
- case n.TEXT_NODE:
484
- return serializeTextNode(n, {
485
- maskTextClass: maskTextClass,
486
- maskTextSelector: maskTextSelector,
487
- maskTextFn: maskTextFn,
488
- enableStrictPrivacy: enableStrictPrivacy,
489
- rootId: rootId
490
- });
491
- case n.CDATA_SECTION_NODE:
492
- return {
493
- type: NodeType$2.CDATA,
494
- textContent: '',
495
- rootId: rootId
496
- };
497
- case n.COMMENT_NODE:
498
- return {
499
- type: NodeType$2.Comment,
500
- textContent: n.textContent || '',
501
- rootId: rootId
502
- };
503
- default:
504
- return false;
505
- }
506
- }
507
- function getRootId(doc, mirror) {
508
- if (!mirror.hasNode(doc))
509
- return undefined;
510
- var docId = mirror.getId(doc);
511
- return docId === 1 ? undefined : docId;
512
- }
513
- function serializeTextNode(n, options) {
514
- var _a;
515
- var maskTextClass = options.maskTextClass, maskTextSelector = options.maskTextSelector, maskTextFn = options.maskTextFn, enableStrictPrivacy = options.enableStrictPrivacy, rootId = options.rootId;
516
- var parentTagName = n.parentNode && n.parentNode.tagName;
517
- var textContent = n.textContent;
518
- var isStyle = parentTagName === 'STYLE' ? true : undefined;
519
- var isScript = parentTagName === 'SCRIPT' ? true : undefined;
520
- var textContentHandled = false;
521
- if (isStyle && textContent) {
522
- try {
523
- if (n.nextSibling || n.previousSibling) {
524
- }
525
- else if ((_a = n.parentNode.sheet) === null || _a === void 0 ? void 0 : _a.cssRules) {
526
- textContent = stringifyStyleSheet(n.parentNode.sheet);
527
- }
528
- }
529
- catch (err) {
530
- console.warn("Cannot get CSS styles from text's parentNode. Error: " + err, n);
531
- }
532
- textContent = absoluteToStylesheet(textContent, getHref());
533
- textContentHandled = true;
534
- }
535
- if (isScript) {
536
- textContent = 'SCRIPT_PLACEHOLDER';
537
- textContentHandled = true;
538
- }
539
- else if (parentTagName === 'NOSCRIPT') {
540
- textContent = '';
541
- textContentHandled = true;
542
- }
543
- if (!isStyle &&
544
- !isScript &&
545
- textContent &&
546
- needMaskingText(n, maskTextClass, maskTextSelector)) {
547
- textContent = maskTextFn
548
- ? maskTextFn(textContent)
549
- : textContent.replace(/[\S]/g, '*');
550
- }
551
- if (enableStrictPrivacy && !textContentHandled && parentTagName) {
552
- var IGNORE_TAG_NAMES = new Set([
553
- 'HEAD',
554
- 'TITLE',
555
- 'STYLE',
556
- 'SCRIPT',
557
- 'HTML',
558
- 'BODY',
559
- 'NOSCRIPT',
560
- ]);
561
- if (!IGNORE_TAG_NAMES.has(parentTagName) && textContent) {
562
- textContent = obfuscateText(textContent);
563
- }
564
- }
565
- return {
566
- type: NodeType$2.Text,
567
- textContent: textContent || '',
568
- isStyle: isStyle,
569
- rootId: rootId
570
- };
571
- }
572
- function serializeElementNode(n, options) {
573
- var doc = options.doc, blockClass = options.blockClass, blockSelector = options.blockSelector, inlineStylesheet = options.inlineStylesheet, _a = options.maskInputOptions, maskInputOptions = _a === void 0 ? {} : _a, maskInputFn = options.maskInputFn, _b = options.dataURLOptions, dataURLOptions = _b === void 0 ? {} : _b, inlineImages = options.inlineImages, recordCanvas = options.recordCanvas, keepIframeSrcFn = options.keepIframeSrcFn, _c = options.newlyAddedElement, newlyAddedElement = _c === void 0 ? false : _c, enableStrictPrivacy = options.enableStrictPrivacy, rootId = options.rootId;
574
- var needBlock = _isBlockedElement(n, blockClass, blockSelector);
575
- var tagName = getValidTagName$1(n);
576
- var attributes = {};
577
- var len = n.attributes.length;
578
- for (var i = 0; i < len; i++) {
579
- var attr = n.attributes[i];
580
- attributes[attr.name] = transformAttribute(doc, tagName, attr.name, attr.value);
581
- }
582
- if (tagName === 'link' && inlineStylesheet) {
583
- var stylesheet = Array.from(doc.styleSheets).find(function (s) {
584
- return s.href === n.href;
585
- });
586
- var cssText = null;
587
- if (stylesheet) {
588
- cssText = getCssRulesString(stylesheet);
589
- }
590
- if (cssText) {
591
- delete attributes.rel;
592
- delete attributes.href;
593
- attributes._cssText = absoluteToStylesheet(cssText, stylesheet.href);
594
- }
595
- }
596
- if (tagName === 'style' &&
597
- n.sheet &&
598
- !(n.innerText || n.textContent || '').trim().length) {
599
- var cssText = getCssRulesString(n.sheet);
600
- if (cssText) {
601
- attributes._cssText = absoluteToStylesheet(cssText, getHref());
602
- }
603
- }
604
- if (tagName === 'input' || tagName === 'textarea' || tagName === 'select') {
605
- var value = n.value;
606
- if (attributes.type !== 'radio' &&
607
- attributes.type !== 'checkbox' &&
608
- attributes.type !== 'submit' &&
609
- attributes.type !== 'button' &&
610
- value) {
611
- attributes.value = maskInputValue({
612
- type: attributes.type,
613
- tagName: tagName,
614
- value: value,
615
- maskInputOptions: maskInputOptions,
616
- maskInputFn: maskInputFn
617
- });
618
- }
619
- else if (n.checked) {
620
- attributes.checked = n.checked;
621
- }
622
- }
623
- if (tagName === 'option') {
624
- if (n.selected && !maskInputOptions['select']) {
625
- attributes.selected = true;
626
- }
627
- else {
628
- delete attributes.selected;
629
- }
630
- }
631
- if (tagName === 'canvas' && recordCanvas) {
632
- if (n.__context === '2d') {
633
- if (!is2DCanvasBlank(n)) {
634
- attributes.rr_dataURL = n.toDataURL(dataURLOptions.type, dataURLOptions.quality);
635
- }
636
- }
637
- else if (!('__context' in n)) {
638
- var canvasDataURL = n.toDataURL(dataURLOptions.type, dataURLOptions.quality);
639
- var blankCanvas = document.createElement('canvas');
640
- blankCanvas.width = n.width;
641
- blankCanvas.height = n.height;
642
- var blankCanvasDataURL = blankCanvas.toDataURL(dataURLOptions.type, dataURLOptions.quality);
643
- if (canvasDataURL !== blankCanvasDataURL) {
644
- attributes.rr_dataURL = canvasDataURL;
645
- }
646
- }
647
- }
648
- if (tagName === 'img' && inlineImages) {
649
- if (!canvasService) {
650
- canvasService = doc.createElement('canvas');
651
- canvasCtx = canvasService.getContext('2d');
652
- }
653
- var image_1 = n;
654
- var oldValue_1 = image_1.crossOrigin;
655
- image_1.crossOrigin = 'anonymous';
656
- var recordInlineImage = function () {
657
- try {
658
- canvasService.width = image_1.naturalWidth;
659
- canvasService.height = image_1.naturalHeight;
660
- canvasCtx.drawImage(image_1, 0, 0);
661
- attributes.rr_dataURL = canvasService.toDataURL(dataURLOptions.type, dataURLOptions.quality);
662
- }
663
- catch (err) {
664
- console.warn("Cannot inline img src=" + image_1.currentSrc + "! Error: " + err);
665
- }
666
- oldValue_1
667
- ? (attributes.crossOrigin = oldValue_1)
668
- : image_1.removeAttribute('crossorigin');
669
- };
670
- if (image_1.complete && image_1.naturalWidth !== 0)
671
- recordInlineImage();
672
- else
673
- image_1.onload = recordInlineImage;
674
- }
675
- if (tagName === 'audio' || tagName === 'video') {
676
- attributes.rr_mediaState = n.paused
677
- ? 'paused'
678
- : 'played';
679
- attributes.rr_mediaCurrentTime = n.currentTime;
680
- }
681
- if (!newlyAddedElement) {
682
- if (n.scrollLeft) {
683
- attributes.rr_scrollLeft = n.scrollLeft;
684
- }
685
- if (n.scrollTop) {
686
- attributes.rr_scrollTop = n.scrollTop;
687
- }
688
- }
689
- if (needBlock || (tagName === 'img' && enableStrictPrivacy)) {
690
- var _d = n.getBoundingClientRect(), width = _d.width, height = _d.height;
691
- attributes = {
692
- "class": attributes["class"],
693
- rr_width: width + "px",
694
- rr_height: height + "px"
695
- };
696
- needBlock = true;
697
- }
698
- if (tagName === 'iframe' && !keepIframeSrcFn(attributes.src)) {
699
- if (!n.contentDocument) {
700
- attributes.rr_src = attributes.src;
701
- }
702
- delete attributes.src;
703
- }
704
- return {
705
- type: NodeType$2.Element,
706
- tagName: tagName,
707
- attributes: attributes,
708
- childNodes: [],
709
- isSVG: isSVGElement(n) || undefined,
710
- needBlock: needBlock,
711
- rootId: rootId
712
- };
713
- }
714
- function lowerIfExists(maybeAttr) {
715
- if (maybeAttr === undefined) {
716
- return '';
717
- }
718
- else {
719
- return maybeAttr.toLowerCase();
720
- }
721
- }
722
- function slimDOMExcluded(sn, slimDOMOptions) {
723
- if (slimDOMOptions.comment && sn.type === NodeType$2.Comment) {
724
- return true;
725
- }
726
- else if (sn.type === NodeType$2.Element) {
727
- if (slimDOMOptions.script &&
728
- (sn.tagName === 'script' ||
729
- (sn.tagName === 'link' &&
730
- sn.attributes.rel === 'preload' &&
731
- sn.attributes.as === 'script') ||
732
- (sn.tagName === 'link' &&
733
- sn.attributes.rel === 'prefetch' &&
734
- typeof sn.attributes.href === 'string' &&
735
- sn.attributes.href.endsWith('.js')))) {
736
- return true;
737
- }
738
- else if (slimDOMOptions.headFavicon &&
739
- ((sn.tagName === 'link' && sn.attributes.rel === 'shortcut icon') ||
740
- (sn.tagName === 'meta' &&
741
- (lowerIfExists(sn.attributes.name).match(/^msapplication-tile(image|color)$/) ||
742
- lowerIfExists(sn.attributes.name) === 'application-name' ||
743
- lowerIfExists(sn.attributes.rel) === 'icon' ||
744
- lowerIfExists(sn.attributes.rel) === 'apple-touch-icon' ||
745
- lowerIfExists(sn.attributes.rel) === 'shortcut icon')))) {
746
- return true;
747
- }
748
- else if (sn.tagName === 'meta') {
749
- if (slimDOMOptions.headMetaDescKeywords &&
750
- lowerIfExists(sn.attributes.name).match(/^description|keywords$/)) {
751
- return true;
752
- }
753
- else if (slimDOMOptions.headMetaSocial &&
754
- (lowerIfExists(sn.attributes.property).match(/^(og|twitter|fb):/) ||
755
- lowerIfExists(sn.attributes.name).match(/^(og|twitter):/) ||
756
- lowerIfExists(sn.attributes.name) === 'pinterest')) {
757
- return true;
758
- }
759
- else if (slimDOMOptions.headMetaRobots &&
760
- (lowerIfExists(sn.attributes.name) === 'robots' ||
761
- lowerIfExists(sn.attributes.name) === 'googlebot' ||
762
- lowerIfExists(sn.attributes.name) === 'bingbot')) {
763
- return true;
764
- }
765
- else if (slimDOMOptions.headMetaHttpEquiv &&
766
- sn.attributes['http-equiv'] !== undefined) {
767
- return true;
768
- }
769
- else if (slimDOMOptions.headMetaAuthorship &&
770
- (lowerIfExists(sn.attributes.name) === 'author' ||
771
- lowerIfExists(sn.attributes.name) === 'generator' ||
772
- lowerIfExists(sn.attributes.name) === 'framework' ||
773
- lowerIfExists(sn.attributes.name) === 'publisher' ||
774
- lowerIfExists(sn.attributes.name) === 'progid' ||
775
- lowerIfExists(sn.attributes.property).match(/^article:/) ||
776
- lowerIfExists(sn.attributes.property).match(/^product:/))) {
777
- return true;
778
- }
779
- else if (slimDOMOptions.headMetaVerification &&
780
- (lowerIfExists(sn.attributes.name) === 'google-site-verification' ||
781
- lowerIfExists(sn.attributes.name) === 'yandex-verification' ||
782
- lowerIfExists(sn.attributes.name) === 'csrf-token' ||
783
- lowerIfExists(sn.attributes.name) === 'p:domain_verify' ||
784
- lowerIfExists(sn.attributes.name) === 'verify-v1' ||
785
- lowerIfExists(sn.attributes.name) === 'verification' ||
786
- lowerIfExists(sn.attributes.name) === 'shopify-checkout-api-token')) {
787
- return true;
788
- }
789
- }
790
- }
791
- return false;
792
- }
793
- function serializeNodeWithId(n, options) {
794
- var doc = options.doc, mirror = options.mirror, blockClass = options.blockClass, blockSelector = options.blockSelector, maskTextClass = options.maskTextClass, maskTextSelector = options.maskTextSelector, _a = options.skipChild, skipChild = _a === void 0 ? false : _a, _b = options.inlineStylesheet, inlineStylesheet = _b === void 0 ? true : _b, _c = options.maskInputOptions, maskInputOptions = _c === void 0 ? {} : _c, maskTextFn = options.maskTextFn, maskInputFn = options.maskInputFn, slimDOMOptions = options.slimDOMOptions, _d = options.dataURLOptions, dataURLOptions = _d === void 0 ? {} : _d, _e = options.inlineImages, inlineImages = _e === void 0 ? false : _e, _f = options.recordCanvas, recordCanvas = _f === void 0 ? false : _f, onSerialize = options.onSerialize, onIframeLoad = options.onIframeLoad, _g = options.iframeLoadTimeout, iframeLoadTimeout = _g === void 0 ? 5000 : _g, onStylesheetLoad = options.onStylesheetLoad, _h = options.stylesheetLoadTimeout, stylesheetLoadTimeout = _h === void 0 ? 5000 : _h, _j = options.keepIframeSrcFn, keepIframeSrcFn = _j === void 0 ? function () { return false; } : _j, _k = options.newlyAddedElement, newlyAddedElement = _k === void 0 ? false : _k, enableStrictPrivacy = options.enableStrictPrivacy;
795
- var _l = options.preserveWhiteSpace, preserveWhiteSpace = _l === void 0 ? true : _l;
796
- var _serializedNode = serializeNode(n, {
797
- doc: doc,
798
- mirror: mirror,
799
- blockClass: blockClass,
800
- blockSelector: blockSelector,
801
- maskTextClass: maskTextClass,
802
- maskTextSelector: maskTextSelector,
803
- inlineStylesheet: inlineStylesheet,
804
- maskInputOptions: maskInputOptions,
805
- maskTextFn: maskTextFn,
806
- maskInputFn: maskInputFn,
807
- dataURLOptions: dataURLOptions,
808
- inlineImages: inlineImages,
809
- recordCanvas: recordCanvas,
810
- keepIframeSrcFn: keepIframeSrcFn,
811
- newlyAddedElement: newlyAddedElement,
812
- enableStrictPrivacy: enableStrictPrivacy
813
- });
814
- if (!_serializedNode) {
815
- console.warn(n, 'not serialized');
816
- return null;
817
- }
818
- var id;
819
- if (mirror.hasNode(n)) {
820
- id = mirror.getId(n);
821
- }
822
- else if (slimDOMExcluded(_serializedNode, slimDOMOptions) ||
823
- (!preserveWhiteSpace &&
824
- _serializedNode.type === NodeType$2.Text &&
825
- !_serializedNode.isStyle &&
826
- !_serializedNode.textContent.replace(/^\s+|\s+$/gm, '').length)) {
827
- id = IGNORED_NODE;
828
- }
829
- else {
830
- id = genId();
831
- }
832
- if (id === IGNORED_NODE) {
833
- return null;
834
- }
835
- var serializedNode = Object.assign(_serializedNode, { id: id });
836
- mirror.add(n, serializedNode);
837
- if (onSerialize) {
838
- onSerialize(n);
839
- }
840
- var recordChild = !skipChild;
841
- if (serializedNode.type === NodeType$2.Element) {
842
- recordChild = recordChild && !serializedNode.needBlock;
843
- if (serializedNode.needBlock && serializedNode.tagName === 'img') {
844
- var clone = n.cloneNode();
845
- clone.src = '';
846
- mirror.add(clone, serializedNode);
847
- }
848
- delete serializedNode.needBlock;
849
- if (n.shadowRoot)
850
- serializedNode.isShadowHost = true;
851
- }
852
- if ((serializedNode.type === NodeType$2.Document ||
853
- serializedNode.type === NodeType$2.Element) &&
854
- recordChild) {
855
- if (slimDOMOptions.headWhitespace &&
856
- serializedNode.type === NodeType$2.Element &&
857
- serializedNode.tagName === 'head') {
858
- preserveWhiteSpace = false;
859
- }
860
- var bypassOptions = {
861
- doc: doc,
862
- mirror: mirror,
863
- blockClass: blockClass,
864
- blockSelector: blockSelector,
865
- maskTextClass: maskTextClass,
866
- maskTextSelector: maskTextSelector,
867
- skipChild: skipChild,
868
- inlineStylesheet: inlineStylesheet,
869
- maskInputOptions: maskInputOptions,
870
- maskTextFn: maskTextFn,
871
- maskInputFn: maskInputFn,
872
- slimDOMOptions: slimDOMOptions,
873
- dataURLOptions: dataURLOptions,
874
- inlineImages: inlineImages,
875
- recordCanvas: recordCanvas,
876
- preserveWhiteSpace: preserveWhiteSpace,
877
- onSerialize: onSerialize,
878
- onIframeLoad: onIframeLoad,
879
- iframeLoadTimeout: iframeLoadTimeout,
880
- onStylesheetLoad: onStylesheetLoad,
881
- stylesheetLoadTimeout: stylesheetLoadTimeout,
882
- keepIframeSrcFn: keepIframeSrcFn,
883
- enableStrictPrivacy: enableStrictPrivacy
884
- };
885
- for (var _i = 0, _m = Array.from(n.childNodes); _i < _m.length; _i++) {
886
- var childN = _m[_i];
887
- var serializedChildNode = serializeNodeWithId(childN, bypassOptions);
888
- if (serializedChildNode) {
889
- serializedNode.childNodes.push(serializedChildNode);
890
- }
891
- }
892
- if (isElement(n) && n.shadowRoot) {
893
- for (var _o = 0, _p = Array.from(n.shadowRoot.childNodes); _o < _p.length; _o++) {
894
- var childN = _p[_o];
895
- var serializedChildNode = serializeNodeWithId(childN, bypassOptions);
896
- if (serializedChildNode) {
897
- serializedChildNode.isShadow = true;
898
- serializedNode.childNodes.push(serializedChildNode);
899
- }
900
- }
901
- }
902
- }
903
- if (n.parentNode && isShadowRoot(n.parentNode)) {
904
- serializedNode.isShadow = true;
905
- }
906
- if (serializedNode.type === NodeType$2.Element &&
907
- serializedNode.tagName === 'iframe') {
908
- onceIframeLoaded(n, function () {
909
- var iframeDoc = n.contentDocument;
910
- if (iframeDoc && onIframeLoad) {
911
- var serializedIframeNode = serializeNodeWithId(iframeDoc, {
912
- doc: iframeDoc,
913
- mirror: mirror,
914
- blockClass: blockClass,
915
- blockSelector: blockSelector,
916
- maskTextClass: maskTextClass,
917
- maskTextSelector: maskTextSelector,
918
- skipChild: false,
919
- inlineStylesheet: inlineStylesheet,
920
- maskInputOptions: maskInputOptions,
921
- maskTextFn: maskTextFn,
922
- maskInputFn: maskInputFn,
923
- slimDOMOptions: slimDOMOptions,
924
- dataURLOptions: dataURLOptions,
925
- inlineImages: inlineImages,
926
- recordCanvas: recordCanvas,
927
- preserveWhiteSpace: preserveWhiteSpace,
928
- onSerialize: onSerialize,
929
- onIframeLoad: onIframeLoad,
930
- iframeLoadTimeout: iframeLoadTimeout,
931
- onStylesheetLoad: onStylesheetLoad,
932
- stylesheetLoadTimeout: stylesheetLoadTimeout,
933
- keepIframeSrcFn: keepIframeSrcFn,
934
- enableStrictPrivacy: enableStrictPrivacy
935
- });
936
- if (serializedIframeNode) {
937
- onIframeLoad(n, serializedIframeNode);
938
- }
939
- }
940
- }, iframeLoadTimeout);
941
- }
942
- if (serializedNode.type === NodeType$2.Element &&
943
- serializedNode.tagName === 'link' &&
944
- serializedNode.attributes.rel === 'stylesheet') {
945
- onceStylesheetLoaded(n, function () {
946
- if (onStylesheetLoad) {
947
- var serializedLinkNode = serializeNodeWithId(n, {
948
- doc: doc,
949
- mirror: mirror,
950
- blockClass: blockClass,
951
- blockSelector: blockSelector,
952
- maskTextClass: maskTextClass,
953
- maskTextSelector: maskTextSelector,
954
- skipChild: false,
955
- inlineStylesheet: inlineStylesheet,
956
- maskInputOptions: maskInputOptions,
957
- maskTextFn: maskTextFn,
958
- maskInputFn: maskInputFn,
959
- slimDOMOptions: slimDOMOptions,
960
- dataURLOptions: dataURLOptions,
961
- inlineImages: inlineImages,
962
- recordCanvas: recordCanvas,
963
- preserveWhiteSpace: preserveWhiteSpace,
964
- onSerialize: onSerialize,
965
- onIframeLoad: onIframeLoad,
966
- iframeLoadTimeout: iframeLoadTimeout,
967
- onStylesheetLoad: onStylesheetLoad,
968
- stylesheetLoadTimeout: stylesheetLoadTimeout,
969
- keepIframeSrcFn: keepIframeSrcFn,
970
- enableStrictPrivacy: enableStrictPrivacy
971
- });
972
- if (serializedLinkNode) {
973
- onStylesheetLoad(n, serializedLinkNode);
974
- }
975
- }
976
- }, stylesheetLoadTimeout);
977
- if (isStylesheetLoaded(n) === false)
978
- return null;
979
- }
980
- return serializedNode;
981
- }
982
- function snapshot(n, options) {
983
- var _a = options || {}, _b = _a.mirror, mirror = _b === void 0 ? new Mirror$2() : _b, _c = _a.blockClass, blockClass = _c === void 0 ? 'highlight-block' : _c, _d = _a.blockSelector, blockSelector = _d === void 0 ? null : _d, _e = _a.maskTextClass, maskTextClass = _e === void 0 ? 'highlight-mask' : _e, _f = _a.maskTextSelector, maskTextSelector = _f === void 0 ? null : _f, _g = _a.inlineStylesheet, inlineStylesheet = _g === void 0 ? true : _g, _h = _a.inlineImages, inlineImages = _h === void 0 ? false : _h, _j = _a.recordCanvas, recordCanvas = _j === void 0 ? false : _j, _k = _a.maskAllInputs, maskAllInputs = _k === void 0 ? false : _k, maskTextFn = _a.maskTextFn, maskInputFn = _a.maskInputFn, _l = _a.slimDOM, slimDOM = _l === void 0 ? false : _l, dataURLOptions = _a.dataURLOptions, preserveWhiteSpace = _a.preserveWhiteSpace, onSerialize = _a.onSerialize, onIframeLoad = _a.onIframeLoad, iframeLoadTimeout = _a.iframeLoadTimeout, onStylesheetLoad = _a.onStylesheetLoad, stylesheetLoadTimeout = _a.stylesheetLoadTimeout, _m = _a.keepIframeSrcFn, keepIframeSrcFn = _m === void 0 ? function () { return false; } : _m, _o = _a.enableStrictPrivacy, enableStrictPrivacy = _o === void 0 ? false : _o;
984
- var maskInputOptions = maskAllInputs === true
985
- ? {
986
- color: true,
987
- date: true,
988
- 'datetime-local': true,
989
- email: true,
990
- month: true,
991
- number: true,
992
- range: true,
993
- search: true,
994
- tel: true,
995
- text: true,
996
- time: true,
997
- url: true,
998
- week: true,
999
- textarea: true,
1000
- select: true,
1001
- password: true
1002
- }
1003
- : maskAllInputs === false
1004
- ? {
1005
- password: true
1006
- }
1007
- : maskAllInputs;
1008
- var slimDOMOptions = slimDOM === true || slimDOM === 'all'
1009
- ?
1010
- {
1011
- script: true,
1012
- comment: true,
1013
- headFavicon: true,
1014
- headWhitespace: true,
1015
- headMetaDescKeywords: slimDOM === 'all',
1016
- headMetaSocial: true,
1017
- headMetaRobots: true,
1018
- headMetaHttpEquiv: true,
1019
- headMetaAuthorship: true,
1020
- headMetaVerification: true
1021
- }
1022
- : slimDOM === false
1023
- ? {}
1024
- : slimDOM;
1025
- return serializeNodeWithId(n, {
1026
- doc: n,
1027
- mirror: mirror,
1028
- blockClass: blockClass,
1029
- blockSelector: blockSelector,
1030
- maskTextClass: maskTextClass,
1031
- maskTextSelector: maskTextSelector,
1032
- skipChild: false,
1033
- inlineStylesheet: inlineStylesheet,
1034
- maskInputOptions: maskInputOptions,
1035
- maskTextFn: maskTextFn,
1036
- maskInputFn: maskInputFn,
1037
- slimDOMOptions: slimDOMOptions,
1038
- dataURLOptions: dataURLOptions,
1039
- inlineImages: inlineImages,
1040
- recordCanvas: recordCanvas,
1041
- preserveWhiteSpace: preserveWhiteSpace,
1042
- onSerialize: onSerialize,
1043
- onIframeLoad: onIframeLoad,
1044
- iframeLoadTimeout: iframeLoadTimeout,
1045
- onStylesheetLoad: onStylesheetLoad,
1046
- stylesheetLoadTimeout: stylesheetLoadTimeout,
1047
- keepIframeSrcFn: keepIframeSrcFn,
1048
- newlyAddedElement: false,
1049
- enableStrictPrivacy: enableStrictPrivacy
1050
- });
15
+ function isElement(n) {
16
+ return n.nodeType === n.ELEMENT_NODE;
17
+ }
18
+ function isShadowRoot(n) {
19
+ var host = n === null || n === void 0 ? void 0 : n.host;
20
+ return Boolean((host === null || host === void 0 ? void 0 : host.shadowRoot) === n);
21
+ }
22
+ var Mirror$2 = (function () {
23
+ function Mirror() {
24
+ this.idNodeMap = new Map();
25
+ this.nodeMetaMap = new WeakMap();
26
+ }
27
+ Mirror.prototype.getId = function (n) {
28
+ var _a;
29
+ if (!n)
30
+ return -1;
31
+ var id = (_a = this.getMeta(n)) === null || _a === void 0 ? void 0 : _a.id;
32
+ return id !== null && id !== void 0 ? id : -1;
33
+ };
34
+ Mirror.prototype.getNode = function (id) {
35
+ return this.idNodeMap.get(id) || null;
36
+ };
37
+ Mirror.prototype.getIds = function () {
38
+ return Array.from(this.idNodeMap.keys());
39
+ };
40
+ Mirror.prototype.getMeta = function (n) {
41
+ return this.nodeMetaMap.get(n) || null;
42
+ };
43
+ Mirror.prototype.removeNodeFromMap = function (n) {
44
+ var _this = this;
45
+ var id = this.getId(n);
46
+ this.idNodeMap["delete"](id);
47
+ if (n.childNodes) {
48
+ n.childNodes.forEach(function (childNode) {
49
+ return _this.removeNodeFromMap(childNode);
50
+ });
51
+ }
52
+ };
53
+ Mirror.prototype.has = function (id) {
54
+ return this.idNodeMap.has(id);
55
+ };
56
+ Mirror.prototype.hasNode = function (node) {
57
+ return this.nodeMetaMap.has(node);
58
+ };
59
+ Mirror.prototype.add = function (n, meta) {
60
+ var id = meta.id;
61
+ this.idNodeMap.set(id, n);
62
+ this.nodeMetaMap.set(n, meta);
63
+ };
64
+ Mirror.prototype.replace = function (id, n) {
65
+ this.idNodeMap.set(id, n);
66
+ };
67
+ Mirror.prototype.reset = function () {
68
+ this.idNodeMap = new Map();
69
+ this.nodeMetaMap = new WeakMap();
70
+ };
71
+ return Mirror;
72
+ }());
73
+ function createMirror$2() {
74
+ return new Mirror$2();
75
+ }
76
+ function maskInputValue(_a) {
77
+ var maskInputOptions = _a.maskInputOptions, tagName = _a.tagName, type = _a.type, value = _a.value, maskInputFn = _a.maskInputFn;
78
+ var text = value || '';
79
+ if (maskInputOptions[tagName.toLowerCase()] ||
80
+ maskInputOptions[type]) {
81
+ if (maskInputFn) {
82
+ text = maskInputFn(text);
83
+ }
84
+ else {
85
+ text = '*'.repeat(text.length);
86
+ }
87
+ }
88
+ return text;
89
+ }
90
+ var ORIGINAL_ATTRIBUTE_NAME = '__rrweb_original__';
91
+ function is2DCanvasBlank(canvas) {
92
+ var ctx = canvas.getContext('2d');
93
+ if (!ctx)
94
+ return true;
95
+ var chunkSize = 50;
96
+ for (var x = 0; x < canvas.width; x += chunkSize) {
97
+ for (var y = 0; y < canvas.height; y += chunkSize) {
98
+ var getImageData = ctx.getImageData;
99
+ var originalGetImageData = ORIGINAL_ATTRIBUTE_NAME in getImageData
100
+ ? getImageData[ORIGINAL_ATTRIBUTE_NAME]
101
+ : getImageData;
102
+ var pixelBuffer = new Uint32Array(originalGetImageData.call(ctx, x, y, Math.min(chunkSize, canvas.width - x), Math.min(chunkSize, canvas.height - y)).data.buffer);
103
+ if (pixelBuffer.some(function (pixel) { return pixel !== 0; }))
104
+ return false;
105
+ }
106
+ }
107
+ return true;
108
+ }
109
+ function obfuscateText(text) {
110
+ text = text.replace(/[^ -~]+/g, '');
111
+ text =
112
+ (text === null || text === void 0 ? void 0 : text.split(' ').map(function (word) { return Math.random().toString(20).substr(2, word.length); }).join(' ')) || '';
113
+ return text;
1051
114
  }
1052
115
 
1053
- var commentre = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//g;
1054
- function parse(css, options) {
1055
- if (options === void 0) { options = {}; }
1056
- var lineno = 1;
1057
- var column = 1;
1058
- function updatePosition(str) {
1059
- var lines = str.match(/\n/g);
1060
- if (lines) {
1061
- lineno += lines.length;
1062
- }
1063
- var i = str.lastIndexOf('\n');
1064
- column = i === -1 ? column + str.length : str.length - i;
1065
- }
1066
- function position() {
1067
- var start = { line: lineno, column: column };
1068
- return function (node) {
1069
- node.position = new Position(start);
1070
- whitespace();
1071
- return node;
1072
- };
1073
- }
1074
- var Position = (function () {
1075
- function Position(start) {
1076
- this.start = start;
1077
- this.end = { line: lineno, column: column };
1078
- this.source = options.source;
1079
- }
1080
- return Position;
1081
- }());
1082
- Position.prototype.content = css;
1083
- var errorsList = [];
1084
- function error(msg) {
1085
- var err = new Error(options.source + ':' + lineno + ':' + column + ': ' + msg);
1086
- err.reason = msg;
1087
- err.filename = options.source;
1088
- err.line = lineno;
1089
- err.column = column;
1090
- err.source = css;
1091
- if (options.silent) {
1092
- errorsList.push(err);
1093
- }
1094
- else {
1095
- throw err;
1096
- }
1097
- }
1098
- function stylesheet() {
1099
- var rulesList = rules();
1100
- return {
1101
- type: 'stylesheet',
1102
- stylesheet: {
1103
- source: options.source,
1104
- rules: rulesList,
1105
- parsingErrors: errorsList
1106
- }
1107
- };
1108
- }
1109
- function open() {
1110
- return match(/^{\s*/);
1111
- }
1112
- function close() {
1113
- return match(/^}/);
1114
- }
1115
- function rules() {
1116
- var node;
1117
- var rules = [];
1118
- whitespace();
1119
- comments(rules);
1120
- while (css.length && css.charAt(0) !== '}' && (node = atrule() || rule())) {
1121
- if (node !== false) {
1122
- rules.push(node);
1123
- comments(rules);
1124
- }
1125
- }
1126
- return rules;
1127
- }
1128
- function match(re) {
1129
- var m = re.exec(css);
1130
- if (!m) {
1131
- return;
1132
- }
1133
- var str = m[0];
1134
- updatePosition(str);
1135
- css = css.slice(str.length);
1136
- return m;
1137
- }
1138
- function whitespace() {
1139
- match(/^\s*/);
1140
- }
1141
- function comments(rules) {
1142
- if (rules === void 0) { rules = []; }
1143
- var c;
1144
- while ((c = comment())) {
1145
- if (c !== false) {
1146
- rules.push(c);
1147
- }
1148
- c = comment();
1149
- }
1150
- return rules;
1151
- }
1152
- function comment() {
1153
- var pos = position();
1154
- if ('/' !== css.charAt(0) || '*' !== css.charAt(1)) {
1155
- return;
1156
- }
1157
- var i = 2;
1158
- while ('' !== css.charAt(i) &&
1159
- ('*' !== css.charAt(i) || '/' !== css.charAt(i + 1))) {
1160
- ++i;
1161
- }
1162
- i += 2;
1163
- if ('' === css.charAt(i - 1)) {
1164
- return error('End of comment missing');
1165
- }
1166
- var str = css.slice(2, i - 2);
1167
- column += 2;
1168
- updatePosition(str);
1169
- css = css.slice(i);
1170
- column += 2;
1171
- return pos({
1172
- type: 'comment',
1173
- comment: str
1174
- });
1175
- }
1176
- function selector() {
1177
- var m = match(/^([^{]+)/);
1178
- if (!m) {
1179
- return;
1180
- }
1181
- return trim(m[0])
1182
- .replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g, '')
1183
- .replace(/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'/g, function (m) {
1184
- return m.replace(/,/g, '\u200C');
1185
- })
1186
- .split(/\s*(?![^(]*\)),\s*/)
1187
- .map(function (s) {
1188
- return s.replace(/\u200C/g, ',');
1189
- });
1190
- }
1191
- function declaration() {
1192
- var pos = position();
1193
- var propMatch = match(/^(\*?[-#\/\*\\\w]+(\[[0-9a-z_-]+\])?)\s*/);
1194
- if (!propMatch) {
1195
- return;
1196
- }
1197
- var prop = trim(propMatch[0]);
1198
- if (!match(/^:\s*/)) {
1199
- return error("property missing ':'");
1200
- }
1201
- var val = match(/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^\)]*?\)|[^};])+)/);
1202
- var ret = pos({
1203
- type: 'declaration',
1204
- property: prop.replace(commentre, ''),
1205
- value: val ? trim(val[0]).replace(commentre, '') : ''
1206
- });
1207
- match(/^[;\s]*/);
1208
- return ret;
1209
- }
1210
- function declarations() {
1211
- var decls = [];
1212
- if (!open()) {
1213
- return error("missing '{'");
1214
- }
1215
- comments(decls);
1216
- var decl;
1217
- while ((decl = declaration())) {
1218
- if (decl !== false) {
1219
- decls.push(decl);
1220
- comments(decls);
1221
- }
1222
- decl = declaration();
1223
- }
1224
- if (!close()) {
1225
- return error("missing '}'");
1226
- }
1227
- return decls;
1228
- }
1229
- function keyframe() {
1230
- var m;
1231
- var vals = [];
1232
- var pos = position();
1233
- while ((m = match(/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/))) {
1234
- vals.push(m[1]);
1235
- match(/^,\s*/);
1236
- }
1237
- if (!vals.length) {
1238
- return;
1239
- }
1240
- return pos({
1241
- type: 'keyframe',
1242
- values: vals,
1243
- declarations: declarations()
1244
- });
1245
- }
1246
- function atkeyframes() {
1247
- var pos = position();
1248
- var m = match(/^@([-\w]+)?keyframes\s*/);
1249
- if (!m) {
1250
- return;
1251
- }
1252
- var vendor = m[1];
1253
- m = match(/^([-\w]+)\s*/);
1254
- if (!m) {
1255
- return error('@keyframes missing name');
1256
- }
1257
- var name = m[1];
1258
- if (!open()) {
1259
- return error("@keyframes missing '{'");
1260
- }
1261
- var frame;
1262
- var frames = comments();
1263
- while ((frame = keyframe())) {
1264
- frames.push(frame);
1265
- frames = frames.concat(comments());
1266
- }
1267
- if (!close()) {
1268
- return error("@keyframes missing '}'");
1269
- }
1270
- return pos({
1271
- type: 'keyframes',
1272
- name: name,
1273
- vendor: vendor,
1274
- keyframes: frames
1275
- });
1276
- }
1277
- function atsupports() {
1278
- var pos = position();
1279
- var m = match(/^@supports *([^{]+)/);
1280
- if (!m) {
1281
- return;
1282
- }
1283
- var supports = trim(m[1]);
1284
- if (!open()) {
1285
- return error("@supports missing '{'");
1286
- }
1287
- var style = comments().concat(rules());
1288
- if (!close()) {
1289
- return error("@supports missing '}'");
1290
- }
1291
- return pos({
1292
- type: 'supports',
1293
- supports: supports,
1294
- rules: style
1295
- });
1296
- }
1297
- function athost() {
1298
- var pos = position();
1299
- var m = match(/^@host\s*/);
1300
- if (!m) {
1301
- return;
1302
- }
1303
- if (!open()) {
1304
- return error("@host missing '{'");
1305
- }
1306
- var style = comments().concat(rules());
1307
- if (!close()) {
1308
- return error("@host missing '}'");
1309
- }
1310
- return pos({
1311
- type: 'host',
1312
- rules: style
1313
- });
1314
- }
1315
- function atmedia() {
1316
- var pos = position();
1317
- var m = match(/^@media *([^{]+)/);
1318
- if (!m) {
1319
- return;
1320
- }
1321
- var media = trim(m[1]);
1322
- if (!open()) {
1323
- return error("@media missing '{'");
1324
- }
1325
- var style = comments().concat(rules());
1326
- if (!close()) {
1327
- return error("@media missing '}'");
1328
- }
1329
- return pos({
1330
- type: 'media',
1331
- media: media,
1332
- rules: style
1333
- });
1334
- }
1335
- function atcustommedia() {
1336
- var pos = position();
1337
- var m = match(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/);
1338
- if (!m) {
1339
- return;
1340
- }
1341
- return pos({
1342
- type: 'custom-media',
1343
- name: trim(m[1]),
1344
- media: trim(m[2])
1345
- });
1346
- }
1347
- function atpage() {
1348
- var pos = position();
1349
- var m = match(/^@page */);
1350
- if (!m) {
1351
- return;
1352
- }
1353
- var sel = selector() || [];
1354
- if (!open()) {
1355
- return error("@page missing '{'");
1356
- }
1357
- var decls = comments();
1358
- var decl;
1359
- while ((decl = declaration())) {
1360
- decls.push(decl);
1361
- decls = decls.concat(comments());
1362
- }
1363
- if (!close()) {
1364
- return error("@page missing '}'");
1365
- }
1366
- return pos({
1367
- type: 'page',
1368
- selectors: sel,
1369
- declarations: decls
1370
- });
1371
- }
1372
- function atdocument() {
1373
- var pos = position();
1374
- var m = match(/^@([-\w]+)?document *([^{]+)/);
1375
- if (!m) {
1376
- return;
1377
- }
1378
- var vendor = trim(m[1]);
1379
- var doc = trim(m[2]);
1380
- if (!open()) {
1381
- return error("@document missing '{'");
1382
- }
1383
- var style = comments().concat(rules());
1384
- if (!close()) {
1385
- return error("@document missing '}'");
1386
- }
1387
- return pos({
1388
- type: 'document',
1389
- document: doc,
1390
- vendor: vendor,
1391
- rules: style
1392
- });
1393
- }
1394
- function atfontface() {
1395
- var pos = position();
1396
- var m = match(/^@font-face\s*/);
1397
- if (!m) {
1398
- return;
1399
- }
1400
- if (!open()) {
1401
- return error("@font-face missing '{'");
1402
- }
1403
- var decls = comments();
1404
- var decl;
1405
- while ((decl = declaration())) {
1406
- decls.push(decl);
1407
- decls = decls.concat(comments());
1408
- }
1409
- if (!close()) {
1410
- return error("@font-face missing '}'");
1411
- }
1412
- return pos({
1413
- type: 'font-face',
1414
- declarations: decls
1415
- });
1416
- }
1417
- var atimport = _compileAtrule('import');
1418
- var atcharset = _compileAtrule('charset');
1419
- var atnamespace = _compileAtrule('namespace');
1420
- function _compileAtrule(name) {
1421
- var re = new RegExp('^@' + name + '\\s*([^;]+);');
1422
- return function () {
1423
- var pos = position();
1424
- var m = match(re);
1425
- if (!m) {
1426
- return;
1427
- }
1428
- var ret = { type: name };
1429
- ret[name] = m[1].trim();
1430
- return pos(ret);
1431
- };
1432
- }
1433
- function atrule() {
1434
- if (css[0] !== '@') {
1435
- return;
1436
- }
1437
- return (atkeyframes() ||
1438
- atmedia() ||
1439
- atcustommedia() ||
1440
- atsupports() ||
1441
- atimport() ||
1442
- atcharset() ||
1443
- atnamespace() ||
1444
- atdocument() ||
1445
- atpage() ||
1446
- athost() ||
1447
- atfontface());
1448
- }
1449
- function rule() {
1450
- var pos = position();
1451
- var sel = selector();
1452
- if (!sel) {
1453
- return error('selector missing');
1454
- }
1455
- comments();
1456
- return pos({
1457
- type: 'rule',
1458
- selectors: sel,
1459
- declarations: declarations()
1460
- });
1461
- }
1462
- return addParent(stylesheet());
1463
- }
1464
- function trim(str) {
1465
- return str ? str.replace(/^\s+|\s+$/g, '') : '';
1466
- }
1467
- function addParent(obj, parent) {
1468
- var isNode = obj && typeof obj.type === 'string';
1469
- var childParent = isNode ? obj : parent;
1470
- for (var _i = 0, _a = Object.keys(obj); _i < _a.length; _i++) {
1471
- var k = _a[_i];
1472
- var value = obj[k];
1473
- if (Array.isArray(value)) {
1474
- value.forEach(function (v) {
1475
- addParent(v, childParent);
1476
- });
1477
- }
1478
- else if (value && typeof value === 'object') {
1479
- addParent(value, childParent);
1480
- }
1481
- }
1482
- if (isNode) {
1483
- Object.defineProperty(obj, 'parent', {
1484
- configurable: true,
1485
- writable: true,
1486
- enumerable: false,
1487
- value: parent || null
1488
- });
1489
- }
1490
- return obj;
116
+ var _id = 1;
117
+ var tagNameRegex = new RegExp('[^a-z0-9-_:]');
118
+ var IGNORED_NODE = -2;
119
+ function genId() {
120
+ return _id++;
121
+ }
122
+ function getValidTagName$1(element) {
123
+ if (element instanceof HTMLFormElement) {
124
+ return 'form';
125
+ }
126
+ var processedTagName = element.tagName.toLowerCase().trim();
127
+ if (tagNameRegex.test(processedTagName)) {
128
+ return 'div';
129
+ }
130
+ return processedTagName;
131
+ }
132
+ function getCssRulesString(s) {
133
+ try {
134
+ var rules = s.rules || s.cssRules;
135
+ return rules ? Array.from(rules).map(getCssRuleString).join('') : null;
136
+ }
137
+ catch (error) {
138
+ return null;
139
+ }
140
+ }
141
+ function getCssRuleString(rule) {
142
+ var cssStringified = rule.cssText;
143
+ if (isCSSImportRule(rule)) {
144
+ try {
145
+ cssStringified = getCssRulesString(rule.styleSheet) || cssStringified;
146
+ }
147
+ catch (_a) {
148
+ }
149
+ }
150
+ return cssStringified;
151
+ }
152
+ function isCSSImportRule(rule) {
153
+ return 'styleSheet' in rule;
154
+ }
155
+ function stringifyStyleSheet(sheet) {
156
+ return sheet.cssRules
157
+ ? Array.from(sheet.cssRules)
158
+ .map(function (rule) { return rule.cssText || ''; })
159
+ .join('')
160
+ : '';
161
+ }
162
+ function extractOrigin(url) {
163
+ var origin = '';
164
+ if (url.indexOf('//') > -1) {
165
+ origin = url.split('/').slice(0, 3).join('/');
166
+ }
167
+ else {
168
+ origin = url.split('/')[0];
169
+ }
170
+ origin = origin.split('?')[0];
171
+ return origin;
172
+ }
173
+ var canvasService;
174
+ var canvasCtx;
175
+ var URL_IN_CSS_REF = /url\((?:(')([^']*)'|(")(.*?)"|([^)]*))\)/gm;
176
+ var RELATIVE_PATH = /^(?!www\.|(?:http|ftp)s?:\/\/|[A-Za-z]:\\|\/\/|#).*/;
177
+ var DATA_URI = /^(data:)([^,]*),(.*)/i;
178
+ function absoluteToStylesheet(cssText, href) {
179
+ return (cssText || '').replace(URL_IN_CSS_REF, function (origin, quote1, path1, quote2, path2, path3) {
180
+ var filePath = path1 || path2 || path3;
181
+ var maybeQuote = quote1 || quote2 || '';
182
+ if (!filePath) {
183
+ return origin;
184
+ }
185
+ if (!RELATIVE_PATH.test(filePath)) {
186
+ return "url(".concat(maybeQuote).concat(filePath).concat(maybeQuote, ")");
187
+ }
188
+ if (DATA_URI.test(filePath)) {
189
+ return "url(".concat(maybeQuote).concat(filePath).concat(maybeQuote, ")");
190
+ }
191
+ if (filePath[0] === '/') {
192
+ return "url(".concat(maybeQuote).concat(extractOrigin(href) + filePath).concat(maybeQuote, ")");
193
+ }
194
+ var stack = href.split('/');
195
+ var parts = filePath.split('/');
196
+ stack.pop();
197
+ for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
198
+ var part = parts_1[_i];
199
+ if (part === '.') {
200
+ continue;
201
+ }
202
+ else if (part === '..') {
203
+ stack.pop();
204
+ }
205
+ else {
206
+ stack.push(part);
207
+ }
208
+ }
209
+ return "url(".concat(maybeQuote).concat(stack.join('/')).concat(maybeQuote, ")");
210
+ });
211
+ }
212
+ var SRCSET_NOT_SPACES = /^[^ \t\n\r\u000c]+/;
213
+ var SRCSET_COMMAS_OR_SPACES = /^[, \t\n\r\u000c]+/;
214
+ function getAbsoluteSrcsetString(doc, attributeValue) {
215
+ if (attributeValue.trim() === '') {
216
+ return attributeValue;
217
+ }
218
+ var pos = 0;
219
+ function collectCharacters(regEx) {
220
+ var chars;
221
+ var match = regEx.exec(attributeValue.substring(pos));
222
+ if (match) {
223
+ chars = match[0];
224
+ pos += chars.length;
225
+ return chars;
226
+ }
227
+ return '';
228
+ }
229
+ var output = [];
230
+ while (true) {
231
+ collectCharacters(SRCSET_COMMAS_OR_SPACES);
232
+ if (pos >= attributeValue.length) {
233
+ break;
234
+ }
235
+ var url = collectCharacters(SRCSET_NOT_SPACES);
236
+ if (url.slice(-1) === ',') {
237
+ url = absoluteToDoc(doc, url.substring(0, url.length - 1));
238
+ output.push(url);
239
+ }
240
+ else {
241
+ var descriptorsStr = '';
242
+ url = absoluteToDoc(doc, url);
243
+ var inParens = false;
244
+ while (true) {
245
+ var c = attributeValue.charAt(pos);
246
+ if (c === '') {
247
+ output.push((url + descriptorsStr).trim());
248
+ break;
249
+ }
250
+ else if (!inParens) {
251
+ if (c === ',') {
252
+ pos += 1;
253
+ output.push((url + descriptorsStr).trim());
254
+ break;
255
+ }
256
+ else if (c === '(') {
257
+ inParens = true;
258
+ }
259
+ }
260
+ else {
261
+ if (c === ')') {
262
+ inParens = false;
263
+ }
264
+ }
265
+ descriptorsStr += c;
266
+ pos += 1;
267
+ }
268
+ }
269
+ }
270
+ return output.join(', ');
271
+ }
272
+ function absoluteToDoc(doc, attributeValue) {
273
+ if (!attributeValue || attributeValue.trim() === '') {
274
+ return attributeValue;
275
+ }
276
+ var a = doc.createElement('a');
277
+ a.href = attributeValue;
278
+ return a.href;
279
+ }
280
+ function isSVGElement(el) {
281
+ return Boolean(el.tagName === 'svg' || el.ownerSVGElement);
282
+ }
283
+ function getHref() {
284
+ var a = document.createElement('a');
285
+ a.href = '';
286
+ return a.href;
287
+ }
288
+ function transformAttribute(doc, tagName, name, value) {
289
+ if (name === 'src' || (name === 'href' && value)) {
290
+ return absoluteToDoc(doc, value);
291
+ }
292
+ else if (name === 'xlink:href' && value && value[0] !== '#') {
293
+ return absoluteToDoc(doc, value);
294
+ }
295
+ else if (name === 'background' &&
296
+ value &&
297
+ (tagName === 'table' || tagName === 'td' || tagName === 'th')) {
298
+ return absoluteToDoc(doc, value);
299
+ }
300
+ else if (name === 'srcset' && value) {
301
+ return getAbsoluteSrcsetString(doc, value);
302
+ }
303
+ else if (name === 'style' && value) {
304
+ return absoluteToStylesheet(value, getHref());
305
+ }
306
+ else if (tagName === 'object' && name === 'data' && value) {
307
+ return absoluteToDoc(doc, value);
308
+ }
309
+ else {
310
+ return value;
311
+ }
312
+ }
313
+ function _isBlockedElement(element, blockClass, blockSelector) {
314
+ if (typeof blockClass === 'string') {
315
+ if (element.classList.contains(blockClass)) {
316
+ return true;
317
+ }
318
+ }
319
+ else {
320
+ for (var eIndex = element.classList.length; eIndex--;) {
321
+ var className = element.classList[eIndex];
322
+ if (blockClass.test(className)) {
323
+ return true;
324
+ }
325
+ }
326
+ }
327
+ if (blockSelector) {
328
+ return element.matches(blockSelector);
329
+ }
330
+ return false;
331
+ }
332
+ function classMatchesRegex(node, regex, checkAncestors) {
333
+ if (!node)
334
+ return false;
335
+ if (node.nodeType !== node.ELEMENT_NODE) {
336
+ if (!checkAncestors)
337
+ return false;
338
+ return classMatchesRegex(node.parentNode, regex, checkAncestors);
339
+ }
340
+ for (var eIndex = node.classList.length; eIndex--;) {
341
+ var className = node.classList[eIndex];
342
+ if (regex.test(className)) {
343
+ return true;
344
+ }
345
+ }
346
+ if (!checkAncestors)
347
+ return false;
348
+ return classMatchesRegex(node.parentNode, regex, checkAncestors);
349
+ }
350
+ function needMaskingText(node, maskTextClass, maskTextSelector) {
351
+ var el = node.nodeType === node.ELEMENT_NODE
352
+ ? node
353
+ : node.parentElement;
354
+ if (el === null)
355
+ return false;
356
+ if (typeof maskTextClass === 'string') {
357
+ if (el.classList.contains(maskTextClass))
358
+ return true;
359
+ if (el.closest(".".concat(maskTextClass)))
360
+ return true;
361
+ }
362
+ else {
363
+ if (classMatchesRegex(el, maskTextClass, true))
364
+ return true;
365
+ }
366
+ if (maskTextSelector) {
367
+ if (el.matches(maskTextSelector))
368
+ return true;
369
+ if (el.closest(maskTextSelector))
370
+ return true;
371
+ }
372
+ return false;
373
+ }
374
+ function onceIframeLoaded(iframeEl, listener, iframeLoadTimeout) {
375
+ var win = iframeEl.contentWindow;
376
+ if (!win) {
377
+ return;
378
+ }
379
+ var fired = false;
380
+ var readyState;
381
+ try {
382
+ readyState = win.document.readyState;
383
+ }
384
+ catch (error) {
385
+ return;
386
+ }
387
+ if (readyState !== 'complete') {
388
+ var timer_1 = setTimeout(function () {
389
+ if (!fired) {
390
+ listener();
391
+ fired = true;
392
+ }
393
+ }, iframeLoadTimeout);
394
+ iframeEl.addEventListener('load', function () {
395
+ clearTimeout(timer_1);
396
+ fired = true;
397
+ listener();
398
+ });
399
+ return;
400
+ }
401
+ var blankUrl = 'about:blank';
402
+ if (win.location.href !== blankUrl ||
403
+ iframeEl.src === blankUrl ||
404
+ iframeEl.src === '') {
405
+ setTimeout(listener, 0);
406
+ return iframeEl.addEventListener('load', listener);
407
+ }
408
+ iframeEl.addEventListener('load', listener);
409
+ }
410
+ function isStylesheetLoaded(link) {
411
+ if (!link.getAttribute('href'))
412
+ return true;
413
+ return link.sheet !== null;
414
+ }
415
+ function onceStylesheetLoaded(link, listener, styleSheetLoadTimeout) {
416
+ var fired = false;
417
+ var styleSheetLoaded;
418
+ try {
419
+ styleSheetLoaded = link.sheet;
420
+ }
421
+ catch (error) {
422
+ return;
423
+ }
424
+ if (styleSheetLoaded)
425
+ return;
426
+ var timer = setTimeout(function () {
427
+ if (!fired) {
428
+ listener();
429
+ fired = true;
430
+ }
431
+ }, styleSheetLoadTimeout);
432
+ link.addEventListener('load', function () {
433
+ clearTimeout(timer);
434
+ fired = true;
435
+ listener();
436
+ });
437
+ }
438
+ function serializeNode(n, options) {
439
+ var doc = options.doc, mirror = options.mirror, blockClass = options.blockClass, blockSelector = options.blockSelector, maskTextClass = options.maskTextClass, maskTextSelector = options.maskTextSelector, inlineStylesheet = options.inlineStylesheet, _a = options.maskInputOptions, maskInputOptions = _a === void 0 ? {} : _a, maskTextFn = options.maskTextFn, maskInputFn = options.maskInputFn, _b = options.dataURLOptions, dataURLOptions = _b === void 0 ? {} : _b, inlineImages = options.inlineImages, recordCanvas = options.recordCanvas, keepIframeSrcFn = options.keepIframeSrcFn, _c = options.newlyAddedElement, newlyAddedElement = _c === void 0 ? false : _c, enableStrictPrivacy = options.enableStrictPrivacy;
440
+ var rootId = getRootId(doc, mirror);
441
+ switch (n.nodeType) {
442
+ case n.DOCUMENT_NODE:
443
+ if (n.compatMode !== 'CSS1Compat') {
444
+ return {
445
+ type: NodeType$2.Document,
446
+ childNodes: [],
447
+ compatMode: n.compatMode,
448
+ rootId: rootId
449
+ };
450
+ }
451
+ else {
452
+ return {
453
+ type: NodeType$2.Document,
454
+ childNodes: [],
455
+ rootId: rootId
456
+ };
457
+ }
458
+ case n.DOCUMENT_TYPE_NODE:
459
+ return {
460
+ type: NodeType$2.DocumentType,
461
+ name: n.name,
462
+ publicId: n.publicId,
463
+ systemId: n.systemId,
464
+ rootId: rootId
465
+ };
466
+ case n.ELEMENT_NODE:
467
+ return serializeElementNode(n, {
468
+ doc: doc,
469
+ blockClass: blockClass,
470
+ blockSelector: blockSelector,
471
+ inlineStylesheet: inlineStylesheet,
472
+ maskInputOptions: maskInputOptions,
473
+ maskInputFn: maskInputFn,
474
+ dataURLOptions: dataURLOptions,
475
+ inlineImages: inlineImages,
476
+ recordCanvas: recordCanvas,
477
+ keepIframeSrcFn: keepIframeSrcFn,
478
+ newlyAddedElement: newlyAddedElement,
479
+ enableStrictPrivacy: enableStrictPrivacy,
480
+ rootId: rootId
481
+ });
482
+ case n.TEXT_NODE:
483
+ return serializeTextNode(n, {
484
+ maskTextClass: maskTextClass,
485
+ maskTextSelector: maskTextSelector,
486
+ maskTextFn: maskTextFn,
487
+ enableStrictPrivacy: enableStrictPrivacy,
488
+ rootId: rootId
489
+ });
490
+ case n.CDATA_SECTION_NODE:
491
+ return {
492
+ type: NodeType$2.CDATA,
493
+ textContent: '',
494
+ rootId: rootId
495
+ };
496
+ case n.COMMENT_NODE:
497
+ return {
498
+ type: NodeType$2.Comment,
499
+ textContent: n.textContent || '',
500
+ rootId: rootId
501
+ };
502
+ default:
503
+ return false;
504
+ }
505
+ }
506
+ function getRootId(doc, mirror) {
507
+ if (!mirror.hasNode(doc))
508
+ return undefined;
509
+ var docId = mirror.getId(doc);
510
+ return docId === 1 ? undefined : docId;
511
+ }
512
+ function serializeTextNode(n, options) {
513
+ var _a;
514
+ var maskTextClass = options.maskTextClass, maskTextSelector = options.maskTextSelector, maskTextFn = options.maskTextFn, enableStrictPrivacy = options.enableStrictPrivacy, rootId = options.rootId;
515
+ var parentTagName = n.parentNode && n.parentNode.tagName;
516
+ var textContent = n.textContent;
517
+ var isStyle = parentTagName === 'STYLE' ? true : undefined;
518
+ var isScript = parentTagName === 'SCRIPT' ? true : undefined;
519
+ var textContentHandled = false;
520
+ if (isStyle && textContent) {
521
+ try {
522
+ if (n.nextSibling || n.previousSibling) {
523
+ }
524
+ else if ((_a = n.parentNode.sheet) === null || _a === void 0 ? void 0 : _a.cssRules) {
525
+ textContent = stringifyStyleSheet(n.parentNode.sheet);
526
+ }
527
+ }
528
+ catch (err) {
529
+ console.warn("Cannot get CSS styles from text's parentNode. Error: ".concat(err), n);
530
+ }
531
+ textContent = absoluteToStylesheet(textContent, getHref());
532
+ textContentHandled = true;
533
+ }
534
+ if (isScript) {
535
+ textContent = 'SCRIPT_PLACEHOLDER';
536
+ textContentHandled = true;
537
+ }
538
+ else if (parentTagName === 'NOSCRIPT') {
539
+ textContent = '';
540
+ textContentHandled = true;
541
+ }
542
+ if (!isStyle &&
543
+ !isScript &&
544
+ textContent &&
545
+ needMaskingText(n, maskTextClass, maskTextSelector)) {
546
+ textContent = maskTextFn
547
+ ? maskTextFn(textContent)
548
+ : textContent.replace(/[\S]/g, '*');
549
+ }
550
+ if (enableStrictPrivacy && !textContentHandled && parentTagName) {
551
+ var IGNORE_TAG_NAMES = new Set([
552
+ 'HEAD',
553
+ 'TITLE',
554
+ 'STYLE',
555
+ 'SCRIPT',
556
+ 'HTML',
557
+ 'BODY',
558
+ 'NOSCRIPT',
559
+ ]);
560
+ if (!IGNORE_TAG_NAMES.has(parentTagName) && textContent) {
561
+ textContent = obfuscateText(textContent);
562
+ }
563
+ }
564
+ return {
565
+ type: NodeType$2.Text,
566
+ textContent: textContent || '',
567
+ isStyle: isStyle,
568
+ rootId: rootId
569
+ };
570
+ }
571
+ function serializeElementNode(n, options) {
572
+ var doc = options.doc, blockClass = options.blockClass, blockSelector = options.blockSelector, inlineStylesheet = options.inlineStylesheet, _a = options.maskInputOptions, maskInputOptions = _a === void 0 ? {} : _a, maskInputFn = options.maskInputFn, _b = options.dataURLOptions, dataURLOptions = _b === void 0 ? {} : _b, inlineImages = options.inlineImages, recordCanvas = options.recordCanvas, keepIframeSrcFn = options.keepIframeSrcFn, _c = options.newlyAddedElement, newlyAddedElement = _c === void 0 ? false : _c, enableStrictPrivacy = options.enableStrictPrivacy, rootId = options.rootId;
573
+ var needBlock = _isBlockedElement(n, blockClass, blockSelector);
574
+ var tagName = getValidTagName$1(n);
575
+ var attributes = {};
576
+ var len = n.attributes.length;
577
+ for (var i = 0; i < len; i++) {
578
+ var attr = n.attributes[i];
579
+ attributes[attr.name] = transformAttribute(doc, tagName, attr.name, attr.value);
580
+ }
581
+ if (tagName === 'link' && inlineStylesheet) {
582
+ var stylesheet = Array.from(doc.styleSheets).find(function (s) {
583
+ return s.href === n.href;
584
+ });
585
+ var cssText = null;
586
+ if (stylesheet) {
587
+ cssText = getCssRulesString(stylesheet);
588
+ }
589
+ if (cssText) {
590
+ delete attributes.rel;
591
+ delete attributes.href;
592
+ attributes._cssText = absoluteToStylesheet(cssText, stylesheet.href);
593
+ }
594
+ }
595
+ if (tagName === 'style' &&
596
+ n.sheet &&
597
+ !(n.innerText || n.textContent || '').trim().length) {
598
+ var cssText = getCssRulesString(n.sheet);
599
+ if (cssText) {
600
+ attributes._cssText = absoluteToStylesheet(cssText, getHref());
601
+ }
602
+ }
603
+ if (tagName === 'input' || tagName === 'textarea' || tagName === 'select') {
604
+ var value = n.value;
605
+ if (attributes.type !== 'radio' &&
606
+ attributes.type !== 'checkbox' &&
607
+ attributes.type !== 'submit' &&
608
+ attributes.type !== 'button' &&
609
+ value) {
610
+ attributes.value = maskInputValue({
611
+ type: attributes.type,
612
+ tagName: tagName,
613
+ value: value,
614
+ maskInputOptions: maskInputOptions,
615
+ maskInputFn: maskInputFn
616
+ });
617
+ }
618
+ else if (n.checked) {
619
+ attributes.checked = n.checked;
620
+ }
621
+ }
622
+ if (tagName === 'option') {
623
+ if (n.selected && !maskInputOptions['select']) {
624
+ attributes.selected = true;
625
+ }
626
+ else {
627
+ delete attributes.selected;
628
+ }
629
+ }
630
+ if (tagName === 'canvas' && recordCanvas) {
631
+ if (n.__context === '2d') {
632
+ if (!is2DCanvasBlank(n)) {
633
+ attributes.rr_dataURL = n.toDataURL(dataURLOptions.type, dataURLOptions.quality);
634
+ }
635
+ }
636
+ else if (!('__context' in n)) {
637
+ var canvasDataURL = n.toDataURL(dataURLOptions.type, dataURLOptions.quality);
638
+ var blankCanvas = document.createElement('canvas');
639
+ blankCanvas.width = n.width;
640
+ blankCanvas.height = n.height;
641
+ var blankCanvasDataURL = blankCanvas.toDataURL(dataURLOptions.type, dataURLOptions.quality);
642
+ if (canvasDataURL !== blankCanvasDataURL) {
643
+ attributes.rr_dataURL = canvasDataURL;
644
+ }
645
+ }
646
+ }
647
+ if (tagName === 'img' && inlineImages) {
648
+ if (!canvasService) {
649
+ canvasService = doc.createElement('canvas');
650
+ canvasCtx = canvasService.getContext('2d');
651
+ }
652
+ var image_1 = n;
653
+ var oldValue_1 = image_1.crossOrigin;
654
+ image_1.crossOrigin = 'anonymous';
655
+ var recordInlineImage = function () {
656
+ try {
657
+ canvasService.width = image_1.naturalWidth;
658
+ canvasService.height = image_1.naturalHeight;
659
+ canvasCtx.drawImage(image_1, 0, 0);
660
+ attributes.rr_dataURL = canvasService.toDataURL(dataURLOptions.type, dataURLOptions.quality);
661
+ }
662
+ catch (err) {
663
+ console.warn("Cannot inline img src=".concat(image_1.currentSrc, "! Error: ").concat(err));
664
+ }
665
+ oldValue_1
666
+ ? (attributes.crossOrigin = oldValue_1)
667
+ : image_1.removeAttribute('crossorigin');
668
+ };
669
+ if (image_1.complete && image_1.naturalWidth !== 0)
670
+ recordInlineImage();
671
+ else
672
+ image_1.onload = recordInlineImage;
673
+ }
674
+ if (tagName === 'audio' || tagName === 'video') {
675
+ attributes.rr_mediaState = n.paused
676
+ ? 'paused'
677
+ : 'played';
678
+ attributes.rr_mediaCurrentTime = n.currentTime;
679
+ }
680
+ if (!newlyAddedElement) {
681
+ if (n.scrollLeft) {
682
+ attributes.rr_scrollLeft = n.scrollLeft;
683
+ }
684
+ if (n.scrollTop) {
685
+ attributes.rr_scrollTop = n.scrollTop;
686
+ }
687
+ }
688
+ if (needBlock || (tagName === 'img' && enableStrictPrivacy)) {
689
+ var _d = n.getBoundingClientRect(), width = _d.width, height = _d.height;
690
+ attributes = {
691
+ "class": attributes["class"],
692
+ rr_width: "".concat(width, "px"),
693
+ rr_height: "".concat(height, "px")
694
+ };
695
+ needBlock = true;
696
+ }
697
+ if (tagName === 'iframe' && !keepIframeSrcFn(attributes.src)) {
698
+ if (!n.contentDocument) {
699
+ attributes.rr_src = attributes.src;
700
+ }
701
+ delete attributes.src;
702
+ }
703
+ return {
704
+ type: NodeType$2.Element,
705
+ tagName: tagName,
706
+ attributes: attributes,
707
+ childNodes: [],
708
+ isSVG: isSVGElement(n) || undefined,
709
+ needBlock: needBlock,
710
+ rootId: rootId
711
+ };
712
+ }
713
+ function lowerIfExists(maybeAttr) {
714
+ if (maybeAttr === undefined) {
715
+ return '';
716
+ }
717
+ else {
718
+ return maybeAttr.toLowerCase();
719
+ }
720
+ }
721
+ function slimDOMExcluded(sn, slimDOMOptions) {
722
+ if (slimDOMOptions.comment && sn.type === NodeType$2.Comment) {
723
+ return true;
724
+ }
725
+ else if (sn.type === NodeType$2.Element) {
726
+ if (slimDOMOptions.script &&
727
+ (sn.tagName === 'script' ||
728
+ (sn.tagName === 'link' &&
729
+ sn.attributes.rel === 'preload' &&
730
+ sn.attributes.as === 'script') ||
731
+ (sn.tagName === 'link' &&
732
+ sn.attributes.rel === 'prefetch' &&
733
+ typeof sn.attributes.href === 'string' &&
734
+ sn.attributes.href.endsWith('.js')))) {
735
+ return true;
736
+ }
737
+ else if (slimDOMOptions.headFavicon &&
738
+ ((sn.tagName === 'link' && sn.attributes.rel === 'shortcut icon') ||
739
+ (sn.tagName === 'meta' &&
740
+ (lowerIfExists(sn.attributes.name).match(/^msapplication-tile(image|color)$/) ||
741
+ lowerIfExists(sn.attributes.name) === 'application-name' ||
742
+ lowerIfExists(sn.attributes.rel) === 'icon' ||
743
+ lowerIfExists(sn.attributes.rel) === 'apple-touch-icon' ||
744
+ lowerIfExists(sn.attributes.rel) === 'shortcut icon')))) {
745
+ return true;
746
+ }
747
+ else if (sn.tagName === 'meta') {
748
+ if (slimDOMOptions.headMetaDescKeywords &&
749
+ lowerIfExists(sn.attributes.name).match(/^description|keywords$/)) {
750
+ return true;
751
+ }
752
+ else if (slimDOMOptions.headMetaSocial &&
753
+ (lowerIfExists(sn.attributes.property).match(/^(og|twitter|fb):/) ||
754
+ lowerIfExists(sn.attributes.name).match(/^(og|twitter):/) ||
755
+ lowerIfExists(sn.attributes.name) === 'pinterest')) {
756
+ return true;
757
+ }
758
+ else if (slimDOMOptions.headMetaRobots &&
759
+ (lowerIfExists(sn.attributes.name) === 'robots' ||
760
+ lowerIfExists(sn.attributes.name) === 'googlebot' ||
761
+ lowerIfExists(sn.attributes.name) === 'bingbot')) {
762
+ return true;
763
+ }
764
+ else if (slimDOMOptions.headMetaHttpEquiv &&
765
+ sn.attributes['http-equiv'] !== undefined) {
766
+ return true;
767
+ }
768
+ else if (slimDOMOptions.headMetaAuthorship &&
769
+ (lowerIfExists(sn.attributes.name) === 'author' ||
770
+ lowerIfExists(sn.attributes.name) === 'generator' ||
771
+ lowerIfExists(sn.attributes.name) === 'framework' ||
772
+ lowerIfExists(sn.attributes.name) === 'publisher' ||
773
+ lowerIfExists(sn.attributes.name) === 'progid' ||
774
+ lowerIfExists(sn.attributes.property).match(/^article:/) ||
775
+ lowerIfExists(sn.attributes.property).match(/^product:/))) {
776
+ return true;
777
+ }
778
+ else if (slimDOMOptions.headMetaVerification &&
779
+ (lowerIfExists(sn.attributes.name) === 'google-site-verification' ||
780
+ lowerIfExists(sn.attributes.name) === 'yandex-verification' ||
781
+ lowerIfExists(sn.attributes.name) === 'csrf-token' ||
782
+ lowerIfExists(sn.attributes.name) === 'p:domain_verify' ||
783
+ lowerIfExists(sn.attributes.name) === 'verify-v1' ||
784
+ lowerIfExists(sn.attributes.name) === 'verification' ||
785
+ lowerIfExists(sn.attributes.name) === 'shopify-checkout-api-token')) {
786
+ return true;
787
+ }
788
+ }
789
+ }
790
+ return false;
791
+ }
792
+ function serializeNodeWithId(n, options) {
793
+ var doc = options.doc, mirror = options.mirror, blockClass = options.blockClass, blockSelector = options.blockSelector, maskTextClass = options.maskTextClass, maskTextSelector = options.maskTextSelector, _a = options.skipChild, skipChild = _a === void 0 ? false : _a, _b = options.inlineStylesheet, inlineStylesheet = _b === void 0 ? true : _b, _c = options.maskInputOptions, maskInputOptions = _c === void 0 ? {} : _c, maskTextFn = options.maskTextFn, maskInputFn = options.maskInputFn, slimDOMOptions = options.slimDOMOptions, _d = options.dataURLOptions, dataURLOptions = _d === void 0 ? {} : _d, _e = options.inlineImages, inlineImages = _e === void 0 ? false : _e, _f = options.recordCanvas, recordCanvas = _f === void 0 ? false : _f, onSerialize = options.onSerialize, onIframeLoad = options.onIframeLoad, _g = options.iframeLoadTimeout, iframeLoadTimeout = _g === void 0 ? 5000 : _g, onStylesheetLoad = options.onStylesheetLoad, _h = options.stylesheetLoadTimeout, stylesheetLoadTimeout = _h === void 0 ? 5000 : _h, _j = options.keepIframeSrcFn, keepIframeSrcFn = _j === void 0 ? function () { return false; } : _j, _k = options.newlyAddedElement, newlyAddedElement = _k === void 0 ? false : _k, enableStrictPrivacy = options.enableStrictPrivacy;
794
+ var _l = options.preserveWhiteSpace, preserveWhiteSpace = _l === void 0 ? true : _l;
795
+ var _serializedNode = serializeNode(n, {
796
+ doc: doc,
797
+ mirror: mirror,
798
+ blockClass: blockClass,
799
+ blockSelector: blockSelector,
800
+ maskTextClass: maskTextClass,
801
+ maskTextSelector: maskTextSelector,
802
+ inlineStylesheet: inlineStylesheet,
803
+ maskInputOptions: maskInputOptions,
804
+ maskTextFn: maskTextFn,
805
+ maskInputFn: maskInputFn,
806
+ dataURLOptions: dataURLOptions,
807
+ inlineImages: inlineImages,
808
+ recordCanvas: recordCanvas,
809
+ keepIframeSrcFn: keepIframeSrcFn,
810
+ newlyAddedElement: newlyAddedElement,
811
+ enableStrictPrivacy: enableStrictPrivacy
812
+ });
813
+ if (!_serializedNode) {
814
+ console.warn(n, 'not serialized');
815
+ return null;
816
+ }
817
+ var id;
818
+ if (mirror.hasNode(n)) {
819
+ id = mirror.getId(n);
820
+ }
821
+ else if (slimDOMExcluded(_serializedNode, slimDOMOptions) ||
822
+ (!preserveWhiteSpace &&
823
+ _serializedNode.type === NodeType$2.Text &&
824
+ !_serializedNode.isStyle &&
825
+ !_serializedNode.textContent.replace(/^\s+|\s+$/gm, '').length)) {
826
+ id = IGNORED_NODE;
827
+ }
828
+ else {
829
+ id = genId();
830
+ }
831
+ if (id === IGNORED_NODE) {
832
+ return null;
833
+ }
834
+ var serializedNode = Object.assign(_serializedNode, { id: id });
835
+ mirror.add(n, serializedNode);
836
+ if (onSerialize) {
837
+ onSerialize(n);
838
+ }
839
+ var recordChild = !skipChild;
840
+ if (serializedNode.type === NodeType$2.Element) {
841
+ recordChild = recordChild && !serializedNode.needBlock;
842
+ if (serializedNode.needBlock && serializedNode.tagName === 'img') {
843
+ var clone = n.cloneNode();
844
+ clone.src = '';
845
+ mirror.add(clone, serializedNode);
846
+ }
847
+ delete serializedNode.needBlock;
848
+ if (n.shadowRoot)
849
+ serializedNode.isShadowHost = true;
850
+ }
851
+ if ((serializedNode.type === NodeType$2.Document ||
852
+ serializedNode.type === NodeType$2.Element) &&
853
+ recordChild) {
854
+ if (slimDOMOptions.headWhitespace &&
855
+ serializedNode.type === NodeType$2.Element &&
856
+ serializedNode.tagName === 'head') {
857
+ preserveWhiteSpace = false;
858
+ }
859
+ var bypassOptions = {
860
+ doc: doc,
861
+ mirror: mirror,
862
+ blockClass: blockClass,
863
+ blockSelector: blockSelector,
864
+ maskTextClass: maskTextClass,
865
+ maskTextSelector: maskTextSelector,
866
+ skipChild: skipChild,
867
+ inlineStylesheet: inlineStylesheet,
868
+ maskInputOptions: maskInputOptions,
869
+ maskTextFn: maskTextFn,
870
+ maskInputFn: maskInputFn,
871
+ slimDOMOptions: slimDOMOptions,
872
+ dataURLOptions: dataURLOptions,
873
+ inlineImages: inlineImages,
874
+ recordCanvas: recordCanvas,
875
+ preserveWhiteSpace: preserveWhiteSpace,
876
+ onSerialize: onSerialize,
877
+ onIframeLoad: onIframeLoad,
878
+ iframeLoadTimeout: iframeLoadTimeout,
879
+ onStylesheetLoad: onStylesheetLoad,
880
+ stylesheetLoadTimeout: stylesheetLoadTimeout,
881
+ keepIframeSrcFn: keepIframeSrcFn,
882
+ enableStrictPrivacy: enableStrictPrivacy
883
+ };
884
+ for (var _i = 0, _m = Array.from(n.childNodes); _i < _m.length; _i++) {
885
+ var childN = _m[_i];
886
+ var serializedChildNode = serializeNodeWithId(childN, bypassOptions);
887
+ if (serializedChildNode) {
888
+ serializedNode.childNodes.push(serializedChildNode);
889
+ }
890
+ }
891
+ if (isElement(n) && n.shadowRoot) {
892
+ for (var _o = 0, _p = Array.from(n.shadowRoot.childNodes); _o < _p.length; _o++) {
893
+ var childN = _p[_o];
894
+ var serializedChildNode = serializeNodeWithId(childN, bypassOptions);
895
+ if (serializedChildNode) {
896
+ serializedChildNode.isShadow = true;
897
+ serializedNode.childNodes.push(serializedChildNode);
898
+ }
899
+ }
900
+ }
901
+ }
902
+ if (n.parentNode && isShadowRoot(n.parentNode)) {
903
+ serializedNode.isShadow = true;
904
+ }
905
+ if (serializedNode.type === NodeType$2.Element &&
906
+ serializedNode.tagName === 'iframe') {
907
+ onceIframeLoaded(n, function () {
908
+ var iframeDoc = n.contentDocument;
909
+ if (iframeDoc && onIframeLoad) {
910
+ var serializedIframeNode = serializeNodeWithId(iframeDoc, {
911
+ doc: iframeDoc,
912
+ mirror: mirror,
913
+ blockClass: blockClass,
914
+ blockSelector: blockSelector,
915
+ maskTextClass: maskTextClass,
916
+ maskTextSelector: maskTextSelector,
917
+ skipChild: false,
918
+ inlineStylesheet: inlineStylesheet,
919
+ maskInputOptions: maskInputOptions,
920
+ maskTextFn: maskTextFn,
921
+ maskInputFn: maskInputFn,
922
+ slimDOMOptions: slimDOMOptions,
923
+ dataURLOptions: dataURLOptions,
924
+ inlineImages: inlineImages,
925
+ recordCanvas: recordCanvas,
926
+ preserveWhiteSpace: preserveWhiteSpace,
927
+ onSerialize: onSerialize,
928
+ onIframeLoad: onIframeLoad,
929
+ iframeLoadTimeout: iframeLoadTimeout,
930
+ onStylesheetLoad: onStylesheetLoad,
931
+ stylesheetLoadTimeout: stylesheetLoadTimeout,
932
+ keepIframeSrcFn: keepIframeSrcFn,
933
+ enableStrictPrivacy: enableStrictPrivacy
934
+ });
935
+ if (serializedIframeNode) {
936
+ onIframeLoad(n, serializedIframeNode);
937
+ }
938
+ }
939
+ }, iframeLoadTimeout);
940
+ }
941
+ if (serializedNode.type === NodeType$2.Element &&
942
+ serializedNode.tagName === 'link' &&
943
+ serializedNode.attributes.rel === 'stylesheet') {
944
+ onceStylesheetLoaded(n, function () {
945
+ if (onStylesheetLoad) {
946
+ var serializedLinkNode = serializeNodeWithId(n, {
947
+ doc: doc,
948
+ mirror: mirror,
949
+ blockClass: blockClass,
950
+ blockSelector: blockSelector,
951
+ maskTextClass: maskTextClass,
952
+ maskTextSelector: maskTextSelector,
953
+ skipChild: false,
954
+ inlineStylesheet: inlineStylesheet,
955
+ maskInputOptions: maskInputOptions,
956
+ maskTextFn: maskTextFn,
957
+ maskInputFn: maskInputFn,
958
+ slimDOMOptions: slimDOMOptions,
959
+ dataURLOptions: dataURLOptions,
960
+ inlineImages: inlineImages,
961
+ recordCanvas: recordCanvas,
962
+ preserveWhiteSpace: preserveWhiteSpace,
963
+ onSerialize: onSerialize,
964
+ onIframeLoad: onIframeLoad,
965
+ iframeLoadTimeout: iframeLoadTimeout,
966
+ onStylesheetLoad: onStylesheetLoad,
967
+ stylesheetLoadTimeout: stylesheetLoadTimeout,
968
+ keepIframeSrcFn: keepIframeSrcFn,
969
+ enableStrictPrivacy: enableStrictPrivacy
970
+ });
971
+ if (serializedLinkNode) {
972
+ onStylesheetLoad(n, serializedLinkNode);
973
+ }
974
+ }
975
+ }, stylesheetLoadTimeout);
976
+ if (isStylesheetLoaded(n) === false)
977
+ return null;
978
+ }
979
+ return serializedNode;
980
+ }
981
+ function snapshot(n, options) {
982
+ var _a = options || {}, _b = _a.mirror, mirror = _b === void 0 ? new Mirror$2() : _b, _c = _a.blockClass, blockClass = _c === void 0 ? 'highlight-block' : _c, _d = _a.blockSelector, blockSelector = _d === void 0 ? null : _d, _e = _a.maskTextClass, maskTextClass = _e === void 0 ? 'highlight-mask' : _e, _f = _a.maskTextSelector, maskTextSelector = _f === void 0 ? null : _f, _g = _a.inlineStylesheet, inlineStylesheet = _g === void 0 ? true : _g, _h = _a.inlineImages, inlineImages = _h === void 0 ? false : _h, _j = _a.recordCanvas, recordCanvas = _j === void 0 ? false : _j, _k = _a.maskAllInputs, maskAllInputs = _k === void 0 ? false : _k, maskTextFn = _a.maskTextFn, maskInputFn = _a.maskInputFn, _l = _a.slimDOM, slimDOM = _l === void 0 ? false : _l, dataURLOptions = _a.dataURLOptions, preserveWhiteSpace = _a.preserveWhiteSpace, onSerialize = _a.onSerialize, onIframeLoad = _a.onIframeLoad, iframeLoadTimeout = _a.iframeLoadTimeout, onStylesheetLoad = _a.onStylesheetLoad, stylesheetLoadTimeout = _a.stylesheetLoadTimeout, _m = _a.keepIframeSrcFn, keepIframeSrcFn = _m === void 0 ? function () { return false; } : _m, _o = _a.enableStrictPrivacy, enableStrictPrivacy = _o === void 0 ? false : _o;
983
+ var maskInputOptions = maskAllInputs === true
984
+ ? {
985
+ color: true,
986
+ date: true,
987
+ 'datetime-local': true,
988
+ email: true,
989
+ month: true,
990
+ number: true,
991
+ range: true,
992
+ search: true,
993
+ tel: true,
994
+ text: true,
995
+ time: true,
996
+ url: true,
997
+ week: true,
998
+ textarea: true,
999
+ select: true,
1000
+ password: true
1001
+ }
1002
+ : maskAllInputs === false
1003
+ ? {
1004
+ password: true
1005
+ }
1006
+ : maskAllInputs;
1007
+ var slimDOMOptions = slimDOM === true || slimDOM === 'all'
1008
+ ?
1009
+ {
1010
+ script: true,
1011
+ comment: true,
1012
+ headFavicon: true,
1013
+ headWhitespace: true,
1014
+ headMetaDescKeywords: slimDOM === 'all',
1015
+ headMetaSocial: true,
1016
+ headMetaRobots: true,
1017
+ headMetaHttpEquiv: true,
1018
+ headMetaAuthorship: true,
1019
+ headMetaVerification: true
1020
+ }
1021
+ : slimDOM === false
1022
+ ? {}
1023
+ : slimDOM;
1024
+ return serializeNodeWithId(n, {
1025
+ doc: n,
1026
+ mirror: mirror,
1027
+ blockClass: blockClass,
1028
+ blockSelector: blockSelector,
1029
+ maskTextClass: maskTextClass,
1030
+ maskTextSelector: maskTextSelector,
1031
+ skipChild: false,
1032
+ inlineStylesheet: inlineStylesheet,
1033
+ maskInputOptions: maskInputOptions,
1034
+ maskTextFn: maskTextFn,
1035
+ maskInputFn: maskInputFn,
1036
+ slimDOMOptions: slimDOMOptions,
1037
+ dataURLOptions: dataURLOptions,
1038
+ inlineImages: inlineImages,
1039
+ recordCanvas: recordCanvas,
1040
+ preserveWhiteSpace: preserveWhiteSpace,
1041
+ onSerialize: onSerialize,
1042
+ onIframeLoad: onIframeLoad,
1043
+ iframeLoadTimeout: iframeLoadTimeout,
1044
+ onStylesheetLoad: onStylesheetLoad,
1045
+ stylesheetLoadTimeout: stylesheetLoadTimeout,
1046
+ keepIframeSrcFn: keepIframeSrcFn,
1047
+ newlyAddedElement: false,
1048
+ enableStrictPrivacy: enableStrictPrivacy
1049
+ });
1050
+ }
1051
+
1052
+ var commentre = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//g;
1053
+ function parse(css, options) {
1054
+ if (options === void 0) { options = {}; }
1055
+ var lineno = 1;
1056
+ var column = 1;
1057
+ function updatePosition(str) {
1058
+ var lines = str.match(/\n/g);
1059
+ if (lines) {
1060
+ lineno += lines.length;
1061
+ }
1062
+ var i = str.lastIndexOf('\n');
1063
+ column = i === -1 ? column + str.length : str.length - i;
1064
+ }
1065
+ function position() {
1066
+ var start = { line: lineno, column: column };
1067
+ return function (node) {
1068
+ node.position = new Position(start);
1069
+ whitespace();
1070
+ return node;
1071
+ };
1072
+ }
1073
+ var Position = (function () {
1074
+ function Position(start) {
1075
+ this.start = start;
1076
+ this.end = { line: lineno, column: column };
1077
+ this.source = options.source;
1078
+ }
1079
+ return Position;
1080
+ }());
1081
+ Position.prototype.content = css;
1082
+ var errorsList = [];
1083
+ function error(msg) {
1084
+ var err = new Error(options.source + ':' + lineno + ':' + column + ': ' + msg);
1085
+ err.reason = msg;
1086
+ err.filename = options.source;
1087
+ err.line = lineno;
1088
+ err.column = column;
1089
+ err.source = css;
1090
+ if (options.silent) {
1091
+ errorsList.push(err);
1092
+ }
1093
+ else {
1094
+ throw err;
1095
+ }
1096
+ }
1097
+ function stylesheet() {
1098
+ var rulesList = rules();
1099
+ return {
1100
+ type: 'stylesheet',
1101
+ stylesheet: {
1102
+ source: options.source,
1103
+ rules: rulesList,
1104
+ parsingErrors: errorsList
1105
+ }
1106
+ };
1107
+ }
1108
+ function open() {
1109
+ return match(/^{\s*/);
1110
+ }
1111
+ function close() {
1112
+ return match(/^}/);
1113
+ }
1114
+ function rules() {
1115
+ var node;
1116
+ var rules = [];
1117
+ whitespace();
1118
+ comments(rules);
1119
+ while (css.length && css.charAt(0) !== '}' && (node = atrule() || rule())) {
1120
+ if (node !== false) {
1121
+ rules.push(node);
1122
+ comments(rules);
1123
+ }
1124
+ }
1125
+ return rules;
1126
+ }
1127
+ function match(re) {
1128
+ var m = re.exec(css);
1129
+ if (!m) {
1130
+ return;
1131
+ }
1132
+ var str = m[0];
1133
+ updatePosition(str);
1134
+ css = css.slice(str.length);
1135
+ return m;
1136
+ }
1137
+ function whitespace() {
1138
+ match(/^\s*/);
1139
+ }
1140
+ function comments(rules) {
1141
+ if (rules === void 0) { rules = []; }
1142
+ var c;
1143
+ while ((c = comment())) {
1144
+ if (c !== false) {
1145
+ rules.push(c);
1146
+ }
1147
+ c = comment();
1148
+ }
1149
+ return rules;
1150
+ }
1151
+ function comment() {
1152
+ var pos = position();
1153
+ if ('/' !== css.charAt(0) || '*' !== css.charAt(1)) {
1154
+ return;
1155
+ }
1156
+ var i = 2;
1157
+ while ('' !== css.charAt(i) &&
1158
+ ('*' !== css.charAt(i) || '/' !== css.charAt(i + 1))) {
1159
+ ++i;
1160
+ }
1161
+ i += 2;
1162
+ if ('' === css.charAt(i - 1)) {
1163
+ return error('End of comment missing');
1164
+ }
1165
+ var str = css.slice(2, i - 2);
1166
+ column += 2;
1167
+ updatePosition(str);
1168
+ css = css.slice(i);
1169
+ column += 2;
1170
+ return pos({
1171
+ type: 'comment',
1172
+ comment: str
1173
+ });
1174
+ }
1175
+ function selector() {
1176
+ var m = match(/^([^{]+)/);
1177
+ if (!m) {
1178
+ return;
1179
+ }
1180
+ return trim(m[0])
1181
+ .replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g, '')
1182
+ .replace(/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'/g, function (m) {
1183
+ return m.replace(/,/g, '\u200C');
1184
+ })
1185
+ .split(/\s*(?![^(]*\)),\s*/)
1186
+ .map(function (s) {
1187
+ return s.replace(/\u200C/g, ',');
1188
+ });
1189
+ }
1190
+ function declaration() {
1191
+ var pos = position();
1192
+ var propMatch = match(/^(\*?[-#\/\*\\\w]+(\[[0-9a-z_-]+\])?)\s*/);
1193
+ if (!propMatch) {
1194
+ return;
1195
+ }
1196
+ var prop = trim(propMatch[0]);
1197
+ if (!match(/^:\s*/)) {
1198
+ return error("property missing ':'");
1199
+ }
1200
+ var val = match(/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^\)]*?\)|[^};])+)/);
1201
+ var ret = pos({
1202
+ type: 'declaration',
1203
+ property: prop.replace(commentre, ''),
1204
+ value: val ? trim(val[0]).replace(commentre, '') : ''
1205
+ });
1206
+ match(/^[;\s]*/);
1207
+ return ret;
1208
+ }
1209
+ function declarations() {
1210
+ var decls = [];
1211
+ if (!open()) {
1212
+ return error("missing '{'");
1213
+ }
1214
+ comments(decls);
1215
+ var decl;
1216
+ while ((decl = declaration())) {
1217
+ if (decl !== false) {
1218
+ decls.push(decl);
1219
+ comments(decls);
1220
+ }
1221
+ decl = declaration();
1222
+ }
1223
+ if (!close()) {
1224
+ return error("missing '}'");
1225
+ }
1226
+ return decls;
1227
+ }
1228
+ function keyframe() {
1229
+ var m;
1230
+ var vals = [];
1231
+ var pos = position();
1232
+ while ((m = match(/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/))) {
1233
+ vals.push(m[1]);
1234
+ match(/^,\s*/);
1235
+ }
1236
+ if (!vals.length) {
1237
+ return;
1238
+ }
1239
+ return pos({
1240
+ type: 'keyframe',
1241
+ values: vals,
1242
+ declarations: declarations()
1243
+ });
1244
+ }
1245
+ function atkeyframes() {
1246
+ var pos = position();
1247
+ var m = match(/^@([-\w]+)?keyframes\s*/);
1248
+ if (!m) {
1249
+ return;
1250
+ }
1251
+ var vendor = m[1];
1252
+ m = match(/^([-\w]+)\s*/);
1253
+ if (!m) {
1254
+ return error('@keyframes missing name');
1255
+ }
1256
+ var name = m[1];
1257
+ if (!open()) {
1258
+ return error("@keyframes missing '{'");
1259
+ }
1260
+ var frame;
1261
+ var frames = comments();
1262
+ while ((frame = keyframe())) {
1263
+ frames.push(frame);
1264
+ frames = frames.concat(comments());
1265
+ }
1266
+ if (!close()) {
1267
+ return error("@keyframes missing '}'");
1268
+ }
1269
+ return pos({
1270
+ type: 'keyframes',
1271
+ name: name,
1272
+ vendor: vendor,
1273
+ keyframes: frames
1274
+ });
1275
+ }
1276
+ function atsupports() {
1277
+ var pos = position();
1278
+ var m = match(/^@supports *([^{]+)/);
1279
+ if (!m) {
1280
+ return;
1281
+ }
1282
+ var supports = trim(m[1]);
1283
+ if (!open()) {
1284
+ return error("@supports missing '{'");
1285
+ }
1286
+ var style = comments().concat(rules());
1287
+ if (!close()) {
1288
+ return error("@supports missing '}'");
1289
+ }
1290
+ return pos({
1291
+ type: 'supports',
1292
+ supports: supports,
1293
+ rules: style
1294
+ });
1295
+ }
1296
+ function athost() {
1297
+ var pos = position();
1298
+ var m = match(/^@host\s*/);
1299
+ if (!m) {
1300
+ return;
1301
+ }
1302
+ if (!open()) {
1303
+ return error("@host missing '{'");
1304
+ }
1305
+ var style = comments().concat(rules());
1306
+ if (!close()) {
1307
+ return error("@host missing '}'");
1308
+ }
1309
+ return pos({
1310
+ type: 'host',
1311
+ rules: style
1312
+ });
1313
+ }
1314
+ function atmedia() {
1315
+ var pos = position();
1316
+ var m = match(/^@media *([^{]+)/);
1317
+ if (!m) {
1318
+ return;
1319
+ }
1320
+ var media = trim(m[1]);
1321
+ if (!open()) {
1322
+ return error("@media missing '{'");
1323
+ }
1324
+ var style = comments().concat(rules());
1325
+ if (!close()) {
1326
+ return error("@media missing '}'");
1327
+ }
1328
+ return pos({
1329
+ type: 'media',
1330
+ media: media,
1331
+ rules: style
1332
+ });
1333
+ }
1334
+ function atcustommedia() {
1335
+ var pos = position();
1336
+ var m = match(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/);
1337
+ if (!m) {
1338
+ return;
1339
+ }
1340
+ return pos({
1341
+ type: 'custom-media',
1342
+ name: trim(m[1]),
1343
+ media: trim(m[2])
1344
+ });
1345
+ }
1346
+ function atpage() {
1347
+ var pos = position();
1348
+ var m = match(/^@page */);
1349
+ if (!m) {
1350
+ return;
1351
+ }
1352
+ var sel = selector() || [];
1353
+ if (!open()) {
1354
+ return error("@page missing '{'");
1355
+ }
1356
+ var decls = comments();
1357
+ var decl;
1358
+ while ((decl = declaration())) {
1359
+ decls.push(decl);
1360
+ decls = decls.concat(comments());
1361
+ }
1362
+ if (!close()) {
1363
+ return error("@page missing '}'");
1364
+ }
1365
+ return pos({
1366
+ type: 'page',
1367
+ selectors: sel,
1368
+ declarations: decls
1369
+ });
1370
+ }
1371
+ function atdocument() {
1372
+ var pos = position();
1373
+ var m = match(/^@([-\w]+)?document *([^{]+)/);
1374
+ if (!m) {
1375
+ return;
1376
+ }
1377
+ var vendor = trim(m[1]);
1378
+ var doc = trim(m[2]);
1379
+ if (!open()) {
1380
+ return error("@document missing '{'");
1381
+ }
1382
+ var style = comments().concat(rules());
1383
+ if (!close()) {
1384
+ return error("@document missing '}'");
1385
+ }
1386
+ return pos({
1387
+ type: 'document',
1388
+ document: doc,
1389
+ vendor: vendor,
1390
+ rules: style
1391
+ });
1392
+ }
1393
+ function atfontface() {
1394
+ var pos = position();
1395
+ var m = match(/^@font-face\s*/);
1396
+ if (!m) {
1397
+ return;
1398
+ }
1399
+ if (!open()) {
1400
+ return error("@font-face missing '{'");
1401
+ }
1402
+ var decls = comments();
1403
+ var decl;
1404
+ while ((decl = declaration())) {
1405
+ decls.push(decl);
1406
+ decls = decls.concat(comments());
1407
+ }
1408
+ if (!close()) {
1409
+ return error("@font-face missing '}'");
1410
+ }
1411
+ return pos({
1412
+ type: 'font-face',
1413
+ declarations: decls
1414
+ });
1415
+ }
1416
+ var atimport = _compileAtrule('import');
1417
+ var atcharset = _compileAtrule('charset');
1418
+ var atnamespace = _compileAtrule('namespace');
1419
+ function _compileAtrule(name) {
1420
+ var re = new RegExp('^@' + name + '\\s*([^;]+);');
1421
+ return function () {
1422
+ var pos = position();
1423
+ var m = match(re);
1424
+ if (!m) {
1425
+ return;
1426
+ }
1427
+ var ret = { type: name };
1428
+ ret[name] = m[1].trim();
1429
+ return pos(ret);
1430
+ };
1431
+ }
1432
+ function atrule() {
1433
+ if (css[0] !== '@') {
1434
+ return;
1435
+ }
1436
+ return (atkeyframes() ||
1437
+ atmedia() ||
1438
+ atcustommedia() ||
1439
+ atsupports() ||
1440
+ atimport() ||
1441
+ atcharset() ||
1442
+ atnamespace() ||
1443
+ atdocument() ||
1444
+ atpage() ||
1445
+ athost() ||
1446
+ atfontface());
1447
+ }
1448
+ function rule() {
1449
+ var pos = position();
1450
+ var sel = selector();
1451
+ if (!sel) {
1452
+ return error('selector missing');
1453
+ }
1454
+ comments();
1455
+ return pos({
1456
+ type: 'rule',
1457
+ selectors: sel,
1458
+ declarations: declarations()
1459
+ });
1460
+ }
1461
+ return addParent(stylesheet());
1462
+ }
1463
+ function trim(str) {
1464
+ return str ? str.replace(/^\s+|\s+$/g, '') : '';
1465
+ }
1466
+ function addParent(obj, parent) {
1467
+ var isNode = obj && typeof obj.type === 'string';
1468
+ var childParent = isNode ? obj : parent;
1469
+ for (var _i = 0, _a = Object.keys(obj); _i < _a.length; _i++) {
1470
+ var k = _a[_i];
1471
+ var value = obj[k];
1472
+ if (Array.isArray(value)) {
1473
+ value.forEach(function (v) {
1474
+ addParent(v, childParent);
1475
+ });
1476
+ }
1477
+ else if (value && typeof value === 'object') {
1478
+ addParent(value, childParent);
1479
+ }
1480
+ }
1481
+ if (isNode) {
1482
+ Object.defineProperty(obj, 'parent', {
1483
+ configurable: true,
1484
+ writable: true,
1485
+ enumerable: false,
1486
+ value: parent || null
1487
+ });
1488
+ }
1489
+ return obj;
1491
1490
  }
1492
1491
 
1493
- var tagMap = {
1494
- script: 'noscript',
1495
- altglyph: 'altGlyph',
1496
- altglyphdef: 'altGlyphDef',
1497
- altglyphitem: 'altGlyphItem',
1498
- animatecolor: 'animateColor',
1499
- animatemotion: 'animateMotion',
1500
- animatetransform: 'animateTransform',
1501
- clippath: 'clipPath',
1502
- feblend: 'feBlend',
1503
- fecolormatrix: 'feColorMatrix',
1504
- fecomponenttransfer: 'feComponentTransfer',
1505
- fecomposite: 'feComposite',
1506
- feconvolvematrix: 'feConvolveMatrix',
1507
- fediffuselighting: 'feDiffuseLighting',
1508
- fedisplacementmap: 'feDisplacementMap',
1509
- fedistantlight: 'feDistantLight',
1510
- fedropshadow: 'feDropShadow',
1511
- feflood: 'feFlood',
1512
- fefunca: 'feFuncA',
1513
- fefuncb: 'feFuncB',
1514
- fefuncg: 'feFuncG',
1515
- fefuncr: 'feFuncR',
1516
- fegaussianblur: 'feGaussianBlur',
1517
- feimage: 'feImage',
1518
- femerge: 'feMerge',
1519
- femergenode: 'feMergeNode',
1520
- femorphology: 'feMorphology',
1521
- feoffset: 'feOffset',
1522
- fepointlight: 'fePointLight',
1523
- fespecularlighting: 'feSpecularLighting',
1524
- fespotlight: 'feSpotLight',
1525
- fetile: 'feTile',
1526
- feturbulence: 'feTurbulence',
1527
- foreignobject: 'foreignObject',
1528
- glyphref: 'glyphRef',
1529
- lineargradient: 'linearGradient',
1530
- radialgradient: 'radialGradient'
1531
- };
1532
- function getTagName(n) {
1533
- var tagName = tagMap[n.tagName] ? tagMap[n.tagName] : n.tagName;
1534
- if (tagName === 'link' && n.attributes._cssText) {
1535
- tagName = 'style';
1536
- }
1537
- return tagName;
1538
- }
1539
- function escapeRegExp(str) {
1540
- return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
1541
- }
1542
- var HOVER_SELECTOR = /([^\\]):hover/;
1543
- var HOVER_SELECTOR_GLOBAL = new RegExp(HOVER_SELECTOR.source, 'g');
1544
- function addHoverClass(cssText, cache) {
1545
- var _a;
1546
- if (!((_a = window === null || window === void 0 ? void 0 : window.HIG_CONFIGURATION) === null || _a === void 0 ? void 0 : _a.enableOnHoverClass)) {
1547
- return cssText;
1548
- }
1549
- var cachedStyle = cache === null || cache === void 0 ? void 0 : cache.stylesWithHoverClass.get(cssText);
1550
- if (cachedStyle)
1551
- return cachedStyle;
1552
- var ast = parse(cssText, {
1553
- silent: true
1554
- });
1555
- if (!ast.stylesheet) {
1556
- return cssText;
1557
- }
1558
- var selectors = [];
1559
- ast.stylesheet.rules.forEach(function (rule) {
1560
- if ('selectors' in rule) {
1561
- (rule.selectors || []).forEach(function (selector) {
1562
- if (HOVER_SELECTOR.test(selector)) {
1563
- selectors.push(selector);
1564
- }
1565
- });
1566
- }
1567
- });
1568
- if (selectors.length === 0) {
1569
- return cssText;
1570
- }
1571
- var selectorMatcher = new RegExp(selectors
1572
- .filter(function (selector, index) { return selectors.indexOf(selector) === index; })
1573
- .sort(function (a, b) { return b.length - a.length; })
1574
- .map(function (selector) {
1575
- return escapeRegExp(selector);
1576
- })
1577
- .join('|'), 'g');
1578
- var result = cssText.replace(selectorMatcher, function (selector) {
1579
- var newSelector = selector.replace(HOVER_SELECTOR_GLOBAL, '$1.\\:hover');
1580
- return selector + ", " + newSelector;
1581
- });
1582
- cache === null || cache === void 0 ? void 0 : cache.stylesWithHoverClass.set(cssText, result);
1583
- return result;
1584
- }
1585
- function createCache() {
1586
- var stylesWithHoverClass = new Map();
1587
- return {
1588
- stylesWithHoverClass: stylesWithHoverClass
1589
- };
1590
- }
1591
- function buildNode(n, options) {
1592
- var doc = options.doc, hackCss = options.hackCss, cache = options.cache;
1593
- switch (n.type) {
1594
- case NodeType$2.Document:
1595
- return doc.implementation.createDocument(null, '', null);
1596
- case NodeType$2.DocumentType:
1597
- return doc.implementation.createDocumentType(n.name || 'html', n.publicId, n.systemId);
1598
- case NodeType$2.Element:
1599
- var tagName = getTagName(n);
1600
- var node_1;
1601
- if (n.isSVG) {
1602
- node_1 = doc.createElementNS('http://www.w3.org/2000/svg', tagName);
1603
- }
1604
- else {
1605
- node_1 = doc.createElement(tagName);
1606
- }
1607
- var _loop_1 = function (name_1) {
1608
- if (!n.attributes.hasOwnProperty(name_1)) {
1609
- return "continue";
1610
- }
1611
- var value = n.attributes[name_1];
1612
- if (tagName === 'option' && name_1 === 'selected' && value === false) {
1613
- return "continue";
1614
- }
1615
- value =
1616
- typeof value === 'boolean' || typeof value === 'number' ? '' : value;
1617
- if (!name_1.startsWith('rr_')) {
1618
- var isTextarea = tagName === 'textarea' && name_1 === 'value';
1619
- var isRemoteOrDynamicCss = tagName === 'style' && name_1 === '_cssText';
1620
- if (isRemoteOrDynamicCss && hackCss) {
1621
- value = addHoverClass(value, cache);
1622
- if (typeof value === 'string') {
1623
- var regex = /url\(\"https:\/\/\S*(.eot|.woff2|.ttf|.woff)\S*\"\)/gm;
1624
- var m = void 0;
1625
- var fontUrls_1 = [];
1626
- var PROXY_URL_1 = 'https://replay-cors-proxy.highlightrun.workers.dev';
1627
- while ((m = regex.exec(value)) !== null) {
1628
- if (m.index === regex.lastIndex) {
1629
- regex.lastIndex++;
1630
- }
1631
- m.forEach(function (match, groupIndex) {
1632
- if (groupIndex === 0) {
1633
- var url = match.slice(5, match.length - 2);
1634
- fontUrls_1.push({
1635
- originalUrl: url,
1636
- proxyUrl: url.replace(url, PROXY_URL_1 + "?url=" + url)
1637
- });
1638
- }
1639
- });
1640
- }
1641
- fontUrls_1.forEach(function (urlPair) {
1642
- value = value.replace(urlPair.originalUrl, urlPair.proxyUrl);
1643
- });
1644
- }
1645
- }
1646
- if (isTextarea || isRemoteOrDynamicCss) {
1647
- var child = doc.createTextNode(value);
1648
- for (var _i = 0, _a = Array.from(node_1.childNodes); _i < _a.length; _i++) {
1649
- var c = _a[_i];
1650
- if (c.nodeType === node_1.TEXT_NODE) {
1651
- node_1.removeChild(c);
1652
- }
1653
- }
1654
- node_1.appendChild(child);
1655
- return "continue";
1656
- }
1657
- try {
1658
- if (n.isSVG && name_1 === 'xlink:href') {
1659
- node_1.setAttributeNS('http://www.w3.org/1999/xlink', name_1, value);
1660
- }
1661
- else if (name_1 === 'onload' ||
1662
- name_1 === 'onclick' ||
1663
- name_1.substring(0, 7) === 'onmouse') {
1664
- node_1.setAttribute('_' + name_1, value);
1665
- }
1666
- else if (tagName === 'meta' &&
1667
- n.attributes['http-equiv'] === 'Content-Security-Policy' &&
1668
- name_1 === 'content') {
1669
- node_1.setAttribute('csp-content', value);
1670
- return "continue";
1671
- }
1672
- else if (tagName === 'link' &&
1673
- n.attributes.rel === 'preload' &&
1674
- n.attributes.as === 'script') {
1675
- }
1676
- else if (tagName === 'link' &&
1677
- n.attributes.rel === 'prefetch' &&
1678
- typeof n.attributes.href === 'string' &&
1679
- n.attributes.href.endsWith('.js')) {
1680
- }
1681
- else if (tagName === 'img' &&
1682
- n.attributes.srcset &&
1683
- n.attributes.rr_dataURL) {
1684
- node_1.setAttribute('rrweb-original-srcset', n.attributes.srcset);
1685
- }
1686
- else {
1687
- node_1.setAttribute(name_1, value);
1688
- }
1689
- }
1690
- catch (error) {
1691
- }
1692
- }
1693
- else {
1694
- if (tagName === 'canvas' && name_1 === 'rr_dataURL') {
1695
- var image_1 = document.createElement('img');
1696
- image_1.src = value;
1697
- image_1.onload = function () {
1698
- var ctx = node_1.getContext('2d');
1699
- if (ctx) {
1700
- ctx.drawImage(image_1, 0, 0, image_1.width, image_1.height);
1701
- }
1702
- };
1703
- }
1704
- else if (tagName === 'img' && name_1 === 'rr_dataURL') {
1705
- var image = node_1;
1706
- if (!image.currentSrc.startsWith('data:')) {
1707
- image.setAttribute('rrweb-original-src', n.attributes.src);
1708
- image.src = value;
1709
- image.setAttribute('rrweb-inline-src', value);
1710
- }
1711
- }
1712
- if (name_1 === 'rr_width') {
1713
- node_1.style.width = value;
1714
- }
1715
- else if (name_1 === 'rr_height') {
1716
- node_1.style.height = value;
1717
- }
1718
- else if (name_1 === 'rr_mediaCurrentTime') {
1719
- node_1.currentTime = n.attributes
1720
- .rr_mediaCurrentTime;
1721
- }
1722
- else if (name_1 === 'rr_mediaState') {
1723
- switch (value) {
1724
- case 'played':
1725
- node_1
1726
- .play()["catch"](function (e) { return console.warn('media playback error', e); });
1727
- break;
1728
- case 'paused':
1729
- node_1.pause();
1730
- break;
1731
- }
1732
- }
1733
- }
1734
- };
1735
- for (var name_1 in n.attributes) {
1736
- _loop_1(name_1);
1737
- }
1738
- if (tagName === 'img') {
1739
- var image = node_1;
1740
- if (!image.currentSrc.startsWith('data:')) {
1741
- var inlineSrc = image.getAttribute('rrweb-inline-src');
1742
- if (inlineSrc === null || inlineSrc === void 0 ? void 0 : inlineSrc.startsWith('data:')) {
1743
- image.src = inlineSrc;
1744
- }
1745
- }
1746
- }
1747
- if (n.isShadowHost) {
1748
- if (!node_1.shadowRoot) {
1749
- node_1.attachShadow({ mode: 'open' });
1750
- }
1751
- else {
1752
- while (node_1.shadowRoot.firstChild) {
1753
- node_1.shadowRoot.removeChild(node_1.shadowRoot.firstChild);
1754
- }
1755
- }
1756
- }
1757
- return node_1;
1758
- case NodeType$2.Text:
1759
- return doc.createTextNode(n.isStyle && hackCss
1760
- ? addHoverClass(n.textContent, cache)
1761
- : n.textContent);
1762
- case NodeType$2.CDATA:
1763
- return doc.createCDATASection(n.textContent);
1764
- case NodeType$2.Comment:
1765
- return doc.createComment(n.textContent);
1766
- default:
1767
- return null;
1768
- }
1769
- }
1770
- function buildNodeWithSN(n, options) {
1771
- var doc = options.doc, mirror = options.mirror, _a = options.skipChild, skipChild = _a === void 0 ? false : _a, _b = options.hackCss, hackCss = _b === void 0 ? true : _b, afterAppend = options.afterAppend, cache = options.cache;
1772
- var node = buildNode(n, { doc: doc, hackCss: hackCss, cache: cache });
1773
- if (!node) {
1774
- return null;
1775
- }
1776
- if (n.rootId) {
1777
- console.assert(mirror.getNode(n.rootId) === doc, 'Target document should have the same root id.');
1778
- }
1779
- if (n.type === NodeType$2.Document) {
1780
- doc.close();
1781
- doc.open();
1782
- if (n.compatMode === 'BackCompat' &&
1783
- n.childNodes &&
1784
- n.childNodes[0].type !== NodeType$2.DocumentType) {
1785
- if (n.childNodes[0].type === NodeType$2.Element &&
1786
- 'xmlns' in n.childNodes[0].attributes &&
1787
- n.childNodes[0].attributes.xmlns === 'http://www.w3.org/1999/xhtml') {
1788
- doc.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">');
1789
- }
1790
- else {
1791
- doc.write('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "">');
1792
- }
1793
- }
1794
- node = doc;
1795
- }
1796
- mirror.add(node, n);
1797
- if ((n.type === NodeType$2.Document || n.type === NodeType$2.Element) &&
1798
- !skipChild) {
1799
- for (var _i = 0, _c = n.childNodes; _i < _c.length; _i++) {
1800
- var childN = _c[_i];
1801
- var childNode = buildNodeWithSN(childN, {
1802
- doc: doc,
1803
- mirror: mirror,
1804
- skipChild: false,
1805
- hackCss: hackCss,
1806
- afterAppend: afterAppend,
1807
- cache: cache
1808
- });
1809
- if (!childNode) {
1810
- console.warn('Failed to rebuild', childN);
1811
- continue;
1812
- }
1813
- if (childN.isShadow && isElement(node) && node.shadowRoot) {
1814
- node.shadowRoot.appendChild(childNode);
1815
- }
1816
- else {
1817
- node.appendChild(childNode);
1818
- }
1819
- if (afterAppend) {
1820
- afterAppend(childNode);
1821
- }
1822
- }
1823
- }
1824
- return node;
1825
- }
1826
- function visit(mirror, onVisit) {
1827
- function walk(node) {
1828
- onVisit(node);
1829
- }
1830
- for (var _i = 0, _a = mirror.getIds(); _i < _a.length; _i++) {
1831
- var id = _a[_i];
1832
- if (mirror.has(id)) {
1833
- walk(mirror.getNode(id));
1834
- }
1835
- }
1836
- }
1837
- function handleScroll(node, mirror) {
1838
- var n = mirror.getMeta(node);
1839
- if ((n === null || n === void 0 ? void 0 : n.type) !== NodeType$2.Element) {
1840
- return;
1841
- }
1842
- var el = node;
1843
- for (var name_2 in n.attributes) {
1844
- if (!(n.attributes.hasOwnProperty(name_2) && name_2.startsWith('rr_'))) {
1845
- continue;
1846
- }
1847
- var value = n.attributes[name_2];
1848
- if (name_2 === 'rr_scrollLeft') {
1849
- el.scrollLeft = value;
1850
- }
1851
- if (name_2 === 'rr_scrollTop') {
1852
- el.scrollTop = value;
1853
- }
1854
- }
1855
- }
1856
- function rebuild(n, options) {
1857
- var doc = options.doc, onVisit = options.onVisit, _a = options.hackCss, hackCss = _a === void 0 ? true : _a, afterAppend = options.afterAppend, cache = options.cache, _b = options.mirror, mirror = _b === void 0 ? new Mirror$2() : _b;
1858
- var node = buildNodeWithSN(n, {
1859
- doc: doc,
1860
- mirror: mirror,
1861
- skipChild: false,
1862
- hackCss: hackCss,
1863
- afterAppend: afterAppend,
1864
- cache: cache
1865
- });
1866
- visit(mirror, function (visitedNode) {
1867
- if (onVisit) {
1868
- onVisit(visitedNode);
1869
- }
1870
- handleScroll(visitedNode, mirror);
1871
- });
1872
- return node;
1492
+ var tagMap = {
1493
+ script: 'noscript',
1494
+ altglyph: 'altGlyph',
1495
+ altglyphdef: 'altGlyphDef',
1496
+ altglyphitem: 'altGlyphItem',
1497
+ animatecolor: 'animateColor',
1498
+ animatemotion: 'animateMotion',
1499
+ animatetransform: 'animateTransform',
1500
+ clippath: 'clipPath',
1501
+ feblend: 'feBlend',
1502
+ fecolormatrix: 'feColorMatrix',
1503
+ fecomponenttransfer: 'feComponentTransfer',
1504
+ fecomposite: 'feComposite',
1505
+ feconvolvematrix: 'feConvolveMatrix',
1506
+ fediffuselighting: 'feDiffuseLighting',
1507
+ fedisplacementmap: 'feDisplacementMap',
1508
+ fedistantlight: 'feDistantLight',
1509
+ fedropshadow: 'feDropShadow',
1510
+ feflood: 'feFlood',
1511
+ fefunca: 'feFuncA',
1512
+ fefuncb: 'feFuncB',
1513
+ fefuncg: 'feFuncG',
1514
+ fefuncr: 'feFuncR',
1515
+ fegaussianblur: 'feGaussianBlur',
1516
+ feimage: 'feImage',
1517
+ femerge: 'feMerge',
1518
+ femergenode: 'feMergeNode',
1519
+ femorphology: 'feMorphology',
1520
+ feoffset: 'feOffset',
1521
+ fepointlight: 'fePointLight',
1522
+ fespecularlighting: 'feSpecularLighting',
1523
+ fespotlight: 'feSpotLight',
1524
+ fetile: 'feTile',
1525
+ feturbulence: 'feTurbulence',
1526
+ foreignobject: 'foreignObject',
1527
+ glyphref: 'glyphRef',
1528
+ lineargradient: 'linearGradient',
1529
+ radialgradient: 'radialGradient'
1530
+ };
1531
+ function getTagName(n) {
1532
+ var tagName = tagMap[n.tagName] ? tagMap[n.tagName] : n.tagName;
1533
+ if (tagName === 'link' && n.attributes._cssText) {
1534
+ tagName = 'style';
1535
+ }
1536
+ return tagName;
1537
+ }
1538
+ function escapeRegExp(str) {
1539
+ return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
1540
+ }
1541
+ var HOVER_SELECTOR = /([^\\]):hover/;
1542
+ var HOVER_SELECTOR_GLOBAL = new RegExp(HOVER_SELECTOR.source, 'g');
1543
+ function addHoverClass(cssText, cache) {
1544
+ var _a;
1545
+ if (!((_a = window === null || window === void 0 ? void 0 : window.HIG_CONFIGURATION) === null || _a === void 0 ? void 0 : _a.enableOnHoverClass)) {
1546
+ return cssText;
1547
+ }
1548
+ var cachedStyle = cache === null || cache === void 0 ? void 0 : cache.stylesWithHoverClass.get(cssText);
1549
+ if (cachedStyle)
1550
+ return cachedStyle;
1551
+ var ast = parse(cssText, {
1552
+ silent: true
1553
+ });
1554
+ if (!ast.stylesheet) {
1555
+ return cssText;
1556
+ }
1557
+ var selectors = [];
1558
+ ast.stylesheet.rules.forEach(function (rule) {
1559
+ if ('selectors' in rule) {
1560
+ (rule.selectors || []).forEach(function (selector) {
1561
+ if (HOVER_SELECTOR.test(selector)) {
1562
+ selectors.push(selector);
1563
+ }
1564
+ });
1565
+ }
1566
+ });
1567
+ if (selectors.length === 0) {
1568
+ return cssText;
1569
+ }
1570
+ var selectorMatcher = new RegExp(selectors
1571
+ .filter(function (selector, index) { return selectors.indexOf(selector) === index; })
1572
+ .sort(function (a, b) { return b.length - a.length; })
1573
+ .map(function (selector) {
1574
+ return escapeRegExp(selector);
1575
+ })
1576
+ .join('|'), 'g');
1577
+ var result = cssText.replace(selectorMatcher, function (selector) {
1578
+ var newSelector = selector.replace(HOVER_SELECTOR_GLOBAL, '$1.\\:hover');
1579
+ return "".concat(selector, ", ").concat(newSelector);
1580
+ });
1581
+ cache === null || cache === void 0 ? void 0 : cache.stylesWithHoverClass.set(cssText, result);
1582
+ return result;
1583
+ }
1584
+ function createCache() {
1585
+ var stylesWithHoverClass = new Map();
1586
+ return {
1587
+ stylesWithHoverClass: stylesWithHoverClass
1588
+ };
1589
+ }
1590
+ function buildNode(n, options) {
1591
+ var doc = options.doc, hackCss = options.hackCss, cache = options.cache;
1592
+ switch (n.type) {
1593
+ case NodeType$2.Document:
1594
+ return doc.implementation.createDocument(null, '', null);
1595
+ case NodeType$2.DocumentType:
1596
+ return doc.implementation.createDocumentType(n.name || 'html', n.publicId, n.systemId);
1597
+ case NodeType$2.Element:
1598
+ var tagName = getTagName(n);
1599
+ var node_1;
1600
+ if (n.isSVG) {
1601
+ node_1 = doc.createElementNS('http://www.w3.org/2000/svg', tagName);
1602
+ }
1603
+ else {
1604
+ node_1 = doc.createElement(tagName);
1605
+ }
1606
+ var _loop_1 = function (name_1) {
1607
+ if (!n.attributes.hasOwnProperty(name_1)) {
1608
+ return "continue";
1609
+ }
1610
+ var value = n.attributes[name_1];
1611
+ if (tagName === 'option' && name_1 === 'selected' && value === false) {
1612
+ return "continue";
1613
+ }
1614
+ value =
1615
+ typeof value === 'boolean' || typeof value === 'number' ? '' : value;
1616
+ if (!name_1.startsWith('rr_')) {
1617
+ var isTextarea = tagName === 'textarea' && name_1 === 'value';
1618
+ var isRemoteOrDynamicCss = tagName === 'style' && name_1 === '_cssText';
1619
+ if (isRemoteOrDynamicCss && hackCss) {
1620
+ value = addHoverClass(value, cache);
1621
+ if (typeof value === 'string') {
1622
+ var regex = /url\(\"https:\/\/\S*(.eot|.woff2|.ttf|.woff)\S*\"\)/gm;
1623
+ var m = void 0;
1624
+ var fontUrls_1 = [];
1625
+ var PROXY_URL_1 = 'https://replay-cors-proxy.highlightrun.workers.dev';
1626
+ while ((m = regex.exec(value)) !== null) {
1627
+ if (m.index === regex.lastIndex) {
1628
+ regex.lastIndex++;
1629
+ }
1630
+ m.forEach(function (match, groupIndex) {
1631
+ if (groupIndex === 0) {
1632
+ var url = match.slice(5, match.length - 2);
1633
+ fontUrls_1.push({
1634
+ originalUrl: url,
1635
+ proxyUrl: url.replace(url, "".concat(PROXY_URL_1, "?url=").concat(url))
1636
+ });
1637
+ }
1638
+ });
1639
+ }
1640
+ fontUrls_1.forEach(function (urlPair) {
1641
+ value = value.replace(urlPair.originalUrl, urlPair.proxyUrl);
1642
+ });
1643
+ }
1644
+ }
1645
+ if (isTextarea || isRemoteOrDynamicCss) {
1646
+ var child = doc.createTextNode(value);
1647
+ for (var _i = 0, _a = Array.from(node_1.childNodes); _i < _a.length; _i++) {
1648
+ var c = _a[_i];
1649
+ if (c.nodeType === node_1.TEXT_NODE) {
1650
+ node_1.removeChild(c);
1651
+ }
1652
+ }
1653
+ node_1.appendChild(child);
1654
+ return "continue";
1655
+ }
1656
+ try {
1657
+ if (n.isSVG && name_1 === 'xlink:href') {
1658
+ node_1.setAttributeNS('http://www.w3.org/1999/xlink', name_1, value);
1659
+ }
1660
+ else if (name_1 === 'onload' ||
1661
+ name_1 === 'onclick' ||
1662
+ name_1.substring(0, 7) === 'onmouse') {
1663
+ node_1.setAttribute('_' + name_1, value);
1664
+ }
1665
+ else if (tagName === 'meta' &&
1666
+ n.attributes['http-equiv'] === 'Content-Security-Policy' &&
1667
+ name_1 === 'content') {
1668
+ node_1.setAttribute('csp-content', value);
1669
+ return "continue";
1670
+ }
1671
+ else if (tagName === 'link' &&
1672
+ n.attributes.rel === 'preload' &&
1673
+ n.attributes.as === 'script') {
1674
+ }
1675
+ else if (tagName === 'link' &&
1676
+ n.attributes.rel === 'prefetch' &&
1677
+ typeof n.attributes.href === 'string' &&
1678
+ n.attributes.href.endsWith('.js')) {
1679
+ }
1680
+ else if (tagName === 'img' &&
1681
+ n.attributes.srcset &&
1682
+ n.attributes.rr_dataURL) {
1683
+ node_1.setAttribute('rrweb-original-srcset', n.attributes.srcset);
1684
+ }
1685
+ else {
1686
+ node_1.setAttribute(name_1, value);
1687
+ }
1688
+ }
1689
+ catch (error) {
1690
+ }
1691
+ }
1692
+ else {
1693
+ if (tagName === 'canvas' && name_1 === 'rr_dataURL') {
1694
+ var image_1 = document.createElement('img');
1695
+ image_1.src = value;
1696
+ image_1.onload = function () {
1697
+ var ctx = node_1.getContext('2d');
1698
+ if (ctx) {
1699
+ ctx.drawImage(image_1, 0, 0, image_1.width, image_1.height);
1700
+ }
1701
+ };
1702
+ }
1703
+ else if (tagName === 'img' && name_1 === 'rr_dataURL') {
1704
+ var image = node_1;
1705
+ if (!image.currentSrc.startsWith('data:')) {
1706
+ image.setAttribute('rrweb-original-src', n.attributes.src);
1707
+ image.src = value;
1708
+ image.setAttribute('rrweb-inline-src', value);
1709
+ }
1710
+ }
1711
+ if (name_1 === 'rr_width') {
1712
+ node_1.style.width = value;
1713
+ }
1714
+ else if (name_1 === 'rr_height') {
1715
+ node_1.style.height = value;
1716
+ }
1717
+ else if (name_1 === 'rr_mediaCurrentTime') {
1718
+ node_1.currentTime = n.attributes
1719
+ .rr_mediaCurrentTime;
1720
+ }
1721
+ else if (name_1 === 'rr_mediaState') {
1722
+ switch (value) {
1723
+ case 'played':
1724
+ node_1
1725
+ .play()["catch"](function (e) { return console.warn('media playback error', e); });
1726
+ break;
1727
+ case 'paused':
1728
+ node_1.pause();
1729
+ break;
1730
+ }
1731
+ }
1732
+ }
1733
+ };
1734
+ for (var name_1 in n.attributes) {
1735
+ _loop_1(name_1);
1736
+ }
1737
+ if (tagName === 'img') {
1738
+ var image = node_1;
1739
+ if (!image.currentSrc.startsWith('data:')) {
1740
+ var inlineSrc = image.getAttribute('rrweb-inline-src');
1741
+ if (inlineSrc === null || inlineSrc === void 0 ? void 0 : inlineSrc.startsWith('data:')) {
1742
+ image.src = inlineSrc;
1743
+ }
1744
+ }
1745
+ }
1746
+ if (n.isShadowHost) {
1747
+ if (!node_1.shadowRoot) {
1748
+ node_1.attachShadow({ mode: 'open' });
1749
+ }
1750
+ else {
1751
+ while (node_1.shadowRoot.firstChild) {
1752
+ node_1.shadowRoot.removeChild(node_1.shadowRoot.firstChild);
1753
+ }
1754
+ }
1755
+ }
1756
+ return node_1;
1757
+ case NodeType$2.Text:
1758
+ return doc.createTextNode(n.isStyle && hackCss
1759
+ ? addHoverClass(n.textContent, cache)
1760
+ : n.textContent);
1761
+ case NodeType$2.CDATA:
1762
+ return doc.createCDATASection(n.textContent);
1763
+ case NodeType$2.Comment:
1764
+ return doc.createComment(n.textContent);
1765
+ default:
1766
+ return null;
1767
+ }
1768
+ }
1769
+ function buildNodeWithSN(n, options) {
1770
+ var doc = options.doc, mirror = options.mirror, _a = options.skipChild, skipChild = _a === void 0 ? false : _a, _b = options.hackCss, hackCss = _b === void 0 ? true : _b, afterAppend = options.afterAppend, cache = options.cache;
1771
+ var node = buildNode(n, { doc: doc, hackCss: hackCss, cache: cache });
1772
+ if (!node) {
1773
+ return null;
1774
+ }
1775
+ if (n.rootId) {
1776
+ console.assert(mirror.getNode(n.rootId) === doc, 'Target document should have the same root id.');
1777
+ }
1778
+ if (n.type === NodeType$2.Document) {
1779
+ doc.close();
1780
+ doc.open();
1781
+ if (n.compatMode === 'BackCompat' &&
1782
+ n.childNodes &&
1783
+ n.childNodes[0].type !== NodeType$2.DocumentType) {
1784
+ if (n.childNodes[0].type === NodeType$2.Element &&
1785
+ 'xmlns' in n.childNodes[0].attributes &&
1786
+ n.childNodes[0].attributes.xmlns === 'http://www.w3.org/1999/xhtml') {
1787
+ doc.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">');
1788
+ }
1789
+ else {
1790
+ doc.write('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "">');
1791
+ }
1792
+ }
1793
+ node = doc;
1794
+ }
1795
+ mirror.add(node, n);
1796
+ if ((n.type === NodeType$2.Document || n.type === NodeType$2.Element) &&
1797
+ !skipChild) {
1798
+ for (var _i = 0, _c = n.childNodes; _i < _c.length; _i++) {
1799
+ var childN = _c[_i];
1800
+ var childNode = buildNodeWithSN(childN, {
1801
+ doc: doc,
1802
+ mirror: mirror,
1803
+ skipChild: false,
1804
+ hackCss: hackCss,
1805
+ afterAppend: afterAppend,
1806
+ cache: cache
1807
+ });
1808
+ if (!childNode) {
1809
+ console.warn('Failed to rebuild', childN);
1810
+ continue;
1811
+ }
1812
+ if (childN.isShadow && isElement(node) && node.shadowRoot) {
1813
+ node.shadowRoot.appendChild(childNode);
1814
+ }
1815
+ else {
1816
+ node.appendChild(childNode);
1817
+ }
1818
+ if (afterAppend) {
1819
+ afterAppend(childNode);
1820
+ }
1821
+ }
1822
+ }
1823
+ return node;
1824
+ }
1825
+ function visit(mirror, onVisit) {
1826
+ function walk(node) {
1827
+ onVisit(node);
1828
+ }
1829
+ for (var _i = 0, _a = mirror.getIds(); _i < _a.length; _i++) {
1830
+ var id = _a[_i];
1831
+ if (mirror.has(id)) {
1832
+ walk(mirror.getNode(id));
1833
+ }
1834
+ }
1835
+ }
1836
+ function handleScroll(node, mirror) {
1837
+ var n = mirror.getMeta(node);
1838
+ if ((n === null || n === void 0 ? void 0 : n.type) !== NodeType$2.Element) {
1839
+ return;
1840
+ }
1841
+ var el = node;
1842
+ for (var name_2 in n.attributes) {
1843
+ if (!(n.attributes.hasOwnProperty(name_2) && name_2.startsWith('rr_'))) {
1844
+ continue;
1845
+ }
1846
+ var value = n.attributes[name_2];
1847
+ if (name_2 === 'rr_scrollLeft') {
1848
+ el.scrollLeft = value;
1849
+ }
1850
+ if (name_2 === 'rr_scrollTop') {
1851
+ el.scrollTop = value;
1852
+ }
1853
+ }
1854
+ }
1855
+ function rebuild(n, options) {
1856
+ var doc = options.doc, onVisit = options.onVisit, _a = options.hackCss, hackCss = _a === void 0 ? true : _a, afterAppend = options.afterAppend, cache = options.cache, _b = options.mirror, mirror = _b === void 0 ? new Mirror$2() : _b;
1857
+ var node = buildNodeWithSN(n, {
1858
+ doc: doc,
1859
+ mirror: mirror,
1860
+ skipChild: false,
1861
+ hackCss: hackCss,
1862
+ afterAppend: afterAppend,
1863
+ cache: cache
1864
+ });
1865
+ visit(mirror, function (visitedNode) {
1866
+ if (onVisit) {
1867
+ onVisit(visitedNode);
1868
+ }
1869
+ handleScroll(visitedNode, mirror);
1870
+ });
1871
+ return node;
1873
1872
  }
1874
1873
 
1875
1874
  function on(type, fn, target = document) {
@@ -2582,6 +2581,16 @@ class MutationBuffer {
2582
2581
  return;
2583
2582
  }
2584
2583
  let item = this.attributes.find((a) => a.node === m.target);
2584
+ if (target.tagName === 'IFRAME' &&
2585
+ m.attributeName === 'src' &&
2586
+ !this.keepIframeSrcFn(value)) {
2587
+ if (!target.contentDocument) {
2588
+ m.attributeName = 'rr_src';
2589
+ }
2590
+ else {
2591
+ return;
2592
+ }
2593
+ }
2585
2594
  if (!item) {
2586
2595
  item = {
2587
2596
  node: m.target,
@@ -2627,7 +2636,7 @@ class MutationBuffer {
2627
2636
  break;
2628
2637
  }
2629
2638
  }
2630
- item.attributes[m.attributeName] = transformAttribute(this.doc, m.target.tagName, m.attributeName, value);
2639
+ item.attributes[m.attributeName] = transformAttribute(this.doc, target.tagName, m.attributeName, value);
2631
2640
  }
2632
2641
  break;
2633
2642
  }
@@ -2701,6 +2710,7 @@ class MutationBuffer {
2701
2710
  'maskInputOptions',
2702
2711
  'maskTextFn',
2703
2712
  'maskInputFn',
2713
+ 'keepIframeSrcFn',
2704
2714
  'recordCanvas',
2705
2715
  'inlineImages',
2706
2716
  'slimDOMOptions',
@@ -4160,6 +4170,7 @@ function record(options = {}) {
4160
4170
  iframeManager,
4161
4171
  stylesheetManager,
4162
4172
  canvasManager,
4173
+ keepIframeSrcFn,
4163
4174
  enableStrictPrivacy
4164
4175
  },
4165
4176
  mirror,
@@ -4296,6 +4307,7 @@ function record(options = {}) {
4296
4307
  doc,
4297
4308
  maskInputFn,
4298
4309
  maskTextFn,
4310
+ keepIframeSrcFn,
4299
4311
  blockSelector,
4300
4312
  slimDOMOptions,
4301
4313
  mirror,
@@ -4368,68 +4380,68 @@ record.takeFullSnapshot = (isCheckout) => {
4368
4380
  };
4369
4381
  record.mirror = mirror;
4370
4382
 
4371
- var NodeType$1;
4372
- (function (NodeType) {
4373
- NodeType[NodeType["Document"] = 0] = "Document";
4374
- NodeType[NodeType["DocumentType"] = 1] = "DocumentType";
4375
- NodeType[NodeType["Element"] = 2] = "Element";
4376
- NodeType[NodeType["Text"] = 3] = "Text";
4377
- NodeType[NodeType["CDATA"] = 4] = "CDATA";
4378
- NodeType[NodeType["Comment"] = 5] = "Comment";
4383
+ var NodeType$1;
4384
+ (function (NodeType) {
4385
+ NodeType[NodeType["Document"] = 0] = "Document";
4386
+ NodeType[NodeType["DocumentType"] = 1] = "DocumentType";
4387
+ NodeType[NodeType["Element"] = 2] = "Element";
4388
+ NodeType[NodeType["Text"] = 3] = "Text";
4389
+ NodeType[NodeType["CDATA"] = 4] = "CDATA";
4390
+ NodeType[NodeType["Comment"] = 5] = "Comment";
4379
4391
  })(NodeType$1 || (NodeType$1 = {}));
4380
- var Mirror$1 = (function () {
4381
- function Mirror() {
4382
- this.idNodeMap = new Map();
4383
- this.nodeMetaMap = new WeakMap();
4384
- }
4385
- Mirror.prototype.getId = function (n) {
4386
- var _a;
4387
- if (!n)
4388
- return -1;
4389
- var id = (_a = this.getMeta(n)) === null || _a === void 0 ? void 0 : _a.id;
4390
- return id !== null && id !== void 0 ? id : -1;
4391
- };
4392
- Mirror.prototype.getNode = function (id) {
4393
- return this.idNodeMap.get(id) || null;
4394
- };
4395
- Mirror.prototype.getIds = function () {
4396
- return Array.from(this.idNodeMap.keys());
4397
- };
4398
- Mirror.prototype.getMeta = function (n) {
4399
- return this.nodeMetaMap.get(n) || null;
4400
- };
4401
- Mirror.prototype.removeNodeFromMap = function (n) {
4402
- var _this = this;
4403
- var id = this.getId(n);
4404
- this.idNodeMap["delete"](id);
4405
- if (n.childNodes) {
4406
- n.childNodes.forEach(function (childNode) {
4407
- return _this.removeNodeFromMap(childNode);
4408
- });
4409
- }
4410
- };
4411
- Mirror.prototype.has = function (id) {
4412
- return this.idNodeMap.has(id);
4413
- };
4414
- Mirror.prototype.hasNode = function (node) {
4415
- return this.nodeMetaMap.has(node);
4416
- };
4417
- Mirror.prototype.add = function (n, meta) {
4418
- var id = meta.id;
4419
- this.idNodeMap.set(id, n);
4420
- this.nodeMetaMap.set(n, meta);
4421
- };
4422
- Mirror.prototype.replace = function (id, n) {
4423
- this.idNodeMap.set(id, n);
4424
- };
4425
- Mirror.prototype.reset = function () {
4426
- this.idNodeMap = new Map();
4427
- this.nodeMetaMap = new WeakMap();
4428
- };
4429
- return Mirror;
4430
- }());
4431
- function createMirror$1() {
4432
- return new Mirror$1();
4392
+ var Mirror$1 = (function () {
4393
+ function Mirror() {
4394
+ this.idNodeMap = new Map();
4395
+ this.nodeMetaMap = new WeakMap();
4396
+ }
4397
+ Mirror.prototype.getId = function (n) {
4398
+ var _a;
4399
+ if (!n)
4400
+ return -1;
4401
+ var id = (_a = this.getMeta(n)) === null || _a === void 0 ? void 0 : _a.id;
4402
+ return id !== null && id !== void 0 ? id : -1;
4403
+ };
4404
+ Mirror.prototype.getNode = function (id) {
4405
+ return this.idNodeMap.get(id) || null;
4406
+ };
4407
+ Mirror.prototype.getIds = function () {
4408
+ return Array.from(this.idNodeMap.keys());
4409
+ };
4410
+ Mirror.prototype.getMeta = function (n) {
4411
+ return this.nodeMetaMap.get(n) || null;
4412
+ };
4413
+ Mirror.prototype.removeNodeFromMap = function (n) {
4414
+ var _this = this;
4415
+ var id = this.getId(n);
4416
+ this.idNodeMap["delete"](id);
4417
+ if (n.childNodes) {
4418
+ n.childNodes.forEach(function (childNode) {
4419
+ return _this.removeNodeFromMap(childNode);
4420
+ });
4421
+ }
4422
+ };
4423
+ Mirror.prototype.has = function (id) {
4424
+ return this.idNodeMap.has(id);
4425
+ };
4426
+ Mirror.prototype.hasNode = function (node) {
4427
+ return this.nodeMetaMap.has(node);
4428
+ };
4429
+ Mirror.prototype.add = function (n, meta) {
4430
+ var id = meta.id;
4431
+ this.idNodeMap.set(id, n);
4432
+ this.nodeMetaMap.set(n, meta);
4433
+ };
4434
+ Mirror.prototype.replace = function (id, n) {
4435
+ this.idNodeMap.set(id, n);
4436
+ };
4437
+ Mirror.prototype.reset = function () {
4438
+ this.idNodeMap = new Map();
4439
+ this.nodeMetaMap = new WeakMap();
4440
+ };
4441
+ return Mirror;
4442
+ }());
4443
+ function createMirror$1() {
4444
+ return new Mirror$1();
4433
4445
  }
4434
4446
 
4435
4447
  function parseCSSText(cssText) {
@@ -4999,43 +5011,45 @@ function diffChildren(oldChildren, newChildren, parentNode, replayer, rrnodeMirr
4999
5011
  let oldStartNode = oldChildren[oldStartIndex], oldEndNode = oldChildren[oldEndIndex], newStartNode = newChildren[newStartIndex], newEndNode = newChildren[newEndIndex];
5000
5012
  let oldIdToIndex = undefined, indexInOld;
5001
5013
  while (oldStartIndex <= oldEndIndex && newStartIndex <= newEndIndex) {
5014
+ const oldStartId = replayer.mirror.getId(oldStartNode);
5015
+ const oldEndId = replayer.mirror.getId(oldEndNode);
5016
+ const newStartId = rrnodeMirror.getId(newStartNode);
5017
+ const newEndId = rrnodeMirror.getId(newEndNode);
5018
+ console.log('oldStartId', oldStartId);
5019
+ console.log('oldEndId', oldEndId);
5020
+ console.log('newStartId', newStartId);
5021
+ console.log('newEndId', newEndId);
5002
5022
  if (oldStartNode === undefined) {
5003
5023
  oldStartNode = oldChildren[++oldStartIndex];
5004
5024
  }
5005
5025
  else if (oldEndNode === undefined) {
5006
5026
  oldEndNode = oldChildren[--oldEndIndex];
5007
5027
  }
5008
- else if (replayer.mirror.getId(oldStartNode) === rrnodeMirror.getId(newStartNode)) {
5028
+ else if (oldStartId !== -1 &&
5029
+ oldStartId === newStartId) {
5009
5030
  diff(oldStartNode, newStartNode, replayer, rrnodeMirror);
5010
5031
  oldStartNode = oldChildren[++oldStartIndex];
5011
5032
  newStartNode = newChildren[++newStartIndex];
5012
5033
  }
5013
- else if (replayer.mirror.getId(oldEndNode) === rrnodeMirror.getId(newEndNode)) {
5034
+ else if (oldEndId !== -1 &&
5035
+ oldEndId === newEndId) {
5014
5036
  diff(oldEndNode, newEndNode, replayer, rrnodeMirror);
5015
5037
  oldEndNode = oldChildren[--oldEndIndex];
5016
5038
  newEndNode = newChildren[--newEndIndex];
5017
5039
  }
5018
- else if (replayer.mirror.getId(oldStartNode) === rrnodeMirror.getId(newEndNode)) {
5019
- try {
5020
- parentNode.insertBefore(oldStartNode, oldEndNode.nextSibling);
5021
- diff(oldStartNode, newEndNode, replayer, rrnodeMirror);
5022
- oldStartNode = oldChildren[++oldStartIndex];
5023
- newEndNode = newChildren[--newEndIndex];
5024
- }
5025
- catch (e) {
5026
- console.error(e, parentNode, oldStartNode, oldEndNode);
5027
- }
5040
+ else if (oldStartId !== -1 &&
5041
+ oldStartId === newEndId) {
5042
+ parentNode.insertBefore(oldStartNode, oldEndNode.nextSibling);
5043
+ diff(oldStartNode, newEndNode, replayer, rrnodeMirror);
5044
+ oldStartNode = oldChildren[++oldStartIndex];
5045
+ newEndNode = newChildren[--newEndIndex];
5028
5046
  }
5029
- else if (replayer.mirror.getId(oldEndNode) === rrnodeMirror.getId(newStartNode)) {
5030
- try {
5031
- parentNode.insertBefore(oldEndNode, oldStartNode);
5032
- diff(oldEndNode, newStartNode, replayer, rrnodeMirror);
5033
- oldEndNode = oldChildren[--oldEndIndex];
5034
- newStartNode = newChildren[++newStartIndex];
5035
- }
5036
- catch (e) {
5037
- console.error(e, parentNode, oldEndNode, oldStartNode);
5038
- }
5047
+ else if (oldEndId !== -1 &&
5048
+ oldEndId === newStartId) {
5049
+ parentNode.insertBefore(oldEndNode, oldStartNode);
5050
+ diff(oldEndNode, newStartNode, replayer, rrnodeMirror);
5051
+ oldEndNode = oldChildren[--oldEndIndex];
5052
+ newStartNode = newChildren[++newStartIndex];
5039
5053
  }
5040
5054
  else {
5041
5055
  if (!oldIdToIndex) {
@@ -5049,14 +5063,9 @@ function diffChildren(oldChildren, newChildren, parentNode, replayer, rrnodeMirr
5049
5063
  indexInOld = oldIdToIndex[rrnodeMirror.getId(newStartNode)];
5050
5064
  if (indexInOld) {
5051
5065
  const nodeToMove = oldChildren[indexInOld];
5052
- try {
5053
- parentNode.insertBefore(nodeToMove, oldStartNode);
5054
- diff(nodeToMove, newStartNode, replayer, rrnodeMirror);
5055
- oldChildren[indexInOld] = undefined;
5056
- }
5057
- catch (e) {
5058
- console.error(e, parentNode, nodeToMove, oldStartNode);
5059
- }
5066
+ parentNode.insertBefore(nodeToMove, oldStartNode);
5067
+ diff(nodeToMove, newStartNode, replayer, rrnodeMirror);
5068
+ oldChildren[indexInOld] = undefined;
5060
5069
  }
5061
5070
  else {
5062
5071
  const newNode = createOrGetNode(newStartNode, replayer.mirror, rrnodeMirror);
@@ -5067,13 +5076,8 @@ function diffChildren(oldChildren, newChildren, parentNode, replayer, rrnodeMirr
5067
5076
  oldChildren[oldStartIndex] = undefined;
5068
5077
  oldStartNode = undefined;
5069
5078
  }
5070
- try {
5071
- parentNode.insertBefore(newNode, oldStartNode || null);
5072
- diff(newNode, newStartNode, replayer, rrnodeMirror);
5073
- }
5074
- catch (e) {
5075
- console.error(e, parentNode, newNode, oldStartNode || null);
5076
- }
5079
+ parentNode.insertBefore(newNode, oldStartNode || null);
5080
+ diff(newNode, newStartNode, replayer, rrnodeMirror);
5077
5081
  }
5078
5082
  newStartNode = newChildren[++newStartIndex];
5079
5083
  }
@@ -5088,13 +5092,8 @@ function diffChildren(oldChildren, newChildren, parentNode, replayer, rrnodeMirr
5088
5092
  });
5089
5093
  for (; newStartIndex <= newEndIndex; ++newStartIndex) {
5090
5094
  const newNode = createOrGetNode(newChildren[newStartIndex], replayer.mirror, rrnodeMirror);
5091
- try {
5092
- parentNode.insertBefore(newNode, referenceNode);
5093
- diff(newNode, newChildren[newStartIndex], replayer, rrnodeMirror);
5094
- }
5095
- catch (e) {
5096
- console.error(e, parentNode, newNode, referenceNode);
5097
- }
5095
+ parentNode.insertBefore(newNode, referenceNode);
5096
+ diff(newNode, newChildren[newStartIndex], replayer, rrnodeMirror);
5098
5097
  }
5099
5098
  }
5100
5099
  else if (newStartIndex > newEndIndex) {
@@ -5108,8 +5107,11 @@ function diffChildren(oldChildren, newChildren, parentNode, replayer, rrnodeMirr
5108
5107
  }
5109
5108
  }
5110
5109
  function createOrGetNode(rrNode, domMirror, rrnodeMirror) {
5111
- let node = domMirror.getNode(rrnodeMirror.getId(rrNode));
5110
+ const nodeId = rrnodeMirror.getId(rrNode);
5112
5111
  const sn = rrnodeMirror.getMeta(rrNode);
5112
+ let node = null;
5113
+ if (nodeId > -1)
5114
+ node = domMirror.getNode(nodeId);
5113
5115
  if (node !== null)
5114
5116
  return node;
5115
5117
  switch (rrNode.RRNodeType) {
@@ -5328,11 +5330,11 @@ function buildFromNode(node, rrdom, domMirror, parentRRNode) {
5328
5330
  }
5329
5331
  break;
5330
5332
  case NodeType.DOCUMENT_TYPE_NODE:
5331
- const documentType = (node);
5333
+ const documentType = node;
5332
5334
  rrNode = rrdom.createDocumentType(documentType.name, documentType.publicId, documentType.systemId);
5333
5335
  break;
5334
5336
  case NodeType.ELEMENT_NODE:
5335
- const elementNode = (node);
5337
+ const elementNode = node;
5336
5338
  const tagName = getValidTagName(elementNode);
5337
5339
  rrNode = rrdom.createElement(tagName);
5338
5340
  const rrElement = rrNode;
@@ -5343,13 +5345,13 @@ function buildFromNode(node, rrdom, domMirror, parentRRNode) {
5343
5345
  elementNode.scrollTop && (rrElement.scrollTop = elementNode.scrollTop);
5344
5346
  break;
5345
5347
  case NodeType.TEXT_NODE:
5346
- rrNode = rrdom.createTextNode((node).textContent || '');
5348
+ rrNode = rrdom.createTextNode(node.textContent || '');
5347
5349
  break;
5348
5350
  case NodeType.CDATA_SECTION_NODE:
5349
- rrNode = rrdom.createCDATASection((node).data);
5351
+ rrNode = rrdom.createCDATASection(node.data);
5350
5352
  break;
5351
5353
  case NodeType.COMMENT_NODE:
5352
- rrNode = rrdom.createComment((node).textContent || '');
5354
+ rrNode = rrdom.createComment(node.textContent || '');
5353
5355
  break;
5354
5356
  case NodeType.DOCUMENT_FRAGMENT_NODE:
5355
5357
  rrNode = parentRRNode.attachShadow({ mode: 'open' });
@@ -5385,8 +5387,8 @@ function buildFromDom(dom, domMirror = createMirror$1(), rrdom = new RRDocument(
5385
5387
  node.nodeType === NodeType.ELEMENT_NODE ||
5386
5388
  node.nodeType === NodeType.DOCUMENT_FRAGMENT_NODE) {
5387
5389
  if (node.nodeType === NodeType.ELEMENT_NODE &&
5388
- (node).shadowRoot)
5389
- walk((node).shadowRoot, rrNode);
5390
+ node.shadowRoot)
5391
+ walk(node.shadowRoot, rrNode);
5390
5392
  node.childNodes.forEach((childNode) => walk(childNode, rrNode));
5391
5393
  }
5392
5394
  }
@@ -6966,7 +6968,7 @@ class Replayer {
6966
6968
  const styleEl = document.createElement('style');
6967
6969
  documentElement.insertBefore(styleEl, head);
6968
6970
  for (let idx = 0; idx < injectStylesRules.length; idx++) {
6969
- (styleEl.sheet).insertRule(injectStylesRules[idx], idx);
6971
+ styleEl.sheet.insertRule(injectStylesRules[idx], idx);
6970
6972
  }
6971
6973
  }
6972
6974
  }
@@ -7351,7 +7353,7 @@ class Replayer {
7351
7353
  if (!target) {
7352
7354
  return this.debugNodeNotFound(d, d.id);
7353
7355
  }
7354
- const styleSheet = (target).sheet;
7356
+ const styleSheet = target.sheet;
7355
7357
  (_d = d.adds) === null || _d === void 0 ? void 0 : _d.forEach(({ rule, index: nestedIndex }) => {
7356
7358
  try {
7357
7359
  if (Array.isArray(nestedIndex)) {