@glimt/record 0.0.45 → 0.0.47

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