@glimt/record 0.0.45 → 0.0.46

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
@@ -813,6 +813,7 @@ function markCssSplits(cssText, style) {
813
813
  return splitCssText(cssText, style).join("/* rr_split */");
814
814
  }
815
815
  const CLEANUP_DEBOUNCE_TIME$1 = 1e3 * 30;
816
+ const DATA_ATTRIBUTE_CLONED_NAME$1 = "data-rrweb-link-cloned";
816
817
  const DISALLOWED_EXTENSIONS$1 = [
817
818
  // Fonts
818
819
  "woff",
@@ -869,14 +870,13 @@ const _AsyncStylesheetManager$1 = class _AsyncStylesheetManager {
869
870
  var _a2;
870
871
  if (!(href in this.clones) || this.clones[href] === void 0) return;
871
872
  const clone = document.querySelector(
872
- `link[data-rrweb-link-cloned="${this.clones[href].cloneNodeAttrId}"]`
873
+ `link[${DATA_ATTRIBUTE_CLONED_NAME$1}="${this.clones[href].cloneNodeAttrId}"]`
873
874
  );
874
875
  if (!clone) return;
875
876
  (_a2 = clone.parentNode) == null ? void 0 : _a2.removeChild(clone);
876
877
  }
877
878
  onLoad(href) {
878
879
  if (!(href in this.clones) || this.clones[href] === void 0) return;
879
- console.log("AsyncStylesheetManager, onLoad: href:", href);
880
880
  const styleSheets2 = Array.from(document.styleSheets);
881
881
  let clonedStyleSheet = null;
882
882
  for (let i2 = styleSheets2.length - 1; i2 >= 0; i2--) {
@@ -885,39 +885,38 @@ const _AsyncStylesheetManager$1 = class _AsyncStylesheetManager {
885
885
  break;
886
886
  }
887
887
  }
888
- if (!clonedStyleSheet) {
889
- console.log(
890
- "AsyncStylesheetManager, onLoad: couldn't find stylesheet for href:",
891
- href
892
- );
893
- return this.removeCloneNode(href);
894
- }
888
+ if (!clonedStyleSheet) return this.removeCloneNode(href);
895
889
  const newCssText = stringifyStylesheet$1(clonedStyleSheet);
896
890
  this.removeCloneNode(href);
897
- if (!newCssText) {
898
- console.log(
899
- "AsyncStylesheetManager, onLoad: couldn't stringify stylesheet for href:",
900
- href
901
- );
902
- return;
903
- }
904
- console.log(
905
- "AsyncStylesheetManager, onLoad: success! did get new css text! forcing mutation... for href:",
906
- href
907
- );
891
+ if (!newCssText) return;
908
892
  this.clones[href].cssText = newCssText;
909
893
  this.clones[href].loaded = true;
910
894
  const original = document.querySelector(
911
- `link[data-rrweb-link-cloned="source-${this.clones[href].cloneNodeAttrId}"]`
895
+ `link[${DATA_ATTRIBUTE_CLONED_NAME$1}="source-${this.clones[href].cloneNodeAttrId}"]`
912
896
  );
913
- if (!original) {
897
+ if (original) {
898
+ original.setAttribute("data-rrweb-mutation", Date.now().toString());
899
+ original.removeAttribute(DATA_ATTRIBUTE_CLONED_NAME$1);
900
+ } else {
914
901
  this.clones[href].original.setAttribute(
915
902
  "data-rrweb-mutation",
916
903
  Date.now().toString()
917
904
  );
918
- } else {
919
- original.setAttribute("data-rrweb-mutation", Date.now().toString());
905
+ this.clones[href].original.removeAttribute(DATA_ATTRIBUTE_CLONED_NAME$1);
920
906
  }
907
+ window.dispatchEvent(
908
+ new CustomEvent("__rrweb_custom_event__", {
909
+ detail: {
910
+ type: 5,
911
+ timestamp: Date.now(),
912
+ data: {
913
+ tag: "async-css-resolution",
914
+ requestCssId: this.clones[href].requestCssId,
915
+ cssText: this.clones[href].cssText
916
+ }
917
+ }
918
+ })
919
+ );
921
920
  }
922
921
  onLoadError(href) {
923
922
  if (!(href in this.clones) || this.clones[href] === void 0) return;
@@ -929,16 +928,17 @@ const _AsyncStylesheetManager$1 = class _AsyncStylesheetManager {
929
928
  }
930
929
  }
931
930
  onCleanTimeout() {
932
- console.log("AsyncStylesheetManager, onCleanTimeout: cleaning up");
933
931
  asyncStylesheetManager$1.cleanTimeout = null;
934
932
  asyncStylesheetManager$1.removeAllCloneElements();
935
933
  }
936
934
  blowCache() {
937
- console.log("AsyncStylesheetManager, blowCache: blowing cache");
938
935
  this.removeAllCloneElements();
939
936
  this.clones = {};
940
937
  }
941
- registerClone({ forElement }) {
938
+ requestClone({
939
+ forElement,
940
+ requestCssId
941
+ }) {
942
942
  if (this.currentHref != null && document.location.href !== this.currentHref)
943
943
  this.blowCache();
944
944
  this.currentHref = document.location.href;
@@ -956,16 +956,12 @@ const _AsyncStylesheetManager$1 = class _AsyncStylesheetManager {
956
956
  }
957
957
  }
958
958
  }
959
- console.log(
960
- "AsyncStylesheetManager, registerClone: registering clone for href:",
961
- href
962
- );
963
959
  const clone = forElement.cloneNode();
964
960
  const cloneNodeAttrId = Math.random().toString(36).slice(2);
965
961
  clone.setAttribute("crossorigin", "anonymous");
966
- clone.setAttribute("data-rrweb-link-cloned", cloneNodeAttrId);
962
+ clone.setAttribute(DATA_ATTRIBUTE_CLONED_NAME$1, cloneNodeAttrId);
967
963
  forElement.setAttribute(
968
- "data-rrweb-link-cloned",
964
+ DATA_ATTRIBUTE_CLONED_NAME$1,
969
965
  `source-${cloneNodeAttrId}`
970
966
  );
971
967
  document.head.appendChild(clone);
@@ -974,7 +970,8 @@ const _AsyncStylesheetManager$1 = class _AsyncStylesheetManager {
974
970
  clone,
975
971
  loaded: false,
976
972
  cssText: null,
977
- cloneNodeAttrId
973
+ cloneNodeAttrId,
974
+ requestCssId
978
975
  };
979
976
  clone.onload = () => {
980
977
  this.onLoad(href);
@@ -990,10 +987,6 @@ const _AsyncStylesheetManager$1 = class _AsyncStylesheetManager {
990
987
  }
991
988
  getClonedCssTextIfAvailable(href) {
992
989
  if (href in this.clones && this.clones[href] !== void 0 && this.clones[href].loaded === true) {
993
- console.log(
994
- "AsyncStylesheetManager, getClonedCssTextIfAvailable: returning cloned cssText, for href:",
995
- href
996
- );
997
990
  return this.clones[href].cssText;
998
991
  }
999
992
  return null;
@@ -1415,9 +1408,12 @@ function serializeElementNode(n2, options) {
1415
1408
  delete attributes.href;
1416
1409
  attributes._cssText = cssText;
1417
1410
  } else {
1418
- asyncStylesheetManager$1.registerClone({
1419
- forElement: n2
1411
+ const requestCssId = `css-request-${Math.random().toString(36).slice(2)}`;
1412
+ asyncStylesheetManager$1.requestClone({
1413
+ forElement: n2,
1414
+ requestCssId
1420
1415
  });
1416
+ attributes._requestCssId = requestCssId;
1421
1417
  }
1422
1418
  }
1423
1419
  if (tagName === "style" && n2.sheet) {
@@ -5705,6 +5701,7 @@ function absolutifyURLs(cssText, href) {
5705
5701
  );
5706
5702
  }
5707
5703
  const CLEANUP_DEBOUNCE_TIME = 1e3 * 30;
5704
+ const DATA_ATTRIBUTE_CLONED_NAME = "data-rrweb-link-cloned";
5708
5705
  const DISALLOWED_EXTENSIONS = [
5709
5706
  // Fonts
5710
5707
  "woff",
@@ -5761,14 +5758,13 @@ const _AsyncStylesheetManager2 = class _AsyncStylesheetManager22 {
5761
5758
  var _a2;
5762
5759
  if (!(href in this.clones) || this.clones[href] === void 0) return;
5763
5760
  const clone = document.querySelector(
5764
- `link[data-rrweb-link-cloned="${this.clones[href].cloneNodeAttrId}"]`
5761
+ `link[${DATA_ATTRIBUTE_CLONED_NAME}="${this.clones[href].cloneNodeAttrId}"]`
5765
5762
  );
5766
5763
  if (!clone) return;
5767
5764
  (_a2 = clone.parentNode) == null ? void 0 : _a2.removeChild(clone);
5768
5765
  }
5769
5766
  onLoad(href) {
5770
5767
  if (!(href in this.clones) || this.clones[href] === void 0) return;
5771
- console.log("AsyncStylesheetManager, onLoad: href:", href);
5772
5768
  const styleSheets2 = Array.from(document.styleSheets);
5773
5769
  let clonedStyleSheet = null;
5774
5770
  for (let i2 = styleSheets2.length - 1; i2 >= 0; i2--) {
@@ -5777,39 +5773,38 @@ const _AsyncStylesheetManager2 = class _AsyncStylesheetManager22 {
5777
5773
  break;
5778
5774
  }
5779
5775
  }
5780
- if (!clonedStyleSheet) {
5781
- console.log(
5782
- "AsyncStylesheetManager, onLoad: couldn't find stylesheet for href:",
5783
- href
5784
- );
5785
- return this.removeCloneNode(href);
5786
- }
5776
+ if (!clonedStyleSheet) return this.removeCloneNode(href);
5787
5777
  const newCssText = stringifyStylesheet(clonedStyleSheet);
5788
5778
  this.removeCloneNode(href);
5789
- if (!newCssText) {
5790
- console.log(
5791
- "AsyncStylesheetManager, onLoad: couldn't stringify stylesheet for href:",
5792
- href
5793
- );
5794
- return;
5795
- }
5796
- console.log(
5797
- "AsyncStylesheetManager, onLoad: success! did get new css text! forcing mutation... for href:",
5798
- href
5799
- );
5779
+ if (!newCssText) return;
5800
5780
  this.clones[href].cssText = newCssText;
5801
5781
  this.clones[href].loaded = true;
5802
5782
  const original = document.querySelector(
5803
- `link[data-rrweb-link-cloned="source-${this.clones[href].cloneNodeAttrId}"]`
5783
+ `link[${DATA_ATTRIBUTE_CLONED_NAME}="source-${this.clones[href].cloneNodeAttrId}"]`
5804
5784
  );
5805
- if (!original) {
5785
+ if (original) {
5786
+ original.setAttribute("data-rrweb-mutation", Date.now().toString());
5787
+ original.removeAttribute(DATA_ATTRIBUTE_CLONED_NAME);
5788
+ } else {
5806
5789
  this.clones[href].original.setAttribute(
5807
5790
  "data-rrweb-mutation",
5808
5791
  Date.now().toString()
5809
5792
  );
5810
- } else {
5811
- original.setAttribute("data-rrweb-mutation", Date.now().toString());
5793
+ this.clones[href].original.removeAttribute(DATA_ATTRIBUTE_CLONED_NAME);
5812
5794
  }
5795
+ window.dispatchEvent(
5796
+ new CustomEvent("__rrweb_custom_event__", {
5797
+ detail: {
5798
+ type: 5,
5799
+ timestamp: Date.now(),
5800
+ data: {
5801
+ tag: "async-css-resolution",
5802
+ requestCssId: this.clones[href].requestCssId,
5803
+ cssText: this.clones[href].cssText
5804
+ }
5805
+ }
5806
+ })
5807
+ );
5813
5808
  }
5814
5809
  onLoadError(href) {
5815
5810
  if (!(href in this.clones) || this.clones[href] === void 0) return;
@@ -5821,16 +5816,17 @@ const _AsyncStylesheetManager2 = class _AsyncStylesheetManager22 {
5821
5816
  }
5822
5817
  }
5823
5818
  onCleanTimeout() {
5824
- console.log("AsyncStylesheetManager, onCleanTimeout: cleaning up");
5825
5819
  asyncStylesheetManager.cleanTimeout = null;
5826
5820
  asyncStylesheetManager.removeAllCloneElements();
5827
5821
  }
5828
5822
  blowCache() {
5829
- console.log("AsyncStylesheetManager, blowCache: blowing cache");
5830
5823
  this.removeAllCloneElements();
5831
5824
  this.clones = {};
5832
5825
  }
5833
- registerClone({ forElement }) {
5826
+ requestClone({
5827
+ forElement,
5828
+ requestCssId
5829
+ }) {
5834
5830
  if (this.currentHref != null && document.location.href !== this.currentHref)
5835
5831
  this.blowCache();
5836
5832
  this.currentHref = document.location.href;
@@ -5848,16 +5844,12 @@ const _AsyncStylesheetManager2 = class _AsyncStylesheetManager22 {
5848
5844
  }
5849
5845
  }
5850
5846
  }
5851
- console.log(
5852
- "AsyncStylesheetManager, registerClone: registering clone for href:",
5853
- href
5854
- );
5855
5847
  const clone = forElement.cloneNode();
5856
5848
  const cloneNodeAttrId = Math.random().toString(36).slice(2);
5857
5849
  clone.setAttribute("crossorigin", "anonymous");
5858
- clone.setAttribute("data-rrweb-link-cloned", cloneNodeAttrId);
5850
+ clone.setAttribute(DATA_ATTRIBUTE_CLONED_NAME, cloneNodeAttrId);
5859
5851
  forElement.setAttribute(
5860
- "data-rrweb-link-cloned",
5852
+ DATA_ATTRIBUTE_CLONED_NAME,
5861
5853
  `source-${cloneNodeAttrId}`
5862
5854
  );
5863
5855
  document.head.appendChild(clone);
@@ -5866,7 +5858,8 @@ const _AsyncStylesheetManager2 = class _AsyncStylesheetManager22 {
5866
5858
  clone,
5867
5859
  loaded: false,
5868
5860
  cssText: null,
5869
- cloneNodeAttrId
5861
+ cloneNodeAttrId,
5862
+ requestCssId
5870
5863
  };
5871
5864
  clone.onload = () => {
5872
5865
  this.onLoad(href);
@@ -5882,10 +5875,6 @@ const _AsyncStylesheetManager2 = class _AsyncStylesheetManager22 {
5882
5875
  }
5883
5876
  getClonedCssTextIfAvailable(href) {
5884
5877
  if (href in this.clones && this.clones[href] !== void 0 && this.clones[href].loaded === true) {
5885
- console.log(
5886
- "AsyncStylesheetManager, getClonedCssTextIfAvailable: returning cloned cssText, for href:",
5887
- href
5888
- );
5889
5878
  return this.clones[href].cssText;
5890
5879
  }
5891
5880
  return null;