@highlight-run/rrweb 2.0.4 → 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 (56) hide show
  1. package/dist/plugins/console-record.js +12 -454
  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.js +4 -164
  5. package/dist/plugins/console-replay.min.js.map +1 -1
  6. package/dist/plugins/sequential-id-record.js +1 -30
  7. package/dist/plugins/sequential-id-replay.js +1 -33
  8. package/dist/record/rrweb-record-pack.js +3 -664
  9. package/dist/record/rrweb-record-pack.min.js.map +1 -1
  10. package/dist/record/rrweb-record.js +4 -3202
  11. package/dist/record/rrweb-record.min.js +3 -3
  12. package/dist/record/rrweb-record.min.js.map +1 -1
  13. package/dist/replay/rrweb-replay-unpack.css +1 -0
  14. package/dist/replay/rrweb-replay-unpack.js +5 -4914
  15. package/dist/replay/rrweb-replay-unpack.min.css +2 -0
  16. package/dist/replay/rrweb-replay-unpack.min.css.map +1 -0
  17. package/dist/replay/rrweb-replay-unpack.min.js +4 -4
  18. package/dist/replay/rrweb-replay-unpack.min.js.map +1 -1
  19. package/dist/replay/rrweb-replay.css +1 -0
  20. package/dist/replay/rrweb-replay.js +5 -4506
  21. package/dist/replay/rrweb-replay.min.css +2 -0
  22. package/dist/replay/rrweb-replay.min.css.map +1 -0
  23. package/dist/replay/rrweb-replay.min.js +3 -3
  24. package/dist/replay/rrweb-replay.min.js.map +1 -1
  25. package/dist/rrweb-all.css +1 -0
  26. package/dist/rrweb-all.js +16 -8877
  27. package/dist/rrweb-all.min.css +2 -0
  28. package/dist/rrweb-all.min.css.map +1 -0
  29. package/dist/rrweb-all.min.js +12 -12
  30. package/dist/rrweb-all.min.js.map +1 -1
  31. package/dist/rrweb.css +1 -0
  32. package/dist/rrweb.js +6 -7546
  33. package/dist/rrweb.min.css +2 -0
  34. package/dist/rrweb.min.css.map +1 -0
  35. package/dist/rrweb.min.js +5 -5
  36. package/dist/rrweb.min.js.map +1 -1
  37. package/es/rrweb/all.css +1 -0
  38. package/es/rrweb/packages/rrweb/src/record/index.js +5 -2
  39. package/es/rrweb/packages/rrweb/src/record/mutation.js +23 -11
  40. package/es/rrweb/packages/rrweb/src/record/observer.js +6 -6
  41. package/es/rrweb/packages/rrweb/src/record/observers/canvas/2d.js +1 -1
  42. package/es/rrweb/packages/rrweb/src/record/observers/canvas/canvas.js +2 -2
  43. package/es/rrweb/packages/rrweb/src/record/observers/canvas/webgl.js +1 -2
  44. package/es/rrweb/packages/rrweb/src/utils.js +16 -23
  45. package/es/rrweb/packages/rrweb-snapshot/es/rrweb-snapshot.js +283 -243
  46. package/lib/record/rrweb-record.js +333 -286
  47. package/lib/replay/rrweb-replay-unpack.css +1 -0
  48. package/lib/replay/rrweb-replay-unpack.js +1 -1
  49. package/lib/replay/rrweb-replay.css +1 -0
  50. package/lib/replay/rrweb-replay.js +1 -1
  51. package/lib/rrweb-all.css +1 -0
  52. package/lib/rrweb-all.js +334 -287
  53. package/lib/rrweb.css +1 -0
  54. package/lib/rrweb.js +334 -287
  55. package/package.json +4 -4
  56. package/typings/utils.d.ts +1 -1
package/lib/rrweb-all.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;
@@ -893,6 +928,8 @@ function serializeNodeWithId(n, options) {
893
928
  onSerialize: onSerialize,
894
929
  onIframeLoad: onIframeLoad,
895
930
  iframeLoadTimeout: iframeLoadTimeout,
931
+ onStylesheetLoad: onStylesheetLoad,
932
+ stylesheetLoadTimeout: stylesheetLoadTimeout,
896
933
  keepIframeSrcFn: keepIframeSrcFn,
897
934
  enableStrictPrivacy: enableStrictPrivacy
898
935
  });
