@highlight-run/rrweb 2.0.5 → 2.0.8

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 (32) hide show
  1. package/dist/plugins/console-record.js +1 -1
  2. package/dist/plugins/console-record.min.js +1 -1
  3. package/dist/plugins/console-record.min.js.map +1 -1
  4. package/dist/plugins/console-replay.min.js.map +1 -1
  5. package/dist/record/rrweb-record-pack.min.js.map +1 -1
  6. package/dist/record/rrweb-record.js +3 -3
  7. package/dist/record/rrweb-record.min.js +3 -3
  8. package/dist/record/rrweb-record.min.js.map +1 -1
  9. package/dist/replay/rrweb-replay-unpack.js +4 -4
  10. package/dist/replay/rrweb-replay-unpack.min.js +4 -4
  11. package/dist/replay/rrweb-replay-unpack.min.js.map +1 -1
  12. package/dist/replay/rrweb-replay.js +3 -3
  13. package/dist/replay/rrweb-replay.min.js +3 -3
  14. package/dist/replay/rrweb-replay.min.js.map +1 -1
  15. package/dist/rrweb-all.js +12 -12
  16. package/dist/rrweb-all.min.js +12 -12
  17. package/dist/rrweb-all.min.js.map +1 -1
  18. package/dist/rrweb.js +5 -5
  19. package/dist/rrweb.min.js +5 -5
  20. package/dist/rrweb.min.js.map +1 -1
  21. package/es/rrweb/packages/rrweb/src/record/mutation.js +23 -11
  22. package/es/rrweb/packages/rrweb/src/record/observer.js +6 -6
  23. package/es/rrweb/packages/rrweb/src/record/observers/canvas/2d.js +1 -1
  24. package/es/rrweb/packages/rrweb/src/record/observers/canvas/canvas.js +2 -2
  25. package/es/rrweb/packages/rrweb/src/record/observers/canvas/webgl.js +1 -2
  26. package/es/rrweb/packages/rrweb/src/utils.js +16 -23
  27. package/es/rrweb/packages/rrweb-snapshot/es/rrweb-snapshot.js +278 -241
  28. package/lib/record/rrweb-record.js +325 -284
  29. package/lib/rrweb-all.js +325 -284
  30. package/lib/rrweb.js +325 -284
  31. package/package.json +4 -4
  32. package/typings/utils.d.ts +1 -1
