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