@@ -926,8 +963,9 @@ function serializeNodeWithId(n, options) {
926
963
  preserveWhiteSpace: preserveWhiteSpace,
927
964
  onSerialize: onSerialize,
928
965
  onIframeLoad: onIframeLoad,
929
- onStylesheetLoad: onStylesheetLoad,
930
966
  iframeLoadTimeout: iframeLoadTimeout,
967
+ onStylesheetLoad: onStylesheetLoad,
968
+ stylesheetLoadTimeout: stylesheetLoadTimeout,
931
969
  keepIframeSrcFn: keepIframeSrcFn,
932
970
  enableStrictPrivacy: enableStrictPrivacy
933
971
  });
@@ -1005,7 +1043,9 @@ function snapshot(n, options) {
1005
1043
  onIframeLoad: onIframeLoad,
1006
1044
  iframeLoadTimeout: iframeLoadTimeout,
1007
1045
  onStylesheetLoad: onStylesheetLoad,
1008
- stylesheetLoadTimeout: stylesheetLoadTimeout, keepIframeSrcFn: keepIframeSrcFn,
1046
+ stylesheetLoadTimeout: stylesheetLoadTimeout,
1047
+ keepIframeSrcFn: keepIframeSrcFn,
1048
+ newlyAddedElement: false,
1009
1049
  enableStrictPrivacy: enableStrictPrivacy
1010
1050
  });
1011
1051
  }
@@ -1503,7 +1543,7 @@ var HOVER_SELECTOR = /([^\\]):hover/;
1503
1543
  var HOVER_SELECTOR_GLOBAL = new RegExp(HOVER_SELECTOR.source, 'g');
