@glimt/record 0.0.44 → 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.
@@ -845,7 +845,8 @@ 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 * 2;
848
+ const CLEANUP_DEBOUNCE_TIME$1 = 1e3 * 30;
849
+ const DATA_ATTRIBUTE_CLONED_NAME$1 = "data-rrweb-link-cloned";
849
850
  const DISALLOWED_EXTENSIONS$1 = [
850
851
  // Fonts
851
852
  "woff",
@@ -902,14 +903,13 @@ const _AsyncStylesheetManager$1 = class _AsyncStylesheetManager {
902
903
  var _a2;
903
904
  if (!(href in this.clones) || this.clones[href] === void 0) return;
904
905
  const clone = document.querySelector(
905
- `link[data-rrweb-link-cloned="${this.clones[href].cloneNodeAttrId}"]`
906
+ `link[${DATA_ATTRIBUTE_CLONED_NAME$1}="${this.clones[href].cloneNodeAttrId}"]`
906
907
  );
907
908
  if (!clone) return;
908
909
  (_a2 = clone.parentNode) == null ? void 0 : _a2.removeChild(clone);
909
910
  }
910
911
  onLoad(href) {
911
912
  if (!(href in this.clones) || this.clones[href] === void 0) return;
912
- console.log("AsyncStylesheetManager, onLoad: href:", href);
913
913
  const styleSheets2 = Array.from(document.styleSheets);
914
914
  let clonedStyleSheet = null;
915
915
  for (let i2 = styleSheets2.length - 1; i2 >= 0; i2--) {
@@ -918,39 +918,38 @@ const _AsyncStylesheetManager$1 = class _AsyncStylesheetManager {
918
918
  break;
919
919
  }
920
920
  }
921
- if (!clonedStyleSheet) {
922
- console.log(
923
- "AsyncStylesheetManager, onLoad: couldn't find stylesheet for href:",
924
- href
925
- );
926
- return this.removeCloneNode(href);
927
- }
921
+ if (!clonedStyleSheet) return this.removeCloneNode(href);
928
922
  const newCssText = stringifyStylesheet$1(clonedStyleSheet);
929
923
  this.removeCloneNode(href);
930
- if (!newCssText) {
931
- console.log(
932
- "AsyncStylesheetManager, onLoad: couldn't stringify stylesheet for href:",
933
- href
934
- );
935
- return;
936
- }
937
- console.log(
938
- "AsyncStylesheetManager, onLoad: success! did get new css text! forcing mutation... for href:",
939
- href
940
- );
924
+ if (!newCssText) return;
941
925
  this.clones[href].cssText = newCssText;
942
926
  this.clones[href].loaded = true;
943
927
  const original = document.querySelector(
944
- `link[data-rrweb-link-cloned="source-${this.clones[href].cloneNodeAttrId}"]`
928
+ `link[${DATA_ATTRIBUTE_CLONED_NAME$1}="source-${this.clones[href].cloneNodeAttrId}"]`
945
929
  );
946
- if (!original) {
930
+ if (original) {
931
+ original.setAttribute("data-rrweb-mutation", Date.now().toString());
932
+ original.removeAttribute(DATA_ATTRIBUTE_CLONED_NAME$1);
933
+ } else {
947
934
  this.clones[href].original.setAttribute(
948
935
  "data-rrweb-mutation",
949
936
  Date.now().toString()
950
937
  );
951
- } else {
952
- original.setAttribute("data-rrweb-mutation", Date.now().toString());
938
+ this.clones[href].original.removeAttribute(DATA_ATTRIBUTE_CLONED_NAME$1);
953
939
  }
940
+ window.dispatchEvent(
941
+ new CustomEvent("__rrweb_custom_event__", {
942
+ detail: {
943
+ type: 5,
944
+ timestamp: Date.now(),
945
+ data: {
946
+ tag: "async-css-resolution",
947
+ requestCssId: this.clones[href].requestCssId,
948
+ cssText: this.clones[href].cssText
949
+ }
950
+ }
951
+ })
952
+ );
954
953
  }
955
954
  onLoadError(href) {
956
955
  if (!(href in this.clones) || this.clones[href] === void 0) return;
@@ -962,16 +961,17 @@ const _AsyncStylesheetManager$1 = class _AsyncStylesheetManager {
962
961
  }
963
962
  }
964
963
  onCleanTimeout() {
965
- console.log("AsyncStylesheetManager, onCleanTimeout: cleaning up");
966
- this.cleanTimeout = null;
967
- this.removeAllCloneElements();
964
+ asyncStylesheetManager$1.cleanTimeout = null;
965
+ asyncStylesheetManager$1.removeAllCloneElements();
968
966
  }
969
967
  blowCache() {
970
- console.log("AsyncStylesheetManager, blowCache: blowing cache");
971
- this.clones = {};
972
968
  this.removeAllCloneElements();
969
+ this.clones = {};
973
970
  }
974
- registerClone({ forElement }) {
971
+ requestClone({
972
+ forElement,
973
+ requestCssId
974
+ }) {
975
975
  if (this.currentHref != null && document.location.href !== this.currentHref)
976
976
  this.blowCache();
977
977
  this.currentHref = document.location.href;
@@ -985,20 +985,16 @@ const _AsyncStylesheetManager$1 = class _AsyncStylesheetManager {
985
985
  const [filename] = last.split("?");
986
986
  const ext = filename.split(".").pop();
987
987
  if (ext) {
988
- if (DISALLOWED_EXTENSIONS$1.includes(ext.toLowerCase())) return;
988
+ if (DISALLOWED_EXTENSIONS$1.includes(ext.trim().toLowerCase())) return;
989
989
  }
990
990
  }
991
991
  }
992
- console.log(
993
- "AsyncStylesheetManager, registerClone: registering clone for href:",
994
- href
995
- );
996
992
  const clone = forElement.cloneNode();
997
993
  const cloneNodeAttrId = Math.random().toString(36).slice(2);
998
994
  clone.setAttribute("crossorigin", "anonymous");
999
- clone.setAttribute("data-rrweb-link-cloned", cloneNodeAttrId);
995
+ clone.setAttribute(DATA_ATTRIBUTE_CLONED_NAME$1, cloneNodeAttrId);
1000
996
  forElement.setAttribute(
1001
- "data-rrweb-link-cloned",
997
+ DATA_ATTRIBUTE_CLONED_NAME$1,
1002
998
  `source-${cloneNodeAttrId}`
1003
999
  );
1004
1000
  document.head.appendChild(clone);
@@ -1007,7 +1003,8 @@ const _AsyncStylesheetManager$1 = class _AsyncStylesheetManager {
1007
1003
  clone,
1008
1004
  loaded: false,
1009
1005
  cssText: null,
1010
- cloneNodeAttrId
1006
+ cloneNodeAttrId,
1007
+ requestCssId
1011
1008
  };
1012
1009
  clone.onload = () => {
1013
1010
  this.onLoad(href);
@@ -1023,10 +1020,6 @@ const _AsyncStylesheetManager$1 = class _AsyncStylesheetManager {
1023
1020
  }
1024
1021
  getClonedCssTextIfAvailable(href) {
1025
1022
  if (href in this.clones && this.clones[href] !== void 0 && this.clones[href].loaded === true) {
1026
- console.log(
1027
- "AsyncStylesheetManager, getClonedCssTextIfAvailable: returning cloned cssText, for href:",
1028
- href
1029
- );
1030
1023
  return this.clones[href].cssText;
1031
1024
  }
1032
1025
  return null;
@@ -1448,9 +1441,12 @@ function serializeElementNode(n2, options) {
1448
1441
  delete attributes.href;
1449
1442
  attributes._cssText = cssText;
1450
1443
  } else {
1451
- asyncStylesheetManager$1.registerClone({
1452
- forElement: n2
1444
+ const requestCssId = `css-request-${Math.random().toString(36).slice(2)}`;
1445
+ asyncStylesheetManager$1.requestClone({
1446
+ forElement: n2,
1447
+ requestCssId
1453
1448
  });
1449
+ attributes._requestCssId = requestCssId;
1454
1450
  }
1455
1451
  }
1456
1452
  if (tagName === "style" && n2.sheet) {
@@ -5741,7 +5737,8 @@ function absolutifyURLs(cssText, href) {
5741
5737
  }
5742
5738
  );
5743
5739
  }
5744
- const CLEANUP_DEBOUNCE_TIME = 1e3 * 60 * 2;
5740
+ const CLEANUP_DEBOUNCE_TIME = 1e3 * 30;
5741
+ const DATA_ATTRIBUTE_CLONED_NAME = "data-rrweb-link-cloned";
5745
5742
  const DISALLOWED_EXTENSIONS = [
5746
5743
  // Fonts
5747
5744
  "woff",
@@ -5798,14 +5795,13 @@ const _AsyncStylesheetManager2 = class _AsyncStylesheetManager22 {
5798
5795
  var _a2;
5799
5796
  if (!(href in this.clones) || this.clones[href] === void 0) return;
5800
5797
  const clone = document.querySelector(
5801
- `link[data-rrweb-link-cloned="${this.clones[href].cloneNodeAttrId}"]`
5798
+ `link[${DATA_ATTRIBUTE_CLONED_NAME}="${this.clones[href].cloneNodeAttrId}"]`
5802
5799
  );
5803
5800
  if (!clone) return;
5804
5801
  (_a2 = clone.parentNode) == null ? void 0 : _a2.removeChild(clone);
5805
5802
  }
5806
5803
  onLoad(href) {
5807
5804
  if (!(href in this.clones) || this.clones[href] === void 0) return;
5808
- console.log("AsyncStylesheetManager, onLoad: href:", href);
5809
5805
  const styleSheets2 = Array.from(document.styleSheets);
5810
5806
  let clonedStyleSheet = null;
5811
5807
  for (let i2 = styleSheets2.length - 1; i2 >= 0; i2--) {
@@ -5814,39 +5810,38 @@ const _AsyncStylesheetManager2 = class _AsyncStylesheetManager22 {
5814
5810
  break;
5815
5811
  }
5816
5812
  }
5817
- if (!clonedStyleSheet) {
5818
- console.log(
5819
- "AsyncStylesheetManager, onLoad: couldn't find stylesheet for href:",
5820
- href
5821
- );
5822
- return this.removeCloneNode(href);
5823
- }
5813
+ if (!clonedStyleSheet) return this.removeCloneNode(href);
5824
5814
  const newCssText = stringifyStylesheet(clonedStyleSheet);
5825
5815
  this.removeCloneNode(href);
5826
- if (!newCssText) {
5827
- console.log(
5828
- "AsyncStylesheetManager, onLoad: couldn't stringify stylesheet for href:",
5829
- href
5830
- );
5831
- return;
5832
- }
5833
- console.log(
5834
- "AsyncStylesheetManager, onLoad: success! did get new css text! forcing mutation... for href:",
5835
- href
5836
- );
5816
+ if (!newCssText) return;
5837
5817
  this.clones[href].cssText = newCssText;
5838
5818
  this.clones[href].loaded = true;
5839
5819
  const original = document.querySelector(
5840
- `link[data-rrweb-link-cloned="source-${this.clones[href].cloneNodeAttrId}"]`
5820
+ `link[${DATA_ATTRIBUTE_CLONED_NAME}="source-${this.clones[href].cloneNodeAttrId}"]`
5841
5821
  );
5842
- if (!original) {
5822
+ if (original) {
5823
+ original.setAttribute("data-rrweb-mutation", Date.now().toString());
5824
+ original.removeAttribute(DATA_ATTRIBUTE_CLONED_NAME);
5825
+ } else {
5843
5826
  this.clones[href].original.setAttribute(
5844
5827
  "data-rrweb-mutation",
5845
5828
  Date.now().toString()
5846
5829
  );
5847
- } else {
5848
- original.setAttribute("data-rrweb-mutation", Date.now().toString());
5830
+ this.clones[href].original.removeAttribute(DATA_ATTRIBUTE_CLONED_NAME);
5849
5831
  }
5832
+ window.dispatchEvent(
5833
+ new CustomEvent("__rrweb_custom_event__", {
5834
+ detail: {
5835
+ type: 5,
5836
+ timestamp: Date.now(),
5837
+ data: {
5838
+ tag: "async-css-resolution",
5839
+ requestCssId: this.clones[href].requestCssId,
5840
+ cssText: this.clones[href].cssText
5841
+ }
5842
+ }
5843
+ })
5844
+ );
5850
5845
  }
5851
5846
  onLoadError(href) {
5852
5847
  if (!(href in this.clones) || this.clones[href] === void 0) return;
@@ -5858,16 +5853,17 @@ const _AsyncStylesheetManager2 = class _AsyncStylesheetManager22 {
5858
5853
  }
5859
5854
  }
5860
5855
  onCleanTimeout() {
5861
- console.log("AsyncStylesheetManager, onCleanTimeout: cleaning up");
5862
- this.cleanTimeout = null;
5863
- this.removeAllCloneElements();
5856
+ asyncStylesheetManager.cleanTimeout = null;
5857
+ asyncStylesheetManager.removeAllCloneElements();
5864
5858
  }
5865
5859
  blowCache() {
5866
- console.log("AsyncStylesheetManager, blowCache: blowing cache");
5867
- this.clones = {};
5868
5860
  this.removeAllCloneElements();
5861
+ this.clones = {};
5869
5862
  }
5870
- registerClone({ forElement }) {
5863
+ requestClone({
5864
+ forElement,
5865
+ requestCssId
5866
+ }) {
5871
5867
  if (this.currentHref != null && document.location.href !== this.currentHref)
5872
5868
  this.blowCache();
5873
5869
  this.currentHref = document.location.href;
@@ -5881,20 +5877,16 @@ const _AsyncStylesheetManager2 = class _AsyncStylesheetManager22 {
5881
5877
  const [filename] = last.split("?");
5882
5878
  const ext = filename.split(".").pop();
5883
5879
  if (ext) {
5884
- if (DISALLOWED_EXTENSIONS.includes(ext.toLowerCase())) return;
5880
+ if (DISALLOWED_EXTENSIONS.includes(ext.trim().toLowerCase())) return;
5885
5881
  }
5886
5882
  }
5887
5883
  }
5888
- console.log(
5889
- "AsyncStylesheetManager, registerClone: registering clone for href:",
5890
- href
5891
- );
5892
5884
  const clone = forElement.cloneNode();
5893
5885
  const cloneNodeAttrId = Math.random().toString(36).slice(2);
5894
5886
  clone.setAttribute("crossorigin", "anonymous");
5895
- clone.setAttribute("data-rrweb-link-cloned", cloneNodeAttrId);
5887
+ clone.setAttribute(DATA_ATTRIBUTE_CLONED_NAME, cloneNodeAttrId);
5896
5888
  forElement.setAttribute(
5897
- "data-rrweb-link-cloned",
5889
+ DATA_ATTRIBUTE_CLONED_NAME,
5898
5890
  `source-${cloneNodeAttrId}`
5899
5891
  );
5900
5892
  document.head.appendChild(clone);
@@ -5903,7 +5895,8 @@ const _AsyncStylesheetManager2 = class _AsyncStylesheetManager22 {
5903
5895
  clone,
5904
5896
  loaded: false,
5905
5897
  cssText: null,
5906
- cloneNodeAttrId
5898
+ cloneNodeAttrId,
5899
+ requestCssId
5907
5900
  };
5908
5901
  clone.onload = () => {
5909
5902
  this.onLoad(href);
@@ -5919,10 +5912,6 @@ const _AsyncStylesheetManager2 = class _AsyncStylesheetManager22 {
5919
5912
  }
5920
5913
  getClonedCssTextIfAvailable(href) {
5921
5914
  if (href in this.clones && this.clones[href] !== void 0 && this.clones[href].loaded === true) {
5922
- console.log(
5923
- "AsyncStylesheetManager, getClonedCssTextIfAvailable: returning cloned cssText, for href:",
5924
- href
5925
- );
5926
5915
  return this.clones[href].cssText;
5927
5916
  }
5928
5917
  return null;