@appsurify-testmap/rrweb 2.1.1-alpha.5 → 2.1.1-alpha.7

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/rrweb.cjs CHANGED
@@ -14444,6 +14444,36 @@ let visibilityManager;
14444
14444
  let recording = false;
14445
14445
  const customEventQueue = [];
14446
14446
  let flushCustomEventQueue;
14447
+ function waitForDOMStabilization(win) {
14448
+ const maxWaitMs = 5e3;
14449
+ return new Promise((resolve2) => {
14450
+ const captureAfterPaint = () => {
14451
+ requestAnimationFrame(() => {
14452
+ requestAnimationFrame(() => {
14453
+ resolve2();
14454
+ });
14455
+ });
14456
+ };
14457
+ const safeResolve = /* @__PURE__ */ (() => {
14458
+ let called = false;
14459
+ return () => {
14460
+ if (!called) {
14461
+ called = true;
14462
+ captureAfterPaint();
14463
+ }
14464
+ };
14465
+ })();
14466
+ if (["interactive", "complete"].includes(win.document.readyState)) {
14467
+ safeResolve();
14468
+ } else {
14469
+ win.addEventListener("DOMContentLoaded", safeResolve, { once: true });
14470
+ win.addEventListener("load", safeResolve, { once: true });
14471
+ setTimeout(() => {
14472
+ safeResolve();
14473
+ }, maxWaitMs);
14474
+ }
14475
+ });
14476
+ }
14447
14477
  try {
14448
14478
  if (Array.from([1], (x2) => x2 * 2)[0] !== 2) {
14449
14479
  const cleanFrame = document.createElement("iframe");
@@ -14935,8 +14965,28 @@ function record(options = {}) {
14935
14965
  flushCustomEventQueue();
14936
14966
  }
14937
14967
  };
14968
+ const runInit = async () => {
14969
+ if (flushCustomEvent === "before") {
14970
+ flushCustomEventQueue();
14971
+ }
14972
+ if (recordAfter === "DOMContentStabilized") {
14973
+ console.log(`[rrweb] 🟢 Waiting for DOM stabilization...`);
14974
+ await waitForDOMStabilization(window);
14975
+ console.log(`[rrweb] ✅ DOM stabilized, starting recording`);
14976
+ }
14977
+ takeFullSnapshot$1();
14978
+ handlers.push(observe(document));
14979
+ recording = true;
14980
+ if (flushCustomEvent === "after") {
14981
+ flushCustomEventQueue();
14982
+ }
14983
+ };
14938
14984
  if (document.readyState === "interactive" || document.readyState === "complete") {
14939
- init();
14985
+ if (recordAfter === "DOMContentStabilized") {
14986
+ void runInit();
14987
+ } else {
14988
+ init();
14989
+ }
14940
14990
  } else {
14941
14991
  handlers.push(
14942
14992
  on("DOMContentLoaded", () => {
@@ -14944,7 +14994,9 @@ function record(options = {}) {
14944
14994
  type: EventType.DomContentLoaded,
14945
14995
  data: {}
14946
14996
  });
14947
- if (recordAfter === "DOMContentLoaded") init();
14997
+ if (recordAfter === "DOMContentLoaded" || recordAfter === "DOMContentStabilized") {
14998
+ void runInit();
14999
+ }
14948
15000
  })
14949
15001
  );
14950
15002
  handlers.push(
@@ -14955,7 +15007,7 @@ function record(options = {}) {
14955
15007
  type: EventType.Load,
14956
15008
  data: {}
14957
15009
  });
14958
- if (recordAfter === "load") init();
15010
+ if (recordAfter === "load") void runInit();
14959
15011
  },
14960
15012
  window
14961
15013
  )
@@ -14972,6 +15024,7 @@ function record(options = {}) {
14972
15024
  console.warn(error);
14973
15025
  }
14974
15026
  }
15027
+ record.isRecording = () => recording;
14975
15028
  record.flushCustomEventQueue = () => {
14976
15029
  console.warn(`[rrweb] CustomEvent flushing: ${customEventQueue.length} events`);
14977
15030
  flushCustomEventQueue();