@appsurify-testmap/rrweb 3.2.0-alpha.1 → 3.3.0-alpha.1

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
@@ -15879,6 +15879,30 @@ function initNavigationObserver({
15879
15879
  handlers.push(restoreReplaceState);
15880
15880
  handlers.push(on("popstate", () => emitNavigation("popstate"), win));
15881
15881
  handlers.push(on("hashchange", () => emitNavigation("hashchange"), win));
15882
+ const useNavigationAPI = typeof sampling.navigation === "object" ? sampling.navigation.useNavigationAPI ?? true : true;
15883
+ if (useNavigationAPI && "navigation" in win) {
15884
+ try {
15885
+ const nav = win.navigation;
15886
+ const handler = (event) => {
15887
+ var _a2;
15888
+ const navEvent = event;
15889
+ if (navEvent.navigationType === "push" || navEvent.navigationType === "replace") {
15890
+ const destUrl = (_a2 = navEvent.destination) == null ? void 0 : _a2.url;
15891
+ if (destUrl && destUrl !== lastHref) {
15892
+ navigationCb({
15893
+ href: destUrl,
15894
+ oldHref: lastHref,
15895
+ navigationType: "navigate"
15896
+ });
15897
+ lastHref = destUrl;
15898
+ }
15899
+ }
15900
+ };
15901
+ nav.addEventListener("navigate", handler);
15902
+ handlers.push(() => nav.removeEventListener("navigate", handler));
15903
+ } catch {
15904
+ }
15905
+ }
15882
15906
  return callbackWrapper(() => {
15883
15907
  handlers.forEach((h) => h());
15884
15908
  });
@@ -17997,6 +18021,164 @@ class VisibilityManager {
17997
18021
  }
17998
18022
  }
17999
18023
  }
