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