1504
1544
  function addHoverClass(cssText, cache) {
1505
1545
  var _a;
1506
- if (!((_a = window.HIG_CONFIGURATION) === null || _a === void 0 ? void 0 : _a.enableOnHoverClass)) {
1546
+ if (!((_a = window === null || window === void 0 ? void 0 : window.HIG_CONFIGURATION) === null || _a === void 0 ? void 0 : _a.enableOnHoverClass)) {
1507
1547
  return cssText;
1508
1548
  }
1509
1549
  var cachedStyle = cache === null || cache === void 0 ? void 0 : cache.stylesWithHoverClass.get(cssText);
@@ -1953,33 +1993,26 @@ const isCanvasNode = (node) => {
1953
1993
  }
1954
1994
  return false;
1955
1995
  };
1956
- function isBlocked(node, blockClass) {
1996
+ function isBlocked(node, blockClass, checkAncestors) {
1957
1997
  if (!node) {
1958
1998
  return false;
1959
1999
  }
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);
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;
1978
2010
  }
1979
- if (node.nodeType === node.TEXT_NODE) {
1980
- return isBlocked(node.parentNode, blockClass);
2011
+ else {
2012
+ if (classMatchesRegex(el, blockClass, checkAncestors))
2013
+ return true;
1981
2014
  }
1982
- return isBlocked(node.parentNode, blockClass);
2015
+ return false;
1983
2016
  }
1984
2017
  function isSerialized(n, mirror) {
1985
2018
  return mirror.getId(n) !== -1;
@@ -2400,6 +2433,7 @@ class MutationBuffer {
2400
2433
  onStylesheetLoad: (link, childSn) => {
2401
2434
  this.stylesheetManager.attachStylesheet(link, childSn, this.mirror);
2402
2435
  },
2436
+ newlyAddedElement: true,
2403
2437
  });
2404
2438
  if (sn) {
2405
2439
  adds.push({
@@ -2508,7 +2542,8 @@ class MutationBuffer {
2508
2542
  switch (m.type) {
2509
2543
  case 'characterData': {
2510
2544
  const value = m.target.textContent;
2511
- if (!isBlocked(m.target, this.blockClass) && value !== m.oldValue) {
2545
+ if (!isBlocked(m.target, this.blockClass, false) &&
2546
+ value !== m.oldValue) {
2512
2547
  this.texts.push({
2513
2548
  value: needMaskingText(m.target, this.maskTextClass, this.maskTextSelector) && value
2514
2549
  ? this.maskTextFn
@@ -2532,7 +2567,8 @@ class MutationBuffer {
2532
2567
  maskInputFn: this.maskInputFn,
2533
2568
  });
2534
2569
  }
2535
- if (isBlocked(m.target, this.blockClass) || value === m.oldValue) {
2570
+ if (isBlocked(m.target, this.blockClass, false) ||
2571
+ value === m.oldValue) {
2536
2572
  return;
2537
2573
  }
2538
2574
  let item = this.attributes.find((a) => a.node === m.target);
@@ -2586,13 +2622,15 @@ class MutationBuffer {
2586
2622
  break;
2587
2623
  }
2588
2624
  case 'childList': {
2625
+ if (isBlocked(m.target, this.blockClass, true))
2626
+ return;
2589
2627
  m.addedNodes.forEach((n) => this.genAdds(n, m.target));
2590
2628
  m.removedNodes.forEach((n) => {
2591
2629
  const nodeId = this.mirror.getId(n);
2592
2630
  const parentId = isShadowRoot(m.target)
2593
2631
  ? this.mirror.getId(m.target.host)
2594
2632
  : this.mirror.getId(m.target);
2595
- if (isBlocked(m.target, this.blockClass) ||
2633
+ if (isBlocked(m.target, this.blockClass, false) ||
2596
2634
  isIgnored(n, this.mirror) ||
2597
2635
  !isSerialized(n, this.mirror)) {
2598
2636
  return;
@@ -2621,16 +2659,13 @@ class MutationBuffer {
2621
2659
  }
2622
2660
  };
2623
2661
  this.genAdds = (n, target) => {
2624
- if (target && isBlocked(target, this.blockClass)) {
2625
- return;
2626
- }
2627
- if (this.mirror.getMeta(n)) {
2662
+ if (this.mirror.hasNode(n)) {
2628
2663
  if (isIgnored(n, this.mirror)) {
2629
2664
  return;
2630
2665
  }
2631
2666
  this.movedSet.add(n);
2632
2667
  let targetId = null;
2633
- if (target && this.mirror.getMeta(target)) {
2668
+ if (target && this.mirror.hasNode(target)) {
2634
2669
  targetId = this.mirror.getId(target);
2635
2670
  }
2636
2671
  if (targetId && targetId !== -1) {
@@ -2641,7 +2676,7 @@ class MutationBuffer {
2641
2676
  this.addedSet.add(n);
2642
2677
  this.droppedSet.delete(n);
2643
2678
  }
2644
- if (!isBlocked(n, this.blockClass))
2679
+ if (!isBlocked(n, this.blockClass, false))
2645
2680
  n.childNodes.forEach((childN) => this.genAdds(childN));
2646
2681
  };
2647
2682
  }
@@ -2701,6 +2736,11 @@ function deepDelete(addsSet, n) {
2701
2736
  n.childNodes.forEach((childN) => deepDelete(addsSet, childN));
2702
2737
  }
2703
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) {
2704
2744
  const { parentNode } = n;
2705
2745
  if (!parentNode) {
2706
2746
  return false;
@@ -2709,9 +2749,14 @@ function isParentRemoved(removes, n, mirror) {
2709
2749
  if (removes.some((r) => r.id === parentId)) {
2710
2750
  return true;
2711
2751
  }
2712
- return isParentRemoved(removes, parentNode, mirror);
2752
+ return _isParentRemoved(removes, parentNode, mirror);
2713
2753
  }
2714
2754
  function isAncestorInSet(set, n) {
2755
+ if (set.size === 0)
2756
+ return false;
2757
+ return _isAncestorInSet(set, n);
2758
+ }
2759
+ function _isAncestorInSet(set, n) {
2715
2760
  const { parentNode } = n;
2716
2761
  if (!parentNode) {
2717
2762
  return false;
@@ -2719,7 +2764,7 @@ function isAncestorInSet(set, n) {
2719
2764
  if (set.has(parentNode)) {
2720
2765
  return true;
2721
2766
  }
2722
- return isAncestorInSet(set, parentNode);
2767
+ return _isAncestorInSet(set, parentNode);
2723
2768
  }
2724
2769
 
2725
2770
  const mutationBuffers = [];
@@ -2829,7 +2874,7 @@ function initMouseInteractionObserver({ mouseInteractionCb, doc, mirror, blockCl
2829
2874
  const getHandler = (eventKey) => {
2830
2875
  return (event) => {
2831
2876
  const target = getEventTarget(event);
2832
- if (isBlocked(target, blockClass) ||
2877
+ if (isBlocked(target, blockClass, true) ||
2833
2878
  isCanvasNode(target)) {
2834
2879
  return;
2835
2880
  }
@@ -2863,7 +2908,7 @@ function initMouseInteractionObserver({ mouseInteractionCb, doc, mirror, blockCl
2863
2908
  function initScrollObserver({ scrollCb, doc, mirror, blockClass, sampling, }) {
2864
2909
  const updatePosition = throttle((evt) => {
2865
2910
  const target = getEventTarget(evt);
2866
- if (!target || isBlocked(target, blockClass)) {
2911
+ if (!target || isBlocked(target, blockClass, true)) {
2867
2912
  return;
2868
2913
  }
2869
2914
  const id = mirror.getId(target);
@@ -2919,7 +2964,7 @@ function initInputObserver({ inputCb, doc, mirror, blockClass, ignoreClass, mask
2919
2964
  if (!target ||
2920
2965
  !target.tagName ||
2921
2966
  INPUT_TAGS.indexOf(target.tagName) < 0 ||
2922
- isBlocked(target, blockClass)) {
2967
+ isBlocked(target, blockClass, true)) {
2923
2968
  return;
2924
2969
  }
2925
2970
  const type = target.type;
@@ -3054,8 +3099,8 @@ function initStyleSheetObserver({ styleSheetRuleCb, mirror }, { win }) {
3054
3099
  const unmodifiedFunctions = {};
3055
3100
  Object.entries(supportedNestedCSSRuleTypes).forEach(([typeKey, type]) => {
3056
3101
  unmodifiedFunctions[typeKey] = {
3057
- insertRule: (type).prototype.insertRule,
3058
- deleteRule: (type).prototype.deleteRule,
3102
+ insertRule: type.prototype.insertRule,
3103
+ deleteRule: type.prototype.deleteRule,
3059
3104
  };
3060
3105
  type.prototype.insertRule = function (rule, index) {
3061
3106
  const id = mirror.getId(this.parentStyleSheet.ownerNode);
@@ -3136,7 +3181,7 @@ function initStyleDeclarationObserver({ styleDeclarationCb, mirror }, { win }) {
3136
3181
  function initMediaInteractionObserver({ mediaInteractionCb, blockClass, mirror, sampling, }) {
3137
3182
  const handler = (type) => throttle((event) => {
3138
3183
  const target = getEventTarget(event);
3139
- if (!target || isBlocked(target, blockClass)) {
3184
+ if (!target || isBlocked(target, blockClass, true)) {
3140
3185
  return;
3141
3186
  }
3142
3187
  const { currentTime, volume, muted } = target;
@@ -3590,7 +3635,7 @@ function initCanvas2DMutationObserver(cb, win, blockClass, mirror) {
3590
3635
  }
3591
3636
  const restoreHandler = patch(win.CanvasRenderingContext2D.prototype, prop, function (original) {
3592
3637
  return function (...args) {
3593
- if (!isBlocked(this.canvas, blockClass)) {
3638
+ if (!isBlocked(this.canvas, blockClass, true)) {
3594
3639
  setTimeout(() => {
3595
3640
  const recordArgs = serializeArgs([...args], win, this);
3596
3641
  cb(this.canvas, {
@@ -3629,9 +3674,9 @@ function initCanvasContextObserver(win, blockClass) {
3629
3674
  try {
3630
3675
  const restoreHandler = patch(win.HTMLCanvasElement.prototype, 'getContext', function (original) {
3631
3676
  return function (contextType, ...args) {
3632
- if (!isBlocked(this, blockClass)) {
3677
+ if (!isBlocked(this, blockClass, true)) {
3633
3678
  if (!('__context' in this))
3634
- (this).__context = contextType;
3679
+ this.__context = contextType;
3635
3680
  }
3636
3681
  return original.apply(this, [contextType, ...args]);
3637
3682
  };
@@ -3658,8 +3703,7 @@ function patchGLPrototype(prototype, type, cb, blockClass, mirror, win) {
3658
3703
  return function (...args) {
3659
3704
  const result = original.apply(this, args);
3660
3705
  saveWebGLVar(result, win, prototype);
3661
- if (!isBlocked(this.canvas, blockClass)) {
3662
- const id = mirror.getId(this.canvas);
3706
+ if (!isBlocked(this.canvas, blockClass, true)) {
3663
3707
  const recordArgs = serializeArgs([...args], win, prototype);
3664
3708
  const mutation = {
3665
3709
  type,
@@ -4138,6 +4182,9 @@ function record(options = {}) {
4138
4182
  if (isSerializedIframe(n, mirror)) {
4139
4183
  iframeManager.addIframe(n);
4140
4184
  }
4185
+ if (isSerializedStylesheet(n, mirror)) {
4186
+ stylesheetManager.addStylesheet(n);
4187
+ }
4141
4188
  if (hasShadowRoot(n)) {
4142
4189
  shadowDomManager.addShadowRoot(n.shadowRoot, document);
4143
4190
  }
@@ -4147,7 +4194,7 @@ function record(options = {}) {
4147
4194
  shadowDomManager.observeAttachShadow(iframe);
4148
4195
  },
4149
4196
  onStylesheetLoad: (linkEl, childSn) => {
4150
- this.stylesheetManager.attachStylesheet(linkEl, childSn, this.mirror);
4197
+ stylesheetManager.attachStylesheet(linkEl, childSn, mirror);
4151
4198
  },
4152
4199
  keepIframeSrcFn,
4153
4200
  });