@appsurify-testmap/rrweb-all 3.2.0-alpha.1 → 3.4.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-all.js CHANGED
@@ -15857,6 +15857,30 @@ function initNavigationObserver({
15857
15857
  handlers.push(restoreReplaceState);
15858
15858
  handlers.push(on("popstate", () => emitNavigation("popstate"), win));
15859
15859
  handlers.push(on("hashchange", () => emitNavigation("hashchange"), win));
15860
+ const useNavigationAPI = typeof sampling.navigation === "object" ? sampling.navigation.useNavigationAPI ?? true : true;
15861
+ if (useNavigationAPI && "navigation" in win) {
15862
+ try {
15863
+ const nav = win.navigation;
15864
+ const handler = (event) => {
15865
+ var _a2;
15866
+ const navEvent = event;
15867
+ if (navEvent.navigationType === "push" || navEvent.navigationType === "replace") {
15868
+ const destUrl = (_a2 = navEvent.destination) == null ? void 0 : _a2.url;
15869
+ if (destUrl && destUrl !== lastHref) {
15870
+ navigationCb({
15871
+ href: destUrl,
15872
+ oldHref: lastHref,
15873
+ navigationType: "navigate"
15874
+ });
15875
+ lastHref = destUrl;
15876
+ }
15877
+ }
15878
+ };
15879
+ nav.addEventListener("navigate", handler);
15880
+ handlers.push(() => nav.removeEventListener("navigate", handler));
15881
+ } catch {
15882
+ }
15883
+ }
15860
15884
  return callbackWrapper(() => {
15861
15885
  handlers.forEach((h) => h());
15862
15886
  });
@@ -17975,6 +17999,162 @@ class VisibilityManager {
17975
17999
  }
17976
18000
  }
17977
18001
  }
