@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.
@@ -845,7 +845,7 @@ function splitCssText(cssText, style, _testNoPxNorm = false) {
845
845
  function markCssSplits(cssText, style) {
846
846
  return splitCssText(cssText, style).join("/* rr_split */");
847
847
  }
848
- const CLEANUP_DEBOUNCE_TIME$1 = 1e3 * 60 * 5;
848
+ const CLEANUP_DEBOUNCE_TIME$1 = 1e3 * 60 * 2;
849
849
  const _AsyncStylesheetManager$1 = class _AsyncStylesheetManager {
850
850
  constructor() {
851
851
  __publicField$1(this, "currentHref", null);
@@ -854,23 +854,44 @@ const _AsyncStylesheetManager$1 = class _AsyncStylesheetManager {
854
854
  if (_AsyncStylesheetManager.instance) return _AsyncStylesheetManager.instance;
855
855
  _AsyncStylesheetManager.instance = this;
856
856
  }
857
+ removeCloneNode(href) {
858
+ if (!(href in this.clones) || this.clones[href] === void 0) return;
859
+ const clone = document.querySelector(
860
+ `link[data-rrweb-link-cloned="${this.clones[href].cloneNodeAttrId}"]`
861
+ );
862
+ if (!clone) return;
863
+ document.head.removeChild(clone);
864
+ }
857
865
  onLoad(href) {
858
866
  if (!(href in this.clones) || this.clones[href] === void 0) return;
859
867
  console.log("AsyncStylesheetManager, onLoad: href:", href);
860
868
  const styleSheets2 = Array.from(document.styleSheets);
861
869
  let clonedStyleSheet = null;
862
- document.head.removeChild(this.clones[href].clone);
863
870
  for (let i2 = styleSheets2.length - 1; i2 >= 0; i2--) {
864
871
  if (styleSheets2[i2].href === href) {
865
872
  clonedStyleSheet = styleSheets2[i2];
866
873
  break;
867
874
  }
868
875
  }
869
- if (!clonedStyleSheet) return;
876
+ if (!clonedStyleSheet) {
877
+ console.log(
878
+ "AsyncStylesheetManager, onLoad: couldn't find stylesheet for href:",
879
+ href
880
+ );
881
+ return this.removeCloneNode(href);
882
+ }
870
883
  const newCssText = stringifyStylesheet$1(clonedStyleSheet);
871
- if (!newCssText) return;
884
+ this.removeCloneNode(href);
885
+ if (!newCssText) {
886
+ console.log(
887
+ "AsyncStylesheetManager, onLoad: couldn't stringify stylesheet for href:",
888
+ href
889
+ );
890
+ return;
891
+ }
872
892
  console.log(
873
- "AsyncStylesheetManager, onLoad: success! did get new css text! forcing mutation..."
893
+ "AsyncStylesheetManager, onLoad: success! did get new css text! forcing mutation... for href:",
894
+ href
874
895
  );
875
896
  this.clones[href].cssText = newCssText;
876
897
  this.clones[href].loaded = true;
@@ -881,12 +902,11 @@ const _AsyncStylesheetManager$1 = class _AsyncStylesheetManager {
881
902
  }
882
903
  onLoadError(href) {
883
904
  if (!(href in this.clones) || this.clones[href] === void 0) return;
884
- document.head.removeChild(this.clones[href].clone);
905
+ this.removeCloneNode(href);
885
906
  }
886
907
  removeAllCloneElements() {
887
- for (const clone of Object.values(this.clones)) {
888
- if (!clone) continue;
889
- document.head.removeChild(clone.clone);
908
+ for (const href of Object.keys(this.clones)) {
909
+ this.removeCloneNode(href);
890
910
  }
891
911
  }
892
912
  onCleanTimeout() {
@@ -904,10 +924,6 @@ const _AsyncStylesheetManager$1 = class _AsyncStylesheetManager {
904
924
  this.blowCache();
905
925
  this.currentHref = document.location.href;
906
926
  const href = forElement.href;
907
- console.log(
908
- "AsyncStylesheetManager, registerClone: wants a clone for href:",
909
- href
910
- );
911
927
  if (!href) return;
912
928
  if (href in this.clones && this.clones[href] !== void 0) return;
913
929
  if (forElement.getAttribute("crossorigin") === "anonymous") return;
@@ -916,14 +932,16 @@ const _AsyncStylesheetManager$1 = class _AsyncStylesheetManager {
916
932
  href
917
933
  );
918
934
  const clone = forElement.cloneNode();
935
+ const cloneNodeAttrId = Math.random().toString(36).slice(2);
919
936
  clone.setAttribute("crossorigin", "anonymous");
920
- clone.setAttribute("data-rrweb-link-cloned", "true");
937
+ clone.setAttribute("data-rrweb-link-cloned", cloneNodeAttrId);
921
938
  document.head.appendChild(clone);
922
939
  this.clones[href] = {
923
940
  original: forElement,
924
941
  clone,
925
942
  loaded: false,
926
- cssText: null
943
+ cssText: null,
944
+ cloneNodeAttrId
927
945
  };
928
946
  clone.onload = () => {
929
947
  this.onLoad(href);
@@ -937,7 +955,8 @@ const _AsyncStylesheetManager$1 = class _AsyncStylesheetManager {
937
955
  getClonedCssTextIfAvailable(href) {
938
956
  if (href in this.clones && this.clones[href] !== void 0 && this.clones[href].loaded === true) {
939
957
  console.log(
940
- "AsyncStylesheetManager, getClonedCssTextIfAvailable: returning cloned cssText!"
958
+ "AsyncStylesheetManager, getClonedCssTextIfAvailable: returning cloned cssText, for href:",
959
+ href
941
960
  );
942
961
  return this.clones[href].cssText;
943
962
  }
@@ -1339,10 +1358,13 @@ function serializeElementNode(n2, options) {
1339
1358
  }
1340
1359
  if (tagName === "link" && inlineStylesheet) {
1341
1360
  const styleSheets2 = Array.from(doc.styleSheets);
1342
- const styleSheetIndex = styleSheets2.findIndex((s2) => {
1343
- return s2.href === n2.href;
1344
- });
1345
- const stylesheet = styleSheets2[styleSheetIndex];
1361
+ let stylesheet = null;
1362
+ for (let i2 = 0; i2 < styleSheets2.length; i2++) {
1363
+ if (styleSheets2[i2].href === n2.href) {
1364
+ stylesheet = styleSheets2[i2];
1365
+ break;
1366
+ }
1367
+ }
1346
1368
  let cssText = null;
1347
1369
  if (stylesheet) {
1348
1370
  cssText = stringifyStylesheet$1(stylesheet);
@@ -1357,10 +1379,6 @@ function serializeElementNode(n2, options) {
1357
1379
  delete attributes.href;
1358
1380
  attributes._cssText = cssText;
1359
1381
  } else {
1360
- console.log(
1361
- "missing cssText on first passthrough for href:",
1362
- n2.href
1363
- );
1364
1382
  asyncStylesheetManager.registerClone({
1365
1383
  forElement: n2
1366
1384
  });
@@ -5654,7 +5672,7 @@ function absolutifyURLs(cssText, href) {
5654
5672
  }
5655
5673
  );
5656
5674
  }
5657
- const CLEANUP_DEBOUNCE_TIME = 1e3 * 60 * 5;
5675
+ const CLEANUP_DEBOUNCE_TIME = 1e3 * 60 * 2;
5658
5676
  const _AsyncStylesheetManager2 = class _AsyncStylesheetManager22 {
5659
5677
  constructor() {
5660
5678
  __publicField22(this, "currentHref", null);
@@ -5663,23 +5681,44 @@ const _AsyncStylesheetManager2 = class _AsyncStylesheetManager22 {
5663
5681
  if (_AsyncStylesheetManager22.instance) return _AsyncStylesheetManager22.instance;
5664
5682
  _AsyncStylesheetManager22.instance = this;
5665
5683
  }
5684
+ removeCloneNode(href) {
5685
+ if (!(href in this.clones) || this.clones[href] === void 0) return;
5686
+ const clone = document.querySelector(
5687
+ `link[data-rrweb-link-cloned="${this.clones[href].cloneNodeAttrId}"]`
5688
+ );
5689
+ if (!clone) return;
5690
+ document.head.removeChild(clone);
5691
+ }
5666
5692
  onLoad(href) {
5667
5693
  if (!(href in this.clones) || this.clones[href] === void 0) return;
5668
5694
  console.log("AsyncStylesheetManager, onLoad: href:", href);
5669
5695
  const styleSheets2 = Array.from(document.styleSheets);
5670
5696
  let clonedStyleSheet = null;
5671
- document.head.removeChild(this.clones[href].clone);
5672
5697
  for (let i2 = styleSheets2.length - 1; i2 >= 0; i2--) {
5673
5698
  if (styleSheets2[i2].href === href) {
5674
5699
  clonedStyleSheet = styleSheets2[i2];
5675
5700
  break;
5676
5701
  }
5677
5702
  }
5678
- if (!clonedStyleSheet) return;
5703
+ if (!clonedStyleSheet) {
5704
+ console.log(
5705
+ "AsyncStylesheetManager, onLoad: couldn't find stylesheet for href:",
5706
+ href
5707
+ );
5708
+ return this.removeCloneNode(href);
5709
+ }
5679
5710
  const newCssText = stringifyStylesheet(clonedStyleSheet);
5680
- if (!newCssText) return;
5711
+ this.removeCloneNode(href);
5712
+ if (!newCssText) {
5713
+ console.log(
5714
+ "AsyncStylesheetManager, onLoad: couldn't stringify stylesheet for href:",
5715
+ href
5716
+ );
5717
+ return;
5718
+ }
5681
5719
  console.log(
5682
- "AsyncStylesheetManager, onLoad: success! did get new css text! forcing mutation..."
5720
+ "AsyncStylesheetManager, onLoad: success! did get new css text! forcing mutation... for href:",
5721
+ href
5683
5722
  );
5684
5723
  this.clones[href].cssText = newCssText;
5685
5724
  this.clones[href].loaded = true;
@@ -5690,12 +5729,11 @@ const _AsyncStylesheetManager2 = class _AsyncStylesheetManager22 {
5690
5729
  }
5691
5730
  onLoadError(href) {
5692
5731
  if (!(href in this.clones) || this.clones[href] === void 0) return;
5693
- document.head.removeChild(this.clones[href].clone);
5732
+ this.removeCloneNode(href);
5694
5733
  }
5695
5734
  removeAllCloneElements() {
5696
- for (const clone of Object.values(this.clones)) {
5697
- if (!clone) continue;
5698
- document.head.removeChild(clone.clone);
5735
+ for (const href of Object.keys(this.clones)) {
5736
+ this.removeCloneNode(href);
5699
5737
  }
5700
5738
  }
5701
5739
  onCleanTimeout() {
@@ -5713,10 +5751,6 @@ const _AsyncStylesheetManager2 = class _AsyncStylesheetManager22 {
5713
5751
  this.blowCache();
5714
5752
  this.currentHref = document.location.href;
5715
5753
  const href = forElement.href;
5716
- console.log(
5717
- "AsyncStylesheetManager, registerClone: wants a clone for href:",
5718
- href
5719
- );
5720
5754
  if (!href) return;
5721
5755
  if (href in this.clones && this.clones[href] !== void 0) return;
5722
5756
  if (forElement.getAttribute("crossorigin") === "anonymous") return;
@@ -5725,14 +5759,16 @@ const _AsyncStylesheetManager2 = class _AsyncStylesheetManager22 {
5725
5759
  href
5726
5760
  );
5727
5761
  const clone = forElement.cloneNode();
5762
+ const cloneNodeAttrId = Math.random().toString(36).slice(2);
5728
5763
  clone.setAttribute("crossorigin", "anonymous");
5729
- clone.setAttribute("data-rrweb-link-cloned", "true");
5764
+ clone.setAttribute("data-rrweb-link-cloned", cloneNodeAttrId);
5730
5765
  document.head.appendChild(clone);
5731
5766
  this.clones[href] = {
5732
5767
  original: forElement,
5733
5768
  clone,
5734
5769
  loaded: false,
5735
- cssText: null
5770
+ cssText: null,
5771
+ cloneNodeAttrId
5736
5772
  };
5737
5773
  clone.onload = () => {
5738
5774
  this.onLoad(href);
@@ -5746,7 +5782,8 @@ const _AsyncStylesheetManager2 = class _AsyncStylesheetManager22 {
5746
5782
  getClonedCssTextIfAvailable(href) {
5747
5783
  if (href in this.clones && this.clones[href] !== void 0 && this.clones[href].loaded === true) {
5748
5784
  console.log(
5749
- "AsyncStylesheetManager, getClonedCssTextIfAvailable: returning cloned cssText!"
5785
+ "AsyncStylesheetManager, getClonedCssTextIfAvailable: returning cloned cssText, for href:",
5786
+ href
5750
5787
  );
5751
5788
  return this.clones[href].cssText;
5752
5789
  }