18024
+ const DEFAULT_SETTLE_TIMEOUT = 150;
18025
+ const DEFAULT_MAX_WAIT = 5e3;
18026
+ const DEFAULT_DEBOUNCE = 100;
18027
+ class NavigationManager {
18028
+ constructor(options) {
18029
+ __publicField(this, "frozen", false);
18030
+ __publicField(this, "locked", false);
18031
+ __publicField(this, "disabled", false);
18032
+ __publicField(this, "settleTimeout");
18033
+ __publicField(this, "maxWait");
18034
+ __publicField(this, "debounceMs");
18035
+ __publicField(this, "settlingObserver", null);
18036
+ __publicField(this, "debounceTimer", null);
18037
+ __publicField(this, "settleCheckTimer", null);
18038
+ __publicField(this, "maxWaitTimer", null);
18039
+ __publicField(this, "lastMutationTime", 0);
18040
+ __publicField(this, "pendingNavigation", null);
18041
+ __publicField(this, "doc");
18042
+ __publicField(this, "onSnapshot");
18043
+ const { doc, config, onSnapshot } = options;
18044
+ this.doc = doc;
18045
+ this.onSnapshot = callbackWrapper(onSnapshot);
18046
+ this.settleTimeout = config.settleTimeout ?? DEFAULT_SETTLE_TIMEOUT;
18047
+ this.maxWait = config.maxWait ?? DEFAULT_MAX_WAIT;
18048
+ this.debounceMs = config.debounce ?? DEFAULT_DEBOUNCE;
18049
+ }
18050
+ handleNavigation(data) {
18051
+ if (this.disabled) return;
18052
+ if (this.locked) return;
18053
+ this.cancelTimers();
18054
+ this.disconnectSettlingObserver();
18055
+ this.pendingNavigation = data;
18056
+ if (this.frozen) {
18057
+ return;
18058
+ }
18059
+ this.startDebounce();
18060
+ }
18061
+ cancelPending() {
18062
+ this.cancelTimers();
18063
+ this.disconnectSettlingObserver();
18064
+ this.pendingNavigation = null;
18065
+ }
18066
+ freeze() {
18067
+ this.frozen = true;
18068
+ this.cancelTimers();
18069
+ this.disconnectSettlingObserver();
18070
+ }
18071
+ unfreeze() {
18072
+ this.frozen = false;
18073
+ if (this.pendingNavigation && !this.locked && !this.disabled) {
18074
+ this.startDebounce();
18075
+ }
18076
+ }
18077
+ lock() {
18078
+ this.locked = true;
18079
+ this.cancelTimers();
18080
+ this.disconnectSettlingObserver();
18081
+ }
18082
+ unlock() {
18083
+ this.locked = false;
18084
+ this.pendingNavigation = null;
18085
+ }
18086
+ unsetFrozen() {
18087
+ this.frozen = false;
18088
+ }
18089
+ reset() {
18090
+ this.cancelTimers();
18091
+ this.disconnectSettlingObserver();
18092
+ this.pendingNavigation = null;
18093
+ this.frozen = false;
18094
+ this.locked = false;
18095
+ }
18096
+ destroy() {
18097
+ this.reset();
18098
+ this.disabled = true;
18099
+ }
18100
+ startDebounce() {
18101
+ this.debounceTimer = setTimeout(() => {
18102
+ this.debounceTimer = null;
18103
+ this.startDOMSettling();
18104
+ }, this.debounceMs);
18105
+ }
18106
+ startDOMSettling() {
18107
+ if (this.frozen || this.locked || this.disabled) return;
18108
+ this.lastMutationTime = performance.now();
18109
+ const ObserverCtor = mutationObserverCtor();
18110
+ this.settlingObserver = new ObserverCtor(() => {
18111
+ this.lastMutationTime = performance.now();
18112
+ if (this.settleCheckTimer !== null) {
18113
+ clearTimeout(this.settleCheckTimer);
18114
+ }
18115
+ this.settleCheckTimer = setTimeout(
18116
+ () => this.checkSettled(),
18117
+ this.settleTimeout
18118
+ );
18119
+ });
18120
+ this.settlingObserver.observe(this.doc, {
18121
+ childList: true,
18122
+ subtree: true,
18123
+ attributes: true,
18124
+ characterData: true
18125
+ });
18126
+ this.settleCheckTimer = setTimeout(
18127
+ () => this.checkSettled(),
18128
+ this.settleTimeout
18129
+ );
18130
+ this.maxWaitTimer = setTimeout(() => {
18131
+ this.maxWaitTimer = null;
18132
+ this.completeSettling();
18133
+ }, this.maxWait);
18134
+ }
18135
+ checkSettled() {
18136
+ this.settleCheckTimer = null;
18137
+ const elapsed = performance.now() - this.lastMutationTime;
18138
+ if (elapsed >= this.settleTimeout) {
18139
+ this.completeSettling();
18140
+ } else {
18141
+ this.settleCheckTimer = setTimeout(
18142
+ () => this.checkSettled(),
18143
+ this.settleTimeout - elapsed
18144
+ );
18145
+ }
18146
+ }
18147
+ completeSettling() {
18148
+ if (this.frozen || this.locked || this.disabled) return;
18149
+ if (!this.pendingNavigation) return;
18150
+ this.cancelTimers();
18151
+ this.disconnectSettlingObserver();
18152
+ this.pendingNavigation = null;
18153
+ requestAnimationFrame(() => {
18154
+ requestAnimationFrame(() => {
18155
+ if (!this.frozen && !this.locked && !this.disabled) {
18156
+ this.onSnapshot(true);
18157
+ }
18158
+ });
18159
+ });
18160
+ }
18161
+ cancelTimers() {
18162
+ if (this.debounceTimer !== null) {
18163
+ clearTimeout(this.debounceTimer);
18164
+ this.debounceTimer = null;
18165
+ }
18166
+ if (this.settleCheckTimer !== null) {
18167
+ clearTimeout(this.settleCheckTimer);
18168
+ this.settleCheckTimer = null;
18169
+ }
18170
+ if (this.maxWaitTimer !== null) {
18171
+ clearTimeout(this.maxWaitTimer);
18172
+ this.maxWaitTimer = null;
18173
+ }
18174
+ }
18175
+ disconnectSettlingObserver() {
18176
+ if (this.settlingObserver) {
18177
+ this.settlingObserver.disconnect();
18178
+ this.settlingObserver = null;
18179
+ }
18180
+ }
18181
+ }
18000
18182
  class StylesheetManager {
18001
18183
  constructor(options) {
18002
18184
  __publicField(this, "trackedLinkElements", /* @__PURE__ */ new WeakSet());
@@ -18080,43 +18262,13 @@ class ProcessedNodeManager {
18080
18262
  destroy() {
18081
18263
  }
18082
18264
  }
18083
- const version$1 = "3.2.0-alpha.1";
18265
+ const version$1 = "3.3.0-alpha.1";
18084
18266
  let wrappedEmit;
18085
18267
  let takeFullSnapshot$1;
18086
18268
  let canvasManager;
18087
18269
  let recording = false;
18088
18270
  const customEventQueue = [];
18089
18271
  let flushCustomEventQueue$1;
18090
- function waitForDOMStabilization(win) {
18091
- const maxWaitMs = 5e3;
18092
- return new Promise((resolve2) => {
18093
- const captureAfterPaint = () => {
18094
- requestAnimationFrame(() => {
18095
- requestAnimationFrame(() => {
18096
- resolve2();
18097
- });
18098
- });
18099
- };
18100
- const safeResolve = /* @__PURE__ */ (() => {
18101
- let called = false;
18102
- return () => {
18103
- if (!called) {
18104
- called = true;
18105
- captureAfterPaint();
18106
- }
18107
- };
18108
- })();
18109
- if (["interactive", "complete"].includes(win.document.readyState)) {
18110
- safeResolve();
18111
- } else {
18112
- win.addEventListener("DOMContentLoaded", safeResolve, { once: true });
18113
- win.addEventListener("load", safeResolve, { once: true });
18114
- setTimeout(() => {
18115
- safeResolve();
18116
- }, maxWaitMs);
18117
- }
18118
- });
18119
- }
18120
18272
  try {
18121
18273
  if (Array.from([1], (x2) => x2 * 2)[0] !== 2) {
18122
18274
  const cleanFrame = document.createElement("iframe");
@@ -18249,6 +18401,7 @@ function record(options = {}) {
18249
18401
  checkoutDebounceTimer = null;
18250
18402
  checkoutPending = false;
18251
18403
  checkoutFreezeTimestamp = null;
18404
+ navigationManager == null ? void 0 : navigationManager.cancelPending();
18252
18405
  takeFullSnapshot$1(true);
18253
18406
  mutationBuffers.forEach((buf) => {
18254
18407
  buf.resetBuffers();
@@ -18257,6 +18410,9 @@ function record(options = {}) {
18257
18410
  if (visibilityManager) {
18258
18411
  visibilityManager.unsetFrozen();
18259
18412
  }
18413
+ if (navigationManager) {
18414
+ navigationManager.unsetFrozen();
18415
+ }
18260
18416
  };
18261
18417
  wrappedEmit = (r2, isCheckout) => {
18262
18418
  var _a2;
@@ -18266,6 +18422,7 @@ function record(options = {}) {
18266
18422
  if (((_a2 = mutationBuffers[0]) == null ? void 0 : _a2.isFrozen()) && !checkoutPending && e2.type !== EventType.FullSnapshot && !(e2.type === EventType.IncrementalSnapshot && e2.data.source === IncrementalSource.Mutation)) {
18267
18423
  mutationBuffers.forEach((buf) => buf.unfreeze());
18268
18424
  visibilityManager == null ? void 0 : visibilityManager.unfreeze();
18425
+ navigationManager == null ? void 0 : navigationManager.unfreeze();
18269
18426
  }
18270
18427
  if (inEmittingFrame) {
18271
18428
  emit == null ? void 0 : emit(eventProcessor(e2), isCheckout);
@@ -18475,6 +18632,7 @@ function record(options = {}) {
18475
18632
  shadowDomManager.init();
18476
18633
  mutationBuffers.forEach((buf) => buf.lock());
18477
18634
  visibilityManager == null ? void 0 : visibilityManager.lock();
18635
+ navigationManager == null ? void 0 : navigationManager.lock();
18478
18636
  const node2 = snapshot(document, {
18479
18637
  mirror,
18480
18638
  blockClass,
@@ -18526,6 +18684,7 @@ function record(options = {}) {
18526
18684
  );
18527
18685
  mutationBuffers.forEach((buf) => buf.unlock());
18528
18686
  visibilityManager == null ? void 0 : visibilityManager.unlock();
18687
+ navigationManager == null ? void 0 : navigationManager.unlock();
18529
18688
  if (document.adoptedStyleSheets && document.adoptedStyleSheets.length > 0)
18530
18689
  stylesheetManager.adoptStyleSheets(
18531
18690
  document.adoptedStyleSheets,
@@ -18538,6 +18697,31 @@ function record(options = {}) {
18538
18697
  }
18539
18698
  customEventQueue.length = 0;
18540
18699
  };
18700
+ let navigationManager;
18701
+ const navigationSampling = sampling.navigation;
18702
+ if (navigationSampling !== false) {
18703
+ const navConfig = typeof navigationSampling === "object" ? navigationSampling : {};
18704
+ navigationManager = new NavigationManager({
18705
+ doc: document,
18706
+ config: navConfig,
18707
+ onSnapshot: (isCheckout) => {
18708
+ if (checkoutPending) {
18709
+ if (checkoutDebounceTimer) {
18710
+ clearTimeout(checkoutDebounceTimer);
18711
+ checkoutDebounceTimer = null;
18712
+ }
18713
+ checkoutPending = false;
18714
+ checkoutFreezeTimestamp = null;
18715
+ mutationBuffers.forEach((buf) => {
18716
+ buf.resetBuffers();
18717
+ buf.unsetFrozen();
18718
+ });
18719
+ visibilityManager == null ? void 0 : visibilityManager.unsetFrozen();
18720
+ }
18721
+ takeFullSnapshot$1(isCheckout);
18722
+ }
18723
+ });
18724
+ }
18541
18725
  try {
18542
18726
  const handlers = [];
18543
18727
  const observe = (doc) => {
@@ -18568,14 +18752,11 @@ function record(options = {}) {
18568
18752
  }
18569
18753
  }),
18570
18754
  navigationCb: (navData) => {
18571
- console.debug(
18572
- `[${nowTimestamp()}] [rrweb:record/navigation] 🧭 Navigation detected:`,
18573
- navData.navigationType,
18574
- navData.oldHref,
18575
- "→",
18576
- navData.href
18577
- );
18578
- takeFullSnapshot$1(true);
18755
+ if (navigationManager) {
18756
+ navigationManager.handleNavigation(navData);
18757
+ } else {
18758
+ takeFullSnapshot$1(true);
18759
+ }
18579
18760
  },
18580
18761
  inputCb: (v2) => wrappedEmit({
18581
18762
  type: EventType.IncrementalSnapshot,
@@ -18694,23 +18875,6 @@ function record(options = {}) {
18694
18875
  flushCustomEventQueue$1();
18695
18876
  }
18696
18877
  };
18697
- const runInit = async () => {
18698
- if (flushCustomEvent === "before") {
18699
- flushCustomEventQueue$1();
18700
- }
18701
- if (recordAfter === "DOMContentStabilized") {
18702
- console.debug(`[${nowTimestamp()}] [rrweb:record] 🟢 Waiting for DOM stabilization...`);
18703
- await waitForDOMStabilization(window);
18704
- console.debug(`[${nowTimestamp()}] [rrweb:record] ✅ DOM stabilized, starting recording`);
18705
- }
18706
- console.debug(`[${nowTimestamp()}] [rrweb:record] ✅ Init dom and takeFullSnapshot `);
18707
- takeFullSnapshot$1();
18708
- handlers.push(observe(document));
18709
- recording = true;
18710
- if (flushCustomEvent === "after") {
18711
- flushCustomEventQueue$1();
18712
- }
18713
- };
18714
18878
  if (document.readyState === "interactive" || document.readyState === "complete") {
18715
18879
  init();
18716
18880
  } else {
@@ -18744,6 +18908,7 @@ function record(options = {}) {
18744
18908
  }
18745
18909
  flushCustomEventQueue$1();
18746
18910
  handlers.forEach((h) => h());
18911
+ navigationManager == null ? void 0 : navigationManager.destroy();
18747
18912
  processedNodeManager.destroy();
18748
18913
  recording = false;
18749
18914
  unregisterErrorHandler();
@@ -21676,7 +21841,7 @@ class Replayer {
21676
21841
  this.config.logger.log(REPLAY_CONSOLE_PREFIX, ...args);
21677
21842
  }
21678
21843
  }
21679
- const version = "3.2.0-alpha.1";
21844
+ const version = "3.3.0-alpha.1";
21680
21845
  const { getVersion } = record;
21681
21846
  const { isRecording } = record;
21682
21847
  const { flushCustomEventQueue } = record;