18002
+ const DEFAULT_SETTLE_TIMEOUT = 150;
18003
+ const DEFAULT_MAX_WAIT = 5e3;
18004
+ const DEFAULT_DEBOUNCE = 100;
18005
+ class NavigationManager {
18006
+ constructor(options) {
18007
+ __publicField(this, "frozen", false);
18008
+ __publicField(this, "locked", false);
18009
+ __publicField(this, "disabled", false);
18010
+ __publicField(this, "settleTimeout");
18011
+ __publicField(this, "maxWait");
18012
+ __publicField(this, "debounceMs");
18013
+ __publicField(this, "settlingObserver", null);
18014
+ __publicField(this, "debounceTimer", null);
18015
+ __publicField(this, "settleCheckTimer", null);
18016
+ __publicField(this, "maxWaitTimer", null);
18017
+ __publicField(this, "lastMutationTime", 0);
18018
+ __publicField(this, "pendingNavigation", null);
18019
+ __publicField(this, "doc");
18020
+ __publicField(this, "onSnapshot");
18021
+ const { doc, config, onSnapshot } = options;
18022
+ this.doc = doc;
18023
+ this.onSnapshot = callbackWrapper(onSnapshot);
18024
+ this.settleTimeout = config.settleTimeout ?? DEFAULT_SETTLE_TIMEOUT;
18025
+ this.maxWait = config.maxWait ?? DEFAULT_MAX_WAIT;
18026
+ this.debounceMs = config.debounce ?? DEFAULT_DEBOUNCE;
18027
+ }
18028
+ handleNavigation(data) {
18029
+ if (this.disabled) return;
18030
+ if (this.locked) return;
18031
+ this.cancelTimers();
18032
+ this.disconnectSettlingObserver();
18033
+ this.pendingNavigation = data;
18034
+ if (this.frozen) {
18035
+ return;
18036
+ }
18037
+ this.startDebounce();
18038
+ }
18039
+ cancelPending() {
18040
+ this.cancelTimers();
18041
+ this.disconnectSettlingObserver();
18042
+ this.pendingNavigation = null;
18043
+ }
18044
+ freeze() {
18045
+ this.frozen = true;
18046
+ this.cancelTimers();
18047
+ this.disconnectSettlingObserver();
18048
+ }
18049
+ unfreeze() {
18050
+ this.frozen = false;
18051
+ if (this.pendingNavigation && !this.locked && !this.disabled) {
18052
+ this.startDebounce();
18053
+ }
18054
+ }
18055
+ lock() {
18056
+ this.locked = true;
18057
+ this.cancelTimers();
18058
+ this.disconnectSettlingObserver();
18059
+ }
18060
+ unlock() {
18061
+ this.locked = false;
18062
+ this.pendingNavigation = null;
18063
+ }
18064
+ unsetFrozen() {
18065
+ this.frozen = false;
18066
+ }
18067
+ reset() {
18068
+ this.cancelTimers();
18069
+ this.disconnectSettlingObserver();
18070
+ this.pendingNavigation = null;
18071
+ this.frozen = false;
18072
+ this.locked = false;
18073
+ }
18074
+ destroy() {
18075
+ const hadPending = this.pendingNavigation !== null;
18076
+ this.reset();
18077
+ this.disabled = true;
18078
+ if (hadPending) {
18079
+ this.onSnapshot(true);
18080
+ }
18081
+ }
18082
+ startDebounce() {
18083
+ this.debounceTimer = setTimeout(() => {
18084
+ this.debounceTimer = null;
18085
+ this.startDOMSettling();
18086
+ }, this.debounceMs);
18087
+ }
18088
+ startDOMSettling() {
18089
+ if (this.frozen || this.locked || this.disabled) return;
18090
+ this.lastMutationTime = performance.now();
18091
+ const ObserverCtor = mutationObserverCtor();
18092
+ this.settlingObserver = new ObserverCtor(() => {
18093
+ this.lastMutationTime = performance.now();
18094
+ if (this.settleCheckTimer !== null) {
18095
+ clearTimeout(this.settleCheckTimer);
18096
+ }
18097
+ this.settleCheckTimer = setTimeout(
18098
+ () => this.checkSettled(),
18099
+ this.settleTimeout
18100
+ );
18101
+ });
18102
+ this.settlingObserver.observe(this.doc, {
18103
+ childList: true,
18104
+ subtree: true,
18105
+ attributes: true,
18106
+ characterData: true
18107
+ });
18108
+ this.settleCheckTimer = setTimeout(
18109
+ () => this.checkSettled(),
18110
+ this.settleTimeout
18111
+ );
18112
+ this.maxWaitTimer = setTimeout(() => {
18113
+ this.maxWaitTimer = null;
18114
+ this.completeSettling();
18115
+ }, this.maxWait);
18116
+ }
18117
+ checkSettled() {
18118
+ this.settleCheckTimer = null;
18119
+ const elapsed = performance.now() - this.lastMutationTime;
18120
+ if (elapsed >= this.settleTimeout) {
18121
+ this.completeSettling();
18122
+ } else {
18123
+ this.settleCheckTimer = setTimeout(
18124
+ () => this.checkSettled(),
18125
+ this.settleTimeout - elapsed
18126
+ );
18127
+ }
18128
+ }
18129
+ completeSettling() {
18130
+ if (this.frozen || this.locked || this.disabled) return;
18131
+ if (!this.pendingNavigation) return;
18132
+ this.cancelTimers();
18133
+ this.disconnectSettlingObserver();
18134
+ this.pendingNavigation = null;
18135
+ this.onSnapshot(true);
18136
+ }
18137
+ cancelTimers() {
18138
+ if (this.debounceTimer !== null) {
18139
+ clearTimeout(this.debounceTimer);
18140
+ this.debounceTimer = null;
18141
+ }
18142
+ if (this.settleCheckTimer !== null) {
18143
+ clearTimeout(this.settleCheckTimer);
18144
+ this.settleCheckTimer = null;
18145
+ }
18146
+ if (this.maxWaitTimer !== null) {
18147
+ clearTimeout(this.maxWaitTimer);
18148
+ this.maxWaitTimer = null;
18149
+ }
18150
+ }
18151
+ disconnectSettlingObserver() {
18152
+ if (this.settlingObserver) {
18153
+ this.settlingObserver.disconnect();
18154
+ this.settlingObserver = null;
18155
+ }
18156
+ }
18157
+ }
17978
18158
  class StylesheetManager {
17979
18159
  constructor(options) {
17980
18160
  __publicField(this, "trackedLinkElements", /* @__PURE__ */ new WeakSet());
@@ -18058,43 +18238,13 @@ class ProcessedNodeManager {
18058
18238
  destroy() {
18059
18239
  }
18060
18240
  }
18061
- const version$1 = "3.1.1-alpha.3";
18241
+ const version$1 = "3.4.0-alpha.1";
18062
18242
  let wrappedEmit;
18063
18243
  let takeFullSnapshot$1;
18064
18244
  let canvasManager;
18065
18245
  let recording = false;
18066
18246
  const customEventQueue = [];
18067
18247
  let flushCustomEventQueue$1;
18068
- function waitForDOMStabilization(win) {
18069
- const maxWaitMs = 5e3;
18070
- return new Promise((resolve2) => {
18071
- const captureAfterPaint = () => {
18072
- requestAnimationFrame(() => {
18073
- requestAnimationFrame(() => {
18074
- resolve2();
18075
- });
18076
- });
18077
- };
18078
- const safeResolve = /* @__PURE__ */ (() => {
18079
- let called = false;
18080
- return () => {
18081
- if (!called) {
18082
- called = true;
18083
- captureAfterPaint();
18084
- }
18085
- };
18086
- })();
18087
- if (["interactive", "complete"].includes(win.document.readyState)) {
18088
- safeResolve();
18089
- } else {
18090
- win.addEventListener("DOMContentLoaded", safeResolve, { once: true });
18091
- win.addEventListener("load", safeResolve, { once: true });
18092
- setTimeout(() => {
18093
- safeResolve();
18094
- }, maxWaitMs);
18095
- }
18096
- });
18097
- }
18098
18248
  try {
18099
18249
  if (Array.from([1], (x2) => x2 * 2)[0] !== 2) {
18100
18250
  const cleanFrame = document.createElement("iframe");
@@ -18227,6 +18377,7 @@ function record(options = {}) {
18227
18377
  checkoutDebounceTimer = null;
18228
18378
  checkoutPending = false;
18229
18379
  checkoutFreezeTimestamp = null;
18380
+ navigationManager == null ? void 0 : navigationManager.cancelPending();
18230
18381
  takeFullSnapshot$1(true);
18231
18382
  mutationBuffers.forEach((buf) => {
18232
18383
  buf.resetBuffers();
@@ -18235,6 +18386,9 @@ function record(options = {}) {
18235
18386
  if (visibilityManager) {
18236
18387
  visibilityManager.unsetFrozen();
18237
18388
  }
18389
+ if (navigationManager) {
18390
+ navigationManager.unsetFrozen();
18391
+ }
18238
18392
  };
18239
18393
  wrappedEmit = (r2, isCheckout) => {
18240
18394
  var _a2;
@@ -18244,6 +18398,7 @@ function record(options = {}) {
18244
18398
  if (((_a2 = mutationBuffers[0]) == null ? void 0 : _a2.isFrozen()) && !checkoutPending && e2.type !== EventType.FullSnapshot && !(e2.type === EventType.IncrementalSnapshot && e2.data.source === IncrementalSource.Mutation)) {
18245
18399
  mutationBuffers.forEach((buf) => buf.unfreeze());
18246
18400
  visibilityManager == null ? void 0 : visibilityManager.unfreeze();
18401
+ navigationManager == null ? void 0 : navigationManager.unfreeze();
18247
18402
  }
18248
18403
  if (inEmittingFrame) {
18249
18404
  emit == null ? void 0 : emit(eventProcessor(e2), isCheckout);
@@ -18453,6 +18608,7 @@ function record(options = {}) {
18453
18608
  shadowDomManager.init();
18454
18609
  mutationBuffers.forEach((buf) => buf.lock());
18455
18610
  visibilityManager == null ? void 0 : visibilityManager.lock();
18611
+ navigationManager == null ? void 0 : navigationManager.lock();
18456
18612
  const node2 = snapshot(document, {
18457
18613
  mirror,
18458
18614
  blockClass,
@@ -18504,6 +18660,7 @@ function record(options = {}) {
18504
18660
  );
18505
18661
  mutationBuffers.forEach((buf) => buf.unlock());
18506
18662
  visibilityManager == null ? void 0 : visibilityManager.unlock();
18663
+ navigationManager == null ? void 0 : navigationManager.unlock();
18507
18664
  if (document.adoptedStyleSheets && document.adoptedStyleSheets.length > 0)
18508
18665
  stylesheetManager.adoptStyleSheets(
18509
18666
  document.adoptedStyleSheets,
@@ -18516,6 +18673,31 @@ function record(options = {}) {
18516
18673
  }
18517
18674
  customEventQueue.length = 0;
18518
18675
  };
18676
+ let navigationManager;
18677
+ const navigationSampling = sampling.navigation;
18678
+ if (navigationSampling !== false) {
18679
+ const navConfig = typeof navigationSampling === "object" ? navigationSampling : {};
18680
+ navigationManager = new NavigationManager({
18681
+ doc: document,
18682
+ config: navConfig,
18683
+ onSnapshot: (isCheckout) => {
18684
+ if (checkoutPending) {
18685
+ if (checkoutDebounceTimer) {
18686
+ clearTimeout(checkoutDebounceTimer);
18687
+ checkoutDebounceTimer = null;
18688
+ }
18689
+ checkoutPending = false;
18690
+ checkoutFreezeTimestamp = null;
18691
+ mutationBuffers.forEach((buf) => {
18692
+ buf.resetBuffers();
18693
+ buf.unsetFrozen();
18694
+ });
18695
+ visibilityManager == null ? void 0 : visibilityManager.unsetFrozen();
18696
+ }
18697
+ takeFullSnapshot$1(isCheckout);
18698
+ }
18699
+ });
18700
+ }
18519
18701
  try {
18520
18702
  const handlers = [];
18521
18703
  const observe = (doc) => {
@@ -18546,14 +18728,11 @@ function record(options = {}) {
18546
18728
  }
18547
18729
  }),
18548
18730
  navigationCb: (navData) => {
18549
- console.debug(
18550
- `[${nowTimestamp()}] [rrweb:record/navigation] 🧭 Navigation detected:`,
18551
- navData.navigationType,
18552
- navData.oldHref,
18553
- "→",
18554
- navData.href
18555
- );
18556
- takeFullSnapshot$1(true);
18731
+ if (navigationManager) {
18732
+ navigationManager.handleNavigation(navData);
18733
+ } else {
18734
+ takeFullSnapshot$1(true);
18735
+ }
18557
18736
  },
18558
18737
  inputCb: (v2) => wrappedEmit({
18559
18738
  type: EventType.IncrementalSnapshot,
@@ -18672,23 +18851,6 @@ function record(options = {}) {
18672
18851
  flushCustomEventQueue$1();
18673
18852
  }
18674
18853
  };
18675
- const runInit = async () => {
18676
- if (flushCustomEvent === "before") {
18677
- flushCustomEventQueue$1();
18678
- }
18679
- if (recordAfter === "DOMContentStabilized") {
18680
- console.debug(`[${nowTimestamp()}] [rrweb:record] 🟢 Waiting for DOM stabilization...`);
18681
- await waitForDOMStabilization(window);
18682
- console.debug(`[${nowTimestamp()}] [rrweb:record] ✅ DOM stabilized, starting recording`);
18683
- }
18684
- console.debug(`[${nowTimestamp()}] [rrweb:record] ✅ Init dom and takeFullSnapshot `);
18685
- takeFullSnapshot$1();
18686
- handlers.push(observe(document));
18687
- recording = true;
18688
- if (flushCustomEvent === "after") {
18689
- flushCustomEventQueue$1();
18690
- }
18691
- };
18692
18854
  if (document.readyState === "interactive" || document.readyState === "complete") {
18693
18855
  init();
18694
18856
  } else {
@@ -18722,6 +18884,7 @@ function record(options = {}) {
18722
18884
  }
18723
18885
  flushCustomEventQueue$1();
18724
18886
  handlers.forEach((h) => h());
18887
+ navigationManager == null ? void 0 : navigationManager.destroy();
18725
18888
  processedNodeManager.destroy();
18726
18889
  recording = false;
18727
18890
  unregisterErrorHandler();
@@ -21646,7 +21809,7 @@ class Replayer {
21646
21809
  this.config.logger.log(REPLAY_CONSOLE_PREFIX, ...args);
21647
21810
  }
21648
21811
  }
21649
- const version = "3.1.1-alpha.3";
21812
+ const version = "3.4.0-alpha.1";
21650
21813
  const { getVersion } = record;
21651
21814
  const { isRecording } = record;
21652
21815
  const { flushCustomEventQueue } = record;