@glimt/record 0.0.41 → 0.0.43

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.
package/dist/record.cjs CHANGED
@@ -812,7 +812,7 @@ function splitCssText(cssText, style, _testNoPxNorm = false) {
812
812
  function markCssSplits(cssText, style) {
813
813
  return splitCssText(cssText, style).join("/* rr_split */");
814
814
  }
815
- const CLEANUP_DEBOUNCE_TIME$1 = 1e3 * 60 * 5;
815
+ const CLEANUP_DEBOUNCE_TIME$1 = 1e3 * 60 * 2;
816
816
  const _AsyncStylesheetManager$1 = class _AsyncStylesheetManager {
817
817
  constructor() {
818
818
  __publicField$1(this, "currentHref", null);
@@ -821,23 +821,44 @@ const _AsyncStylesheetManager$1 = class _AsyncStylesheetManager {
821
821
  if (_AsyncStylesheetManager.instance) return _AsyncStylesheetManager.instance;
822
822
  _AsyncStylesheetManager.instance = this;
823
823
  }
824
+ removeCloneNode(href) {
825
+ if (!(href in this.clones) || this.clones[href] === void 0) return;
826
+ const clone = document.querySelector(
827
+ `link[data-rrweb-link-cloned="${this.clones[href].cloneNodeAttrId}"]`
828
+ );
829
+ if (!clone) return;
830
+ document.head.removeChild(clone);
831
+ }
824
832
  onLoad(href) {
825
833
  if (!(href in this.clones) || this.clones[href] === void 0) return;
826
834
  console.log("AsyncStylesheetManager, onLoad: href:", href);
827
835
  const styleSheets2 = Array.from(document.styleSheets);
828
836
  let clonedStyleSheet = null;
829
- document.head.removeChild(this.clones[href].clone);
830
837
  for (let i2 = styleSheets2.length - 1; i2 >= 0; i2--) {
831
838
  if (styleSheets2[i2].href === href) {
832
839
  clonedStyleSheet = styleSheets2[i2];
833
840
  break;
834
841
  }
835
842
  }
836
- if (!clonedStyleSheet) return;
843
+ if (!clonedStyleSheet) {
844
+ console.log(
845
+ "AsyncStylesheetManager, onLoad: couldn't find stylesheet for href:",
846
+ href
847
+ );
848
+ return this.removeCloneNode(href);
849
+ }
837
850
  const newCssText = stringifyStylesheet$1(clonedStyleSheet);
838
- if (!newCssText) return;
851
+ this.removeCloneNode(href);
852
+ if (!newCssText) {
853
+ console.log(
854
+ "AsyncStylesheetManager, onLoad: couldn't stringify stylesheet for href:",
855
+ href
856
+ );
857
+ return;
858
+ }
839
859
  console.log(
840
- "AsyncStylesheetManager, onLoad: success! did get new css text! forcing mutation..."
860
+ "AsyncStylesheetManager, onLoad: success! did get new css text! forcing mutation... for href:",
861
+ href
841
862
  );
842
863
  this.clones[href].cssText = newCssText;
843
864
  this.clones[href].loaded = true;
@@ -848,12 +869,11 @@ const _AsyncStylesheetManager$1 = class _AsyncStylesheetManager {
848
869
  }
849
870
  onLoadError(href) {
850
871
  if (!(href in this.clones) || this.clones[href] === void 0) return;
851
- document.head.removeChild(this.clones[href].clone);
872
+ this.removeCloneNode(href);
852
873
  }
853
874
  removeAllCloneElements() {
854
- for (const clone of Object.values(this.clones)) {
855
- if (!clone) continue;
856
- document.head.removeChild(clone.clone);
875
+ for (const href of Object.keys(this.clones)) {
876
+ this.removeCloneNode(href);
857
877
  }
858
878
  }
859
879
  onCleanTimeout() {
@@ -871,10 +891,6 @@ const _AsyncStylesheetManager$1 = class _AsyncStylesheetManager {
871
891
  this.blowCache();
872
892
  this.currentHref = document.location.href;
873
893
  const href = forElement.href;
874
- console.log(
875
- "AsyncStylesheetManager, registerClone: wants a clone for href:",
876
- href
877
- );
878
894
  if (!href) return;
879
895
  if (href in this.clones && this.clones[href] !== void 0) return;
880
896
  if (forElement.getAttribute("crossorigin") === "anonymous") return;
@@ -883,14 +899,16 @@ const _AsyncStylesheetManager$1 = class _AsyncStylesheetManager {
883
899
  href
884
900
  );
885
901
  const clone = forElement.cloneNode();
902
+ const cloneNodeAttrId = Math.random().toString(36).slice(2);
886
903
  clone.setAttribute("crossorigin", "anonymous");
887
- clone.setAttribute("data-rrweb-link-cloned", "true");
904
+ clone.setAttribute("data-rrweb-link-cloned", cloneNodeAttrId);
888
905
  document.head.appendChild(clone);
889
906
  this.clones[href] = {
890
907
  original: forElement,
891
908
  clone,
892
909
  loaded: false,
893
- cssText: null
910
+ cssText: null,
911
+ cloneNodeAttrId
894
912
  };
895
913
  clone.onload = () => {
896
914
  this.onLoad(href);
@@ -904,7 +922,8 @@ const _AsyncStylesheetManager$1 = class _AsyncStylesheetManager {
904
922
  getClonedCssTextIfAvailable(href) {
905
923
  if (href in this.clones && this.clones[href] !== void 0 && this.clones[href].loaded === true) {
906
924
  console.log(
907
- "AsyncStylesheetManager, getClonedCssTextIfAvailable: returning cloned cssText!"
925
+ "AsyncStylesheetManager, getClonedCssTextIfAvailable: returning cloned cssText, for href:",
926
+ href
908
927
  );
909
928
  return this.clones[href].cssText;
910
929
  }
@@ -1306,10 +1325,13 @@ function serializeElementNode(n2, options) {
1306
1325
  }
1307
1326
  if (tagName === "link" && inlineStylesheet) {
1308
1327
  const styleSheets2 = Array.from(doc.styleSheets);
1309
- const styleSheetIndex = styleSheets2.findIndex((s2) => {
1310
- return s2.href === n2.href;
1311
- });
1312
- const stylesheet = styleSheets2[styleSheetIndex];
1328
+ let stylesheet = null;
1329
+ for (let i2 = 0; i2 < styleSheets2.length; i2++) {
1330
+ if (styleSheets2[i2].href === n2.href) {
1331
+ stylesheet = styleSheets2[i2];
1332
+ break;
1333
+ }
1334
+ }
1313
1335
  let cssText = null;
1314
1336
  if (stylesheet) {
1315
1337
  cssText = stringifyStylesheet$1(stylesheet);
@@ -1324,10 +1346,6 @@ function serializeElementNode(n2, options) {
1324
1346
  delete attributes.href;
1325
1347
  attributes._cssText = cssText;
1326
1348
  } else {
1327
- console.log(
1328
- "missing cssText on first passthrough for href:",
1329
- n2.href
1330
- );
1331
1349
  asyncStylesheetManager.registerClone({
1332
1350
  forElement: n2
1333
1351
  });
@@ -5617,7 +5635,7 @@ function absolutifyURLs(cssText, href) {
5617
5635
  }
5618
5636
  );
5619
5637
  }
5620
- const CLEANUP_DEBOUNCE_TIME = 1e3 * 60 * 5;
5638
+ const CLEANUP_DEBOUNCE_TIME = 1e3 * 60 * 2;
5621
5639
  const _AsyncStylesheetManager2 = class _AsyncStylesheetManager22 {
5622
5640
  constructor() {
5623
5641
  __publicField22(this, "currentHref", null);
@@ -5626,23 +5644,44 @@ const _AsyncStylesheetManager2 = class _AsyncStylesheetManager22 {
5626
5644
  if (_AsyncStylesheetManager22.instance) return _AsyncStylesheetManager22.instance;
5627
5645
  _AsyncStylesheetManager22.instance = this;
5628
5646
  }
5647
+ removeCloneNode(href) {
5648
+ if (!(href in this.clones) || this.clones[href] === void 0) return;
5649
+ const clone = document.querySelector(
5650
+ `link[data-rrweb-link-cloned="${this.clones[href].cloneNodeAttrId}"]`
5651
+ );
5652
+ if (!clone) return;
5653
+ document.head.removeChild(clone);
5654
+ }
5629
5655
  onLoad(href) {
5630
5656
  if (!(href in this.clones) || this.clones[href] === void 0) return;
5631
5657
  console.log("AsyncStylesheetManager, onLoad: href:", href);
5632
5658
  const styleSheets2 = Array.from(document.styleSheets);
5633
5659
  let clonedStyleSheet = null;
5634
- document.head.removeChild(this.clones[href].clone);
5635
5660
  for (let i2 = styleSheets2.length - 1; i2 >= 0; i2--) {
5636
5661
  if (styleSheets2[i2].href === href) {
5637
5662
  clonedStyleSheet = styleSheets2[i2];
5638
5663
  break;
5639
5664
  }
5640
5665
  }
5641
- if (!clonedStyleSheet) return;
5666
+ if (!clonedStyleSheet) {
5667
+ console.log(
5668
+ "AsyncStylesheetManager, onLoad: couldn't find stylesheet for href:",
5669
+ href
5670
+ );
5671
+ return this.removeCloneNode(href);
5672
+ }
5642
5673
  const newCssText = stringifyStylesheet(clonedStyleSheet);
5643
- if (!newCssText) return;
5674
+ this.removeCloneNode(href);
5675
+ if (!newCssText) {
5676
+ console.log(
5677
+ "AsyncStylesheetManager, onLoad: couldn't stringify stylesheet for href:",
5678
+ href
5679
+ );
5680
+ return;
5681
+ }
5644
5682
  console.log(
5645
- "AsyncStylesheetManager, onLoad: success! did get new css text! forcing mutation..."
5683
+ "AsyncStylesheetManager, onLoad: success! did get new css text! forcing mutation... for href:",
5684
+ href
5646
5685
  );
5647
5686
  this.clones[href].cssText = newCssText;
5648
5687
  this.clones[href].loaded = true;
@@ -5653,12 +5692,11 @@ const _AsyncStylesheetManager2 = class _AsyncStylesheetManager22 {
5653
5692
  }
5654
5693
  onLoadError(href) {
5655
5694
  if (!(href in this.clones) || this.clones[href] === void 0) return;
5656
- document.head.removeChild(this.clones[href].clone);
5695
+ this.removeCloneNode(href);
5657
5696
  }
5658
5697
  removeAllCloneElements() {
5659
- for (const clone of Object.values(this.clones)) {
5660
- if (!clone) continue;
5661
- document.head.removeChild(clone.clone);
5698
+ for (const href of Object.keys(this.clones)) {
5699
+ this.removeCloneNode(href);
5662
5700
  }
5663
5701
  }
5664
5702
  onCleanTimeout() {
@@ -5676,10 +5714,6 @@ const _AsyncStylesheetManager2 = class _AsyncStylesheetManager22 {
5676
5714
  this.blowCache();
5677
5715
  this.currentHref = document.location.href;
5678
5716
  const href = forElement.href;
5679
- console.log(
5680
- "AsyncStylesheetManager, registerClone: wants a clone for href:",
5681
- href
5682
- );
5683
5717
  if (!href) return;
5684
5718
  if (href in this.clones && this.clones[href] !== void 0) return;
5685
5719
  if (forElement.getAttribute("crossorigin") === "anonymous") return;
@@ -5688,14 +5722,16 @@ const _AsyncStylesheetManager2 = class _AsyncStylesheetManager22 {
5688
5722
  href
5689
5723
  );
5690
5724
  const clone = forElement.cloneNode();
5725
+ const cloneNodeAttrId = Math.random().toString(36).slice(2);
5691
5726
  clone.setAttribute("crossorigin", "anonymous");
5692
- clone.setAttribute("data-rrweb-link-cloned", "true");
5727
+ clone.setAttribute("data-rrweb-link-cloned", cloneNodeAttrId);
5693
5728
  document.head.appendChild(clone);
5694
5729
  this.clones[href] = {
5695
5730
  original: forElement,
5696
5731
  clone,
5697
5732
  loaded: false,
5698
- cssText: null
5733
+ cssText: null,
5734
+ cloneNodeAttrId
5699
5735
  };
5700
5736
  clone.onload = () => {
5701
5737
  this.onLoad(href);
@@ -5709,7 +5745,8 @@ const _AsyncStylesheetManager2 = class _AsyncStylesheetManager22 {
5709
5745
  getClonedCssTextIfAvailable(href) {
5710
5746
  if (href in this.clones && this.clones[href] !== void 0 && this.clones[href].loaded === true) {
5711
5747
  console.log(
5712
- "AsyncStylesheetManager, getClonedCssTextIfAvailable: returning cloned cssText!"
5748
+ "AsyncStylesheetManager, getClonedCssTextIfAvailable: returning cloned cssText, for href:",
5749
+ href
5713
5750
  );
5714
5751
  return this.clones[href].cssText;
5715
5752
  }