@highlight-run/rrweb 2.0.6 → 2.0.7

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 (33) 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/index.js +5 -2
  22. package/es/rrweb/packages/rrweb/src/record/mutation.js +23 -11
  23. package/es/rrweb/packages/rrweb/src/record/observer.js +6 -6
  24. package/es/rrweb/packages/rrweb/src/record/observers/canvas/2d.js +1 -1
  25. package/es/rrweb/packages/rrweb/src/record/observers/canvas/canvas.js +2 -2
  26. package/es/rrweb/packages/rrweb/src/record/observers/canvas/webgl.js +1 -2
  27. package/es/rrweb/packages/rrweb/src/utils.js +16 -23
  28. package/es/rrweb/packages/rrweb-snapshot/es/rrweb-snapshot.js +282 -236
  29. package/lib/record/rrweb-record.js +333 -280
  30. package/lib/rrweb-all.js +333 -280
  31. package/lib/rrweb.js +333 -280
  32. package/package.json +4 -4
  33. 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;
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;
360
372
  }
361
- return needMaskingText(node.parentNode, maskTextClass, maskTextSelector);
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) {
@@ -841,16 +882,16 @@ function serializeNodeWithId(n, options) {
841
882
  keepIframeSrcFn: keepIframeSrcFn,
842
883
  enableStrictPrivacy: enableStrictPrivacy
843
884
  };
844
- for (var _i = 0, _l = Array.from(n.childNodes); _i < _l.length; _i++) {
845
- var childN = _l[_i];
885
+ for (var _i = 0, _m = Array.from(n.childNodes); _i < _m.length; _i++) {
886
+ var childN = _m[_i];
846
887
  var serializedChildNode = serializeNodeWithId(childN, bypassOptions);
847
888
  if (serializedChildNode) {
848
889
  serializedNode.childNodes.push(serializedChildNode);
849
890
  }
850
891
  }
851
892
  if (isElement(n) && n.shadowRoot) {
852
- for (var _m = 0, _o = Array.from(n.shadowRoot.childNodes); _m < _o.length; _m++) {
853
- var childN = _o[_m];
893
+ for (var _o = 0, _p = Array.from(n.shadowRoot.childNodes); _o < _p.length; _o++) {
894
+ var childN = _p[_o];
854
895
  var serializedChildNode = serializeNodeWithId(childN, bypassOptions);
855
896
  if (serializedChildNode) {
856
897
  serializedChildNode.isShadow = true;
@@ -887,6 +928,8 @@ function serializeNodeWithId(n, options) {
887
928
  onSerialize: onSerialize,
888
929
  onIframeLoad: onIframeLoad,
889
930
  iframeLoadTimeout: iframeLoadTimeout,
931
+ onStylesheetLoad: onStylesheetLoad,
932
+ stylesheetLoadTimeout: stylesheetLoadTimeout,
890
933
  keepIframeSrcFn: keepIframeSrcFn,
891
934
  enableStrictPrivacy: enableStrictPrivacy
892
935
  });
@@ -920,8 +963,9 @@ function serializeNodeWithId(n, options) {
920
963
  preserveWhiteSpace: preserveWhiteSpace,
921
964
  onSerialize: onSerialize,
922
965
  onIframeLoad: onIframeLoad,
923
- onStylesheetLoad: onStylesheetLoad,
924
966
  iframeLoadTimeout: iframeLoadTimeout,
967
+ onStylesheetLoad: onStylesheetLoad,
968
+ stylesheetLoadTimeout: stylesheetLoadTimeout,
925
969
  keepIframeSrcFn: keepIframeSrcFn,
926
970
  enableStrictPrivacy: enableStrictPrivacy
927
971
  });
@@ -999,7 +1043,9 @@ function snapshot(n, options) {
999
1043
  onIframeLoad: onIframeLoad,
1000
1044
  iframeLoadTimeout: iframeLoadTimeout,
1001
1045
  onStylesheetLoad: onStylesheetLoad,
1002
- stylesheetLoadTimeout: stylesheetLoadTimeout, keepIframeSrcFn: keepIframeSrcFn,
1046
+ stylesheetLoadTimeout: stylesheetLoadTimeout,
1047
+ keepIframeSrcFn: keepIframeSrcFn,
1048
+ newlyAddedElement: false,
1003
1049
  enableStrictPrivacy: enableStrictPrivacy
1004
1050
  });
1005
1051
  }
@@ -1947,33 +1993,26 @@ const isCanvasNode = (node) => {
1947
1993
  }
1948
1994
  return false;
1949
1995
  };
1950
- function isBlocked(node, blockClass) {
1996
+ function isBlocked(node, blockClass, checkAncestors) {
1951
1997
  if (!node) {
1952
1998
  return false;
1953
1999
  }
1954
- if (node.nodeType === node.ELEMENT_NODE) {
1955
- let needBlock = false;
1956
- if (typeof blockClass === 'string') {
1957
- if (node.closest !== undefined) {
1958
- return node.closest('.' + blockClass) !== null;
1959
- }
1960
- else {
1961
- needBlock = node.classList.contains(blockClass);
1962
- }
1963
- }
1964
- else {
1965
- node.classList.forEach((className) => {
1966
- if (blockClass.test(className)) {
1967
- needBlock = true;
1968
- }
1969
- });
1970
- }
1971
- return needBlock || isBlocked(node.parentNode, blockClass);
2000
+ const el = node.nodeType === node.ELEMENT_NODE
2001
+ ? node
2002
+ : node.parentElement;
2003
+ if (!el)
2004
+ return false;
2005
+ if (typeof blockClass === 'string') {
2006
+ if (el.classList.contains(blockClass))
2007
+ return true;
2008
+ if (checkAncestors && el.closest('.' + blockClass) !== null)
2009
+ return true;
1972
2010
  }
1973
- if (node.nodeType === node.TEXT_NODE) {
1974
- return isBlocked(node.parentNode, blockClass);
2011
+ else {
2012
+ if (classMatchesRegex(el, blockClass, checkAncestors))
2013
+ return true;
1975
2014
  }
1976
- return isBlocked(node.parentNode, blockClass);
2015
+ return false;
1977
2016
  }
1978
2017
  function isSerialized(n, mirror) {
1979
2018
  return mirror.getId(n) !== -1;
@@ -2394,6 +2433,7 @@ class MutationBuffer {
2394
2433
  onStylesheetLoad: (link, childSn) => {
2395
2434
  this.stylesheetManager.attachStylesheet(link, childSn, this.mirror);
2396
2435
  },
2436
+ newlyAddedElement: true,
2397
2437
  });
2398
2438
  if (sn) {
2399
2439
  adds.push({
@@ -2502,7 +2542,8 @@ class MutationBuffer {
2502
2542
  switch (m.type) {
2503
2543
  case 'characterData': {
2504
2544
  const value = m.target.textContent;
2505
- if (!isBlocked(m.target, this.blockClass) && value !== m.oldValue) {
2545
+ if (!isBlocked(m.target, this.blockClass, false) &&
2546
+ value !== m.oldValue) {
2506
2547
  this.texts.push({
2507
2548
  value: needMaskingText(m.target, this.maskTextClass, this.maskTextSelector) && value
2508
2549
  ? this.maskTextFn
@@ -2526,7 +2567,8 @@ class MutationBuffer {
2526
2567
  maskInputFn: this.maskInputFn,
2527
2568
  });
2528
2569
  }
2529
- if (isBlocked(m.target, this.blockClass) || value === m.oldValue) {
2570
+ if (isBlocked(m.target, this.blockClass, false) ||
2571
+ value === m.oldValue) {
2530
2572
  return;
2531
2573
  }
2532
2574
  let item = this.attributes.find((a) => a.node === m.target);
@@ -2580,13 +2622,15 @@ class MutationBuffer {
2580
2622
  break;
2581
2623
  }
2582
2624
  case 'childList': {
2625
+ if (isBlocked(m.target, this.blockClass, true))
2626
+ return;
2583
2627
  m.addedNodes.forEach((n) => this.genAdds(n, m.target));
2584
2628
  m.removedNodes.forEach((n) => {
2585
2629
  const nodeId = this.mirror.getId(n);
2586
2630
  const parentId = isShadowRoot(m.target)
2587
2631
  ? this.mirror.getId(m.target.host)
2588
2632
  : this.mirror.getId(m.target);
2589
- if (isBlocked(m.target, this.blockClass) ||
2633
+ if (isBlocked(m.target, this.blockClass, false) ||
2590
2634
  isIgnored(n, this.mirror) ||
2591
2635
  !isSerialized(n, this.mirror)) {
2592
2636
  return;
@@ -2615,16 +2659,13 @@ class MutationBuffer {
2615
2659
  }
2616
2660
  };
2617
2661
  this.genAdds = (n, target) => {
2618
- if (target && isBlocked(target, this.blockClass)) {
2619
- return;
2620
- }
2621
- if (this.mirror.getMeta(n)) {
2662
+ if (this.mirror.hasNode(n)) {
2622
2663
  if (isIgnored(n, this.mirror)) {
2623
2664
  return;
2624
2665
  }
2625
2666
  this.movedSet.add(n);
2626
2667
  let targetId = null;
2627
- if (target && this.mirror.getMeta(target)) {
2668
+ if (target && this.mirror.hasNode(target)) {
2628
2669
  targetId = this.mirror.getId(target);
2629
2670
  }
2630
2671
  if (targetId && targetId !== -1) {
@@ -2635,7 +2676,7 @@ class MutationBuffer {
2635
2676
  this.addedSet.add(n);
2636
2677
  this.droppedSet.delete(n);
2637
2678
  }
2638
- if (!isBlocked(n, this.blockClass))
2679
+ if (!isBlocked(n, this.blockClass, false))
2639
2680
  n.childNodes.forEach((childN) => this.genAdds(childN));
2640
2681
  };
2641
2682
  }
@@ -2695,6 +2736,11 @@ function deepDelete(addsSet, n) {
2695
2736
  n.childNodes.forEach((childN) => deepDelete(addsSet, childN));
2696
2737
  }
2697
2738
  function isParentRemoved(removes, n, mirror) {
2739
+ if (removes.length === 0)
2740
+ return false;
2741
+ return _isParentRemoved(removes, n, mirror);
2742
+ }
2743
+ function _isParentRemoved(removes, n, mirror) {
2698
2744
  const { parentNode } = n;
2699
2745
  if (!parentNode) {
2700
2746
  return false;
@@ -2703,9 +2749,14 @@ function isParentRemoved(removes, n, mirror) {
2703
2749
  if (removes.some((r) => r.id === parentId)) {
2704
2750
  return true;
2705
2751
  }
2706
- return isParentRemoved(removes, parentNode, mirror);
2752
+ return _isParentRemoved(removes, parentNode, mirror);
2707
2753
  }
2708
2754
  function isAncestorInSet(set, n) {
2755
+ if (set.size === 0)
2756
+ return false;
2757
+ return _isAncestorInSet(set, n);
2758
+ }
2759
+ function _isAncestorInSet(set, n) {
2709
2760
  const { parentNode } = n;
2710
2761
  if (!parentNode) {
2711
2762
  return false;
@@ -2713,7 +2764,7 @@ function isAncestorInSet(set, n) {
2713
2764
  if (set.has(parentNode)) {
2714
2765
  return true;
2715
2766
  }
2716
- return isAncestorInSet(set, parentNode);
2767
+ return _isAncestorInSet(set, parentNode);
2717
2768
  }
2718
2769
 
2719
2770
  const mutationBuffers = [];
@@ -2823,7 +2874,7 @@ function initMouseInteractionObserver({ mouseInteractionCb, doc, mirror, blockCl
2823
2874
  const getHandler = (eventKey) => {
2824
2875
  return (event) => {
2825
2876
  const target = getEventTarget(event);
2826
- if (isBlocked(target, blockClass) ||
2877
+ if (isBlocked(target, blockClass, true) ||
2827
2878
  isCanvasNode(target)) {
2828
2879
  return;
2829
2880
  }
@@ -2857,7 +2908,7 @@ function initMouseInteractionObserver({ mouseInteractionCb, doc, mirror, blockCl
2857
2908
  function initScrollObserver({ scrollCb, doc, mirror, blockClass, sampling, }) {
2858
2909
  const updatePosition = throttle((evt) => {
2859
2910
  const target = getEventTarget(evt);
2860
- if (!target || isBlocked(target, blockClass)) {
2911
+ if (!target || isBlocked(target, blockClass, true)) {
2861
2912
  return;
2862
2913
  }
2863
2914
  const id = mirror.getId(target);
@@ -2913,7 +2964,7 @@ function initInputObserver({ inputCb, doc, mirror, blockClass, ignoreClass, mask
2913
2964
  if (!target ||
2914
2965
  !target.tagName ||
2915
2966
  INPUT_TAGS.indexOf(target.tagName) < 0 ||
2916
- isBlocked(target, blockClass)) {
2967
+ isBlocked(target, blockClass, true)) {
2917
2968
  return;
2918
2969
  }
2919
2970
  const type = target.type;
@@ -3048,8 +3099,8 @@ function initStyleSheetObserver({ styleSheetRuleCb, mirror }, { win }) {
3048
3099
  const unmodifiedFunctions = {};
3049
3100
  Object.entries(supportedNestedCSSRuleTypes).forEach(([typeKey, type]) => {
3050
3101
  unmodifiedFunctions[typeKey] = {
3051
- insertRule: (type).prototype.insertRule,
3052
- deleteRule: (type).prototype.deleteRule,
3102
+ insertRule: type.prototype.insertRule,
3103
+ deleteRule: type.prototype.deleteRule,
3053
3104
  };
3054
3105
  type.prototype.insertRule = function (rule, index) {
3055
3106
  const id = mirror.getId(this.parentStyleSheet.ownerNode);
@@ -3130,7 +3181,7 @@ function initStyleDeclarationObserver({ styleDeclarationCb, mirror }, { win }) {
3130
3181
  function initMediaInteractionObserver({ mediaInteractionCb, blockClass, mirror, sampling, }) {
3131
3182
  const handler = (type) => throttle((event) => {
3132
3183
  const target = getEventTarget(event);
3133
- if (!target || isBlocked(target, blockClass)) {
3184
+ if (!target || isBlocked(target, blockClass, true)) {
3134
3185
  return;
3135
3186
  }
3136
3187
  const { currentTime, volume, muted } = target;
@@ -3584,7 +3635,7 @@ function initCanvas2DMutationObserver(cb, win, blockClass, mirror) {
3584
3635
  }
3585
3636
  const restoreHandler = patch(win.CanvasRenderingContext2D.prototype, prop, function (original) {
3586
3637
  return function (...args) {
3587
- if (!isBlocked(this.canvas, blockClass)) {
3638
+ if (!isBlocked(this.canvas, blockClass, true)) {
3588
3639
  setTimeout(() => {
3589
3640
  const recordArgs = serializeArgs([...args], win, this);
3590
3641
  cb(this.canvas, {
@@ -3623,9 +3674,9 @@ function initCanvasContextObserver(win, blockClass) {
3623
3674
  try {
3624
3675
  const restoreHandler = patch(win.HTMLCanvasElement.prototype, 'getContext', function (original) {
3625
3676
  return function (contextType, ...args) {
3626
- if (!isBlocked(this, blockClass)) {
3677
+ if (!isBlocked(this, blockClass, true)) {
3627
3678
  if (!('__context' in this))
3628
- (this).__context = contextType;
3679
+ this.__context = contextType;
3629
3680
  }
3630
3681
  return original.apply(this, [contextType, ...args]);
3631
3682
  };
@@ -3652,8 +3703,7 @@ function patchGLPrototype(prototype, type, cb, blockClass, mirror, win) {
3652
3703
  return function (...args) {
3653
3704
  const result = original.apply(this, args);
3654
3705
  saveWebGLVar(result, win, prototype);
3655
- if (!isBlocked(this.canvas, blockClass)) {
3656
- const id = mirror.getId(this.canvas);
3706
+ if (!isBlocked(this.canvas, blockClass, true)) {
3657
3707
  const recordArgs = serializeArgs([...args], win, prototype);
3658
3708
  const mutation = {
3659
3709
  type,
@@ -4132,6 +4182,9 @@ function record(options = {}) {
4132
4182
  if (isSerializedIframe(n, mirror)) {
4133
4183
  iframeManager.addIframe(n);
4134
4184
  }
4185
+ if (isSerializedStylesheet(n, mirror)) {
4186
+ stylesheetManager.addStylesheet(n);
4187
+ }
4135
4188
  if (hasShadowRoot(n)) {
4136
4189
  shadowDomManager.addShadowRoot(n.shadowRoot, document);
4137
4190
  }
@@ -4141,7 +4194,7 @@ function record(options = {}) {
4141
4194
  shadowDomManager.observeAttachShadow(iframe);
4142
4195
  },
4143
4196
  onStylesheetLoad: (linkEl, childSn) => {
4144
- this.stylesheetManager.attachStylesheet(linkEl, childSn, this.mirror);
4197
+ stylesheetManager.attachStylesheet(linkEl, childSn, mirror);
4145
4198
  },
4146
4199
  keepIframeSrcFn,
4147
4200
  });