package/lib/rrweb.js CHANGED
@@ -18,7 +18,7 @@ function isElement(n) {
18
18
  function isShadowRoot(n) {
19
19
  var _a;
20
20
  var host = (_a = n) === null || _a === void 0 ? void 0 : _a.host;
21
- return Boolean(host && host.shadowRoot && host.shadowRoot === n);
21
+ return Boolean((host === null || host === void 0 ? void 0 : host.shadowRoot) === n);
22
22
  }
23
23
  var Mirror$2 = (function () {
24
24
  function Mirror() {
@@ -318,7 +318,7 @@ function _isBlockedElement(element, blockClass, blockSelector) {
318
318
  }
319
319
  }
320
320
  else {
321
- for (var eIndex = 0; eIndex < element.classList.length; eIndex++) {
321
+ for (var eIndex = element.classList.length; eIndex--;) {
322
322
  var className = element.classList[eIndex];
323
323
  if (blockClass.test(className)) {
324
324
  return true;
@@ -330,35 +330,47 @@ function _isBlockedElement(element, blockClass, blockSelector) {
330
330
  }
331
331
  return false;
332
332
  }
333
- function needMaskingText(node, maskTextClass, maskTextSelector) {
334
- if (!node) {
333
+ function classMatchesRegex(node, regex, checkAncestors) {
334
+ if (!node)
335
335
  return false;
336
+ if (node.nodeType !== node.ELEMENT_NODE) {
337
+ if (!checkAncestors)
338
+ return false;
339
+ return classMatchesRegex(node.parentNode, regex, checkAncestors);
336
340
  }
337
- if (node.nodeType === node.ELEMENT_NODE) {
338
- if (typeof maskTextClass === 'string') {
339
- if (node.classList.contains(maskTextClass)) {
340
- return true;
341
- }
342
- }
343
- else {
344
- for (var eIndex = 0; eIndex < node.classList.length; eIndex++) {
345
- var className = node.classList[eIndex];
346
- if (maskTextClass.test(className)) {
347
- return true;
348
- }
349
- }
350
- }
351
- if (maskTextSelector) {
352
- if (node.matches(maskTextSelector)) {
353
- return true;
354
- }
341
+ for (var eIndex = node.classList.length; eIndex--;) {
342
+ var className = node.classList[eIndex];
343
+ if (regex.test(className)) {
344
+ return true;
355
345
  }
356
- return needMaskingText(node.parentNode, maskTextClass, maskTextSelector);
357
346
  }
358
- if (node.nodeType === node.TEXT_NODE) {
359
- return needMaskingText(node.parentNode, maskTextClass, maskTextSelector);
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;
360
362
  }
361
- return needMaskingText(node.parentNode, maskTextClass, maskTextSelector);
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;
362
374
  }
363
375
  function onceIframeLoaded(iframeEl, listener, iframeLoadTimeout) {
364
376
  var win = iframeEl.contentWindow;
@@ -425,13 +437,8 @@ function onceStylesheetLoaded(link, listener, iframeLoadTimeout) {
425
437
  });
426
438
  }
427
439
  function serializeNode(n, options) {
428
- var _a;
429
- var doc = options.doc, mirror = options.mirror, blockClass = options.blockClass, blockSelector = options.blockSelector, maskTextClass = options.maskTextClass, maskTextSelector = options.maskTextSelector, inlineStylesheet = options.inlineStylesheet, _b = options.maskInputOptions, maskInputOptions = _b === void 0 ? {} : _b, maskTextFn = options.maskTextFn, maskInputFn = options.maskInputFn, _c = options.dataURLOptions, dataURLOptions = _c === void 0 ? {} : _c, inlineImages = options.inlineImages, recordCanvas = options.recordCanvas, keepIframeSrcFn = options.keepIframeSrcFn, enableStrictPrivacy = options.enableStrictPrivacy;
430
- var rootId;
431
- if (mirror.getMeta(doc)) {
432
- var docId = mirror.getId(doc);
433
- rootId = docId === 1 ? undefined : docId;
434
- }
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);
435
442
  switch (n.nodeType) {
436
443
  case n.DOCUMENT_NODE:
437
444
  if (n.compatMode !== 'CSS1Compat') {
@@ -458,203 +465,29 @@ function serializeNode(n, options) {
458
465
  rootId: rootId
459
466
  };
460
467
  case n.ELEMENT_NODE:
461
- var needBlock = _isBlockedElement(n, blockClass, blockSelector);
462
- var tagName = getValidTagName$1(n);
463
- var attributes_1 = {};
464
- var len = n.attributes.length;
465
- for (var i = 0; i < len; i++) {
466
- var attr = n.attributes[i];
467
- attributes_1[attr.name] = transformAttribute(doc, tagName, attr.name, attr.value);
468
- }
469
- if (tagName === 'link' && inlineStylesheet) {
470
- var stylesheet = Array.from(doc.styleSheets).find(function (s) {
471
- return s.href === n.href;
472
- });
473
- var cssText = null;
474
- if (stylesheet) {
475
- cssText = getCssRulesString(stylesheet);
476
- }
477
- if (cssText) {
478
- delete attributes_1.rel;
479
- delete attributes_1.href;
480
- attributes_1._cssText = absoluteToStylesheet(cssText, stylesheet.href);
481
- }
482
- }
483
- if (tagName === 'style' &&
484
- n.sheet &&
485
- !(n.innerText ||
486
- n.textContent ||
487
- '').trim().length) {
488
- var cssText = getCssRulesString(n.sheet);
489
- if (cssText) {
490
- attributes_1._cssText = absoluteToStylesheet(cssText, getHref());
491
- }
492
- }
493
- if (tagName === 'input' ||
494
- tagName === 'textarea' ||
495
- tagName === 'select') {
496
- var value = n.value;
497
- if (attributes_1.type !== 'radio' &&
498
- attributes_1.type !== 'checkbox' &&
499
- attributes_1.type !== 'submit' &&
500
- attributes_1.type !== 'button' &&
501
- value) {
502
- attributes_1.value = maskInputValue({
503
- type: attributes_1.type,
504
- tagName: tagName,
505
- value: value,
506
- maskInputOptions: maskInputOptions,
507
- maskInputFn: maskInputFn
508
- });
509
- }
510
- else if (n.checked) {
511
- attributes_1.checked = n.checked;
512
- }
513
- }
514
- if (tagName === 'option') {
515
- if (n.selected && !maskInputOptions['select']) {
516
- attributes_1.selected = true;
517
- }
518
- else {
519
- delete attributes_1.selected;
520
- }
521
- }
522
- if (tagName === 'canvas' && recordCanvas) {
523
- if (n.__context === '2d') {
524
- if (!is2DCanvasBlank(n)) {
525
- attributes_1.rr_dataURL = n.toDataURL(dataURLOptions.type, dataURLOptions.quality);
526
- }
527
- }
528
- else if (!('__context' in n)) {
529
- var canvasDataURL = n.toDataURL(dataURLOptions.type, dataURLOptions.quality);
530
- var blankCanvas = document.createElement('canvas');
531
- blankCanvas.width = n.width;
532
- blankCanvas.height = n.height;
533
- var blankCanvasDataURL = blankCanvas.toDataURL(dataURLOptions.type, dataURLOptions.quality);
534
- if (canvasDataURL !== blankCanvasDataURL) {
535
- attributes_1.rr_dataURL = canvasDataURL;
536
- }
537
- }
538
- }
539
- if (tagName === 'img' && inlineImages) {
540
- if (!canvasService) {
541
- canvasService = doc.createElement('canvas');
542
- canvasCtx = canvasService.getContext('2d');
543
- }
544
- var image_1 = n;
545
- var oldValue_1 = image_1.crossOrigin;
546
- image_1.crossOrigin = 'anonymous';
547
- var recordInlineImage = function () {
548
- try {
549
- canvasService.width = image_1.naturalWidth;
550
- canvasService.height = image_1.naturalHeight;
551
- canvasCtx.drawImage(image_1, 0, 0);
552
- attributes_1.rr_dataURL = canvasService.toDataURL(dataURLOptions.type, dataURLOptions.quality);
553
- }
554
- catch (err) {
555
- console.warn("Cannot inline img src=" + image_1.currentSrc + "! Error: " + err);
556
- }
557
- oldValue_1
558
- ? (attributes_1.crossOrigin = oldValue_1)
559
- : image_1.removeAttribute('crossorigin');
560
- };
561
- if (image_1.complete && image_1.naturalWidth !== 0)
562
- recordInlineImage();
563
- else
564
- image_1.onload = recordInlineImage;
565
- }
566
- if (tagName === 'audio' || tagName === 'video') {
567
- attributes_1.rr_mediaState = n.paused
568
- ? 'paused'
569
- : 'played';
570
- attributes_1.rr_mediaCurrentTime = n.currentTime;
571
- }
572
- if (n.scrollLeft) {
573
- attributes_1.rr_scrollLeft = n.scrollLeft;
574
- }
575
- if (n.scrollTop) {
576
- attributes_1.rr_scrollTop = n.scrollTop;
577
- }
578
- if (needBlock || (tagName === 'img' && enableStrictPrivacy)) {
579
- var _d = n.getBoundingClientRect(), width = _d.width, height = _d.height;
580
- attributes_1 = {
581
- "class": attributes_1["class"],
582
- rr_width: width + "px",
583
- rr_height: height + "px"
584
- };
585
- needBlock = true;
586
- }
587
- if (tagName === 'iframe' && !keepIframeSrcFn(attributes_1.src)) {
588
- if (!n.contentDocument) {
589
- attributes_1.rr_src = attributes_1.src;
590
- }
591
- delete attributes_1.src;
592
- }
593
- return {
594
- type: NodeType$2.Element,
595
- tagName: tagName,
596
- attributes: attributes_1,
597
- childNodes: [],
598
- isSVG: isSVGElement(n) || undefined,
599
- needBlock: needBlock,
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,
600
481
  rootId: rootId
601
- };
482
+ });
602
483
  case n.TEXT_NODE:
603
- var parentTagName = n.parentNode && n.parentNode.tagName;
604
- var textContent = n.textContent;
605
- var isStyle = parentTagName === 'STYLE' ? true : undefined;
606
- var isScript = parentTagName === 'SCRIPT' ? true : undefined;
607
- var textContentHandled = false;
608
- if (isStyle && textContent) {
609
- try {
610
- if (n.nextSibling || n.previousSibling) {
611
- }
612
- else if ((_a = n.parentNode.sheet) === null || _a === void 0 ? void 0 : _a.cssRules) {
613
- textContent = stringifyStyleSheet(n.parentNode.sheet);
614
- }
615
- }
616
- catch (err) {
617
- console.warn("Cannot get CSS styles from text's parentNode. Error: " + err, n);
618
- }
619
- textContent = absoluteToStylesheet(textContent, getHref());
620
- textContentHandled = true;
621
- }
622
- if (isScript) {
623
- textContent = 'SCRIPT_PLACEHOLDER';
624
- textContentHandled = true;
625
- }
626
- else if (parentTagName === 'NOSCRIPT') {
627
- textContent = '';
628
- textContentHandled = true;
629
- }
630
- if (!isStyle &&
631
- !isScript &&
632
- needMaskingText(n, maskTextClass, maskTextSelector) &&
633
- textContent) {
634
- textContent = maskTextFn
635
- ? maskTextFn(textContent)
636
- : textContent.replace(/[\S]/g, '*');
637
- }
638
- if (enableStrictPrivacy && !textContentHandled && parentTagName) {
639
- var IGNORE_TAG_NAMES = new Set([
640
- 'HEAD',
641
- 'TITLE',
642
- 'STYLE',
643
- 'SCRIPT',
644
- 'HTML',
645
- 'BODY',
646
- 'NOSCRIPT',
647
- ]);
648
- if (!IGNORE_TAG_NAMES.has(parentTagName) && textContent) {
649
- textContent = obfuscateText(textContent);
650
- }
651
- }
652
- return {
653
- type: NodeType$2.Text,
654
- textContent: textContent || '',
655
- isStyle: isStyle,
484
+ return serializeTextNode(n, {
485
+ maskTextClass: maskTextClass,
486
+ maskTextSelector: maskTextSelector,
487
+ maskTextFn: maskTextFn,
488
+ enableStrictPrivacy: enableStrictPrivacy,
656
489
  rootId: rootId
657
- };
490
+ });
658
491
  case n.CDATA_SECTION_NODE:
659
492
  return {
660
493
  type: NodeType$2.CDATA,
@@ -671,6 +504,213 @@ function serializeNode(n, options) {
671
504
  return false;
672
505
  }
673
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
+ }
674
714
  function lowerIfExists(maybeAttr) {
675
715
  if (maybeAttr === undefined) {
676
716
  return '';
@@ -751,8 +791,8 @@ function slimDOMExcluded(sn, slimDOMOptions) {
751
791
  return false;
752
792
  }
753
793
  function serializeNodeWithId(n, options) {
754
- 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, enableStrictPrivacy = options.enableStrictPrivacy;
755
- var _k = options.preserveWhiteSpace, preserveWhiteSpace = _k === void 0 ? true : _k;
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;
756
796
  var _serializedNode = serializeNode(n, {
757
797
  doc: doc,
758
798
  mirror: mirror,
@@ -768,6 +808,7 @@ function serializeNodeWithId(n, options) {
768
808
  inlineImages: inlineImages,
769
809
  recordCanvas: recordCanvas,
770
810
  keepIframeSrcFn: keepIframeSrcFn,
811
+ newlyAddedElement: newlyAddedElement,
771
812
  enableStrictPrivacy: enableStrictPrivacy
772
813
  });
773
814
  if (!_serializedNode) {
@@ -804,12 +845,6 @@ function serializeNodeWithId(n, options) {
804
845
  clone.src = '';
805
846
  mirror.add(clone, serializedNode);
806
847
  }
807
- if (serializedNode.tagName === 'link') {
808
- var clone = n.cloneNode();
809
- clone.href = '';
810
- clone.innerText = serializedNode.attributes._cssText;
811
- mirror.add(clone, serializedNode);
812
- }
813
848
  delete serializedNode.needBlock;
814
849
  if (n.shadowRoot)
815
850
  serializedNode.isShadowHost = true;
@@ -847,16 +882,16 @@ function serializeNodeWithId(n, options) {
847
882
  keepIframeSrcFn: keepIframeSrcFn,
848
883
  enableStrictPrivacy: enableStrictPrivacy
849
884
  };
850
- for (var _i = 0, _l = Array.from(n.childNodes); _i < _l.length; _i++) {
851
- var childN = _l[_i];
885
+ for (var _i = 0, _m = Array.from(n.childNodes); _i < _m.length; _i++) {
886
+ var childN = _m[_i];
852
887
  var serializedChildNode = serializeNodeWithId(childN, bypassOptions);
853
888
  if (serializedChildNode) {
854
889
  serializedNode.childNodes.push(serializedChildNode);
855
890
  }
856
891
  }
857
892
  if (isElement(n) && n.shadowRoot) {
858
- for (var _m = 0, _o = Array.from(n.shadowRoot.childNodes); _m < _o.length; _m++) {
859
- var childN = _o[_m];
893
+ for (var _o = 0, _p = Array.from(n.shadowRoot.childNodes); _o < _p.length; _o++) {
894
+ var childN = _p[_o];
860
895
  var serializedChildNode = serializeNodeWithId(childN, bypassOptions);
861
896
  if (serializedChildNode) {
862
897
  serializedChildNode.isShadow = true;
@@ -1005,7 +1040,9 @@ function snapshot(n, options) {
1005
1040
  onIframeLoad: onIframeLoad,
1006
1041
  iframeLoadTimeout: iframeLoadTimeout,
1007
1042
  onStylesheetLoad: onStylesheetLoad,
1008
- stylesheetLoadTimeout: stylesheetLoadTimeout, keepIframeSrcFn: keepIframeSrcFn,
1043
+ stylesheetLoadTimeout: stylesheetLoadTimeout,
1044
+ keepIframeSrcFn: keepIframeSrcFn,
1045
+ newlyAddedElement: false,
1009
1046
  enableStrictPrivacy: enableStrictPrivacy
1010
1047
  });
1011
1048
  }
@@ -1953,33 +1990,26 @@ const isCanvasNode = (node) => {
1953
1990
  }
1954
1991
  return false;
1955
1992
  };
1956
- function isBlocked(node, blockClass) {
1993
+ function isBlocked(node, blockClass, checkAncestors) {
1957
1994
  if (!node) {
1958
1995
  return false;
1959
1996
  }
1960
- if (node.nodeType === node.ELEMENT_NODE) {
1961
- let needBlock = false;
1962
- if (typeof blockClass === 'string') {
1963
- if (node.closest !== undefined) {
1964
- return node.closest('.' + blockClass) !== null;
1965
- }
1966
- else {
1967
- needBlock = node.classList.contains(blockClass);
1968
- }
1969
- }
1970
- else {
1971
- node.classList.forEach((className) => {
1972
- if (blockClass.test(className)) {
1973
- needBlock = true;
1974
- }
1975
- });
1976
- }
1977
- return needBlock || isBlocked(node.parentNode, blockClass);
1997
+ const el = node.nodeType === node.ELEMENT_NODE
1998
+ ? node
1999
+ : node.parentElement;
2000
+ if (!el)
2001
+ return false;
2002
+ if (typeof blockClass === 'string') {
2003
+ if (el.classList.contains(blockClass))
2004
+ return true;
2005
+ if (checkAncestors && el.closest('.' + blockClass) !== null)
2006
+ return true;
1978
2007
  }
1979
- if (node.nodeType === node.TEXT_NODE) {
1980
- return isBlocked(node.parentNode, blockClass);
2008
+ else {
2009
+ if (classMatchesRegex(el, blockClass, checkAncestors))
2010
+ return true;
1981
2011
  }
1982
- return isBlocked(node.parentNode, blockClass);
2012
+ return false;
1983
2013
  }
1984
2014
  function isSerialized(n, mirror) {
1985
2015
  return mirror.getId(n) !== -1;
@@ -2400,6 +2430,7 @@ class MutationBuffer {
2400
2430
  onStylesheetLoad: (link, childSn) => {
2401
2431
  this.stylesheetManager.attachStylesheet(link, childSn, this.mirror);
2402
2432
  },
2433
+ newlyAddedElement: true,
2403
2434
  });
2404
2435
  if (sn) {
2405
2436
  adds.push({
@@ -2508,7 +2539,8 @@ class MutationBuffer {
2508
2539
  switch (m.type) {
2509
2540
  case 'characterData': {
2510
2541
  const value = m.target.textContent;
2511
- if (!isBlocked(m.target, this.blockClass) && value !== m.oldValue) {
2542
+ if (!isBlocked(m.target, this.blockClass, false) &&
2543
+ value !== m.oldValue) {
2512
2544
  this.texts.push({
2513
2545
  value: needMaskingText(m.target, this.maskTextClass, this.maskTextSelector) && value
2514
2546
  ? this.maskTextFn
@@ -2532,7 +2564,8 @@ class MutationBuffer {
2532
2564
  maskInputFn: this.maskInputFn,
2533
2565
  });
2534
2566
  }
2535
- if (isBlocked(m.target, this.blockClass) || value === m.oldValue) {
2567
+ if (isBlocked(m.target, this.blockClass, false) ||
2568
+ value === m.oldValue) {
2536
2569
  return;
2537
2570
  }
2538
2571
  let item = this.attributes.find((a) => a.node === m.target);
@@ -2586,13 +2619,15 @@ class MutationBuffer {
2586
2619
  break;
2587
2620
  }
2588
2621
  case 'childList': {
2622
+ if (isBlocked(m.target, this.blockClass, true))
2623
+ return;
2589
2624
  m.addedNodes.forEach((n) => this.genAdds(n, m.target));
2590
2625
  m.removedNodes.forEach((n) => {
2591
2626
  const nodeId = this.mirror.getId(n);
2592
2627
  const parentId = isShadowRoot(m.target)
2593
2628
  ? this.mirror.getId(m.target.host)
2594
2629
  : this.mirror.getId(m.target);
2595
- if (isBlocked(m.target, this.blockClass) ||
2630
+ if (isBlocked(m.target, this.blockClass, false) ||
2596
2631
  isIgnored(n, this.mirror) ||
2597
2632
  !isSerialized(n, this.mirror)) {
2598
2633
  return;
@@ -2621,16 +2656,13 @@ class MutationBuffer {
2621
2656
  }
2622
2657
  };
2623
2658
  this.genAdds = (n, target) => {
2624
- if (target && isBlocked(target, this.blockClass)) {
2625
- return;
2626
- }
2627
- if (this.mirror.getMeta(n)) {
2659
+ if (this.mirror.hasNode(n)) {
2628
2660
  if (isIgnored(n, this.mirror)) {
2629
2661
  return;
2630
2662
  }
2631
2663
  this.movedSet.add(n);
2632
2664
  let targetId = null;
2633
- if (target && this.mirror.getMeta(target)) {
2665
+ if (target && this.mirror.hasNode(target)) {
2634
2666
  targetId = this.mirror.getId(target);
2635
2667
  }
2636
2668
  if (targetId && targetId !== -1) {
@@ -2641,7 +2673,7 @@ class MutationBuffer {
2641
2673
  this.addedSet.add(n);
2642
2674
  this.droppedSet.delete(n);
2643
2675
  }
2644
- if (!isBlocked(n, this.blockClass))
2676
+ if (!isBlocked(n, this.blockClass, false))
2645
2677
  n.childNodes.forEach((childN) => this.genAdds(childN));
2646
2678
  };
2647
2679
  }
@@ -2701,6 +2733,11 @@ function deepDelete(addsSet, n) {
2701
2733
  n.childNodes.forEach((childN) => deepDelete(addsSet, childN));
2702
2734
  }
2703
2735
  function isParentRemoved(removes, n, mirror) {
2736
+ if (removes.length === 0)
2737
+ return false;
2738
+ return _isParentRemoved(removes, n, mirror);
2739
+ }
2740
+ function _isParentRemoved(removes, n, mirror) {
2704
2741
  const { parentNode } = n;
2705
2742
  if (!parentNode) {
2706
2743
  return false;
@@ -2709,9 +2746,14 @@ function isParentRemoved(removes, n, mirror) {
2709
2746
  if (removes.some((r) => r.id === parentId)) {
2710
2747
  return true;
2711
2748
  }
2712
- return isParentRemoved(removes, parentNode, mirror);
2749
+ return _isParentRemoved(removes, parentNode, mirror);
2713
2750
  }
2714
2751
  function isAncestorInSet(set, n) {
2752
+ if (set.size === 0)
2753
+ return false;
2754
+ return _isAncestorInSet(set, n);
2755
+ }
2756
+ function _isAncestorInSet(set, n) {
2715
2757
  const { parentNode } = n;
2716
2758
  if (!parentNode) {
2717
2759
  return false;
@@ -2719,7 +2761,7 @@ function isAncestorInSet(set, n) {
2719
2761
  if (set.has(parentNode)) {
2720
2762
  return true;
2721
2763
  }
2722
- return isAncestorInSet(set, parentNode);
2764
+ return _isAncestorInSet(set, parentNode);
2723
2765
  }
2724
2766
 
2725
2767
  const mutationBuffers = [];
@@ -2829,7 +2871,7 @@ function initMouseInteractionObserver({ mouseInteractionCb, doc, mirror, blockCl
2829
2871
  const getHandler = (eventKey) => {
2830
2872
  return (event) => {
2831
2873
  const target = getEventTarget(event);
2832
- if (isBlocked(target, blockClass) ||
2874
+ if (isBlocked(target, blockClass, true) ||
2833
2875
  isCanvasNode(target)) {
2834
2876
  return;
2835
2877
  }
@@ -2863,7 +2905,7 @@ function initMouseInteractionObserver({ mouseInteractionCb, doc, mirror, blockCl
2863
2905
  function initScrollObserver({ scrollCb, doc, mirror, blockClass, sampling, }) {
2864
2906
  const updatePosition = throttle((evt) => {
2865
2907
  const target = getEventTarget(evt);
2866
- if (!target || isBlocked(target, blockClass)) {
2908
+ if (!target || isBlocked(target, blockClass, true)) {
2867
2909
  return;
2868
2910
  }
2869
2911
  const id = mirror.getId(target);
@@ -2919,7 +2961,7 @@ function initInputObserver({ inputCb, doc, mirror, blockClass, ignoreClass, mask
2919
2961
  if (!target ||
2920
2962
  !target.tagName ||
2921
2963
  INPUT_TAGS.indexOf(target.tagName) < 0 ||
2922
- isBlocked(target, blockClass)) {
2964
+ isBlocked(target, blockClass, true)) {
2923
2965
  return;
2924
2966
  }
2925
2967
  const type = target.type;
@@ -3054,8 +3096,8 @@ function initStyleSheetObserver({ styleSheetRuleCb, mirror }, { win }) {
3054
3096
  const unmodifiedFunctions = {};
3055
3097
  Object.entries(supportedNestedCSSRuleTypes).forEach(([typeKey, type]) => {
3056
3098
  unmodifiedFunctions[typeKey] = {
3057
- insertRule: (type).prototype.insertRule,
3058
- deleteRule: (type).prototype.deleteRule,
3099
+ insertRule: type.prototype.insertRule,
3100
+ deleteRule: type.prototype.deleteRule,
3059
3101
  };
3060
3102
  type.prototype.insertRule = function (rule, index) {
3061
3103
  const id = mirror.getId(this.parentStyleSheet.ownerNode);
@@ -3136,7 +3178,7 @@ function initStyleDeclarationObserver({ styleDeclarationCb, mirror }, { win }) {
3136
3178
  function initMediaInteractionObserver({ mediaInteractionCb, blockClass, mirror, sampling, }) {
3137
3179
  const handler = (type) => throttle((event) => {
3138
3180
  const target = getEventTarget(event);
3139
- if (!target || isBlocked(target, blockClass)) {
3181
+ if (!target || isBlocked(target, blockClass, true)) {
3140
3182
  return;
3141
3183
  }
3142
3184
  const { currentTime, volume, muted } = target;
@@ -3590,7 +3632,7 @@ function initCanvas2DMutationObserver(cb, win, blockClass, mirror) {
3590
3632
  }
3591
3633
  const restoreHandler = patch(win.CanvasRenderingContext2D.prototype, prop, function (original) {
3592
3634
  return function (...args) {
3593
- if (!isBlocked(this.canvas, blockClass)) {
3635
+ if (!isBlocked(this.canvas, blockClass, true)) {
3594
3636
  setTimeout(() => {
3595
3637
  const recordArgs = serializeArgs([...args], win, this);
3596
3638
  cb(this.canvas, {
@@ -3629,9 +3671,9 @@ function initCanvasContextObserver(win, blockClass) {
3629
3671
  try {
3630
3672
  const restoreHandler = patch(win.HTMLCanvasElement.prototype, 'getContext', function (original) {
3631
3673
  return function (contextType, ...args) {
3632
- if (!isBlocked(this, blockClass)) {
3674
+ if (!isBlocked(this, blockClass, true)) {
3633
3675
  if (!('__context' in this))
3634
- (this).__context = contextType;
3676
+ this.__context = contextType;
3635
3677
  }
3636
3678
  return original.apply(this, [contextType, ...args]);
3637
3679
  };
@@ -3658,8 +3700,7 @@ function patchGLPrototype(prototype, type, cb, blockClass, mirror, win) {
3658
3700
  return function (...args) {
3659
3701
  const result = original.apply(this, args);
3660
3702
  saveWebGLVar(result, win, prototype);
3661
- if (!isBlocked(this.canvas, blockClass)) {
3662
- const id = mirror.getId(this.canvas);
3703
+ if (!isBlocked(this.canvas, blockClass, true)) {
3663
3704
  const recordArgs = serializeArgs([...args], win, prototype);
3664
3705
  const mutation = {
3665
3706
  type,