@appsurify-testmap/rrweb-record 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.
@@ -13858,6 +13858,30 @@ function initNavigationObserver({
13858
13858
  handlers.push(restoreReplaceState);
13859
13859
  handlers.push(on("popstate", () => emitNavigation("popstate"), win));
13860
13860
  handlers.push(on("hashchange", () => emitNavigation("hashchange"), win));
13861
+ const useNavigationAPI = typeof sampling.navigation === "object" ? sampling.navigation.useNavigationAPI ?? true : true;
13862
+ if (useNavigationAPI && "navigation" in win) {
13863
+ try {
13864
+ const nav = win.navigation;
13865
+ const handler = (event) => {
13866
+ var _a2;
13867
+ const navEvent = event;
13868
+ if (navEvent.navigationType === "push" || navEvent.navigationType === "replace") {
13869
+ const destUrl = (_a2 = navEvent.destination) == null ? void 0 : _a2.url;
13870
+ if (destUrl && destUrl !== lastHref) {
13871
+ navigationCb({
13872
+ href: destUrl,
13873
+ oldHref: lastHref,
13874
+ navigationType: "navigate"
13875
+ });
13876
+ lastHref = destUrl;
13877
+ }
13878
+ }
13879
+ };
13880
+ nav.addEventListener("navigate", handler);
13881
+ handlers.push(() => nav.removeEventListener("navigate", handler));
13882
+ } catch {
13883
+ }
13884
+ }
13861
13885
  return callbackWrapper(() => {
13862
13886
  handlers.forEach((h) => h());
13863
13887
  });
@@ -15956,6 +15980,162 @@ class VisibilityManager {
15956
15980
  }
15957
15981
  }
15958
15982
  }
15983
+ const DEFAULT_SETTLE_TIMEOUT = 150;
15984
+ const DEFAULT_MAX_WAIT = 5e3;
15985
+ const DEFAULT_DEBOUNCE = 100;
15986
+ class NavigationManager {
15987
+ constructor(options) {
15988
+ __publicField(this, "frozen", false);
15989
+ __publicField(this, "locked", false);
15990
+ __publicField(this, "disabled", false);
15991
+ __publicField(this, "settleTimeout");
15992
+ __publicField(this, "maxWait");
15993
+ __publicField(this, "debounceMs");
15994
+ __publicField(this, "settlingObserver", null);
15995
+ __publicField(this, "debounceTimer", null);
15996
+ __publicField(this, "settleCheckTimer", null);
15997
+ __publicField(this, "maxWaitTimer", null);
15998
+ __publicField(this, "lastMutationTime", 0);
15999
+ __publicField(this, "pendingNavigation", null);
16000
+ __publicField(this, "doc");
16001
+ __publicField(this, "onSnapshot");
16002
+ const { doc, config, onSnapshot } = options;
16003
+ this.doc = doc;
16004
+ this.onSnapshot = callbackWrapper(onSnapshot);
16005
+ this.settleTimeout = config.settleTimeout ?? DEFAULT_SETTLE_TIMEOUT;
16006
+ this.maxWait = config.maxWait ?? DEFAULT_MAX_WAIT;
16007
+ this.debounceMs = config.debounce ?? DEFAULT_DEBOUNCE;
16008
+ }
16009
+ handleNavigation(data) {
16010
+ if (this.disabled) return;
16011
+ if (this.locked) return;
16012
+ this.cancelTimers();
16013
+ this.disconnectSettlingObserver();
16014
+ this.pendingNavigation = data;
16015
+ if (this.frozen) {
16016
+ return;
16017
+ }
16018
+ this.startDebounce();
16019
+ }
16020
+ cancelPending() {
16021
+ this.cancelTimers();
16022
+ this.disconnectSettlingObserver();
16023
+ this.pendingNavigation = null;
16024
+ }
16025
+ freeze() {
16026
+ this.frozen = true;
16027
+ this.cancelTimers();
16028
+ this.disconnectSettlingObserver();
16029
+ }
16030
+ unfreeze() {
16031
+ this.frozen = false;
16032
+ if (this.pendingNavigation && !this.locked && !this.disabled) {
16033
+ this.startDebounce();
16034
+ }
16035
+ }
16036
+ lock() {
16037
+ this.locked = true;
16038
+ this.cancelTimers();
16039
+ this.disconnectSettlingObserver();
16040
+ }
16041
+ unlock() {
16042
+ this.locked = false;
16043
+ this.pendingNavigation = null;
16044
+ }
16045
+ unsetFrozen() {
16046
+ this.frozen = false;
16047
+ }
16048
+ reset() {
16049
+ this.cancelTimers();
16050
+ this.disconnectSettlingObserver();
16051
+ this.pendingNavigation = null;
16052
+ this.frozen = false;
16053
+ this.locked = false;
16054
+ }
16055
+ destroy() {
16056
+ const hadPending = this.pendingNavigation !== null;
16057
+ this.reset();
16058
+ this.disabled = true;
16059
+ if (hadPending) {
16060
+ this.onSnapshot(true);
16061
+ }
16062
+ }
16063
+ startDebounce() {
16064
+ this.debounceTimer = setTimeout(() => {
16065
+ this.debounceTimer = null;
16066
+ this.startDOMSettling();
16067
+ }, this.debounceMs);
16068
+ }
16069
+ startDOMSettling() {
16070
+ if (this.frozen || this.locked || this.disabled) return;
16071
+ this.lastMutationTime = performance.now();
16072
+ const ObserverCtor = mutationObserverCtor();
16073
+ this.settlingObserver = new ObserverCtor(() => {
16074
+ this.lastMutationTime = performance.now();
16075
+ if (this.settleCheckTimer !== null) {
16076
+ clearTimeout(this.settleCheckTimer);
16077
+ }
16078
+ this.settleCheckTimer = setTimeout(
16079
+ () => this.checkSettled(),
16080
+ this.settleTimeout
16081
+ );
16082
+ });
16083
+ this.settlingObserver.observe(this.doc, {
16084
+ childList: true,
16085
+ subtree: true,
16086
+ attributes: true,
16087
+ characterData: true
16088
+ });
16089
+ this.settleCheckTimer = setTimeout(
16090
+ () => this.checkSettled(),
16091
+ this.settleTimeout
16092
+ );
16093
+ this.maxWaitTimer = setTimeout(() => {
16094
+ this.maxWaitTimer = null;
16095
+ this.completeSettling();
16096
+ }, this.maxWait);
16097
+ }
16098
+ checkSettled() {
16099
+ this.settleCheckTimer = null;
16100
+ const elapsed = performance.now() - this.lastMutationTime;
16101
+ if (elapsed >= this.settleTimeout) {
16102
+ this.completeSettling();
16103
+ } else {
16104
+ this.settleCheckTimer = setTimeout(
16105
+ () => this.checkSettled(),
16106
+ this.settleTimeout - elapsed
16107
+ );
16108
+ }
16109
+ }
16110
+ completeSettling() {
16111
+ if (this.frozen || this.locked || this.disabled) return;
16112
+ if (!this.pendingNavigation) return;
16113
+ this.cancelTimers();
16114
+ this.disconnectSettlingObserver();
16115
+ this.pendingNavigation = null;
16116
+ this.onSnapshot(true);
16117
+ }
16118
+ cancelTimers() {
16119
+ if (this.debounceTimer !== null) {
16120
+ clearTimeout(this.debounceTimer);
16121
+ this.debounceTimer = null;
16122
+ }
16123
+ if (this.settleCheckTimer !== null) {
16124
+ clearTimeout(this.settleCheckTimer);
16125
+ this.settleCheckTimer = null;
16126
+ }
16127
+ if (this.maxWaitTimer !== null) {
16128
+ clearTimeout(this.maxWaitTimer);
16129
+ this.maxWaitTimer = null;
16130
+ }
16131
+ }
16132
+ disconnectSettlingObserver() {
16133
+ if (this.settlingObserver) {
16134
+ this.settlingObserver.disconnect();
16135
+ this.settlingObserver = null;
16136
+ }
16137
+ }
16138
+ }
15959
16139
  class StylesheetManager {
15960
16140
  constructor(options) {
15961
16141
  __publicField(this, "trackedLinkElements", /* @__PURE__ */ new WeakSet());
@@ -16039,43 +16219,13 @@ class ProcessedNodeManager {
16039
16219
  destroy() {
16040
16220
  }
16041
16221
  }
16042
- const version$1 = "3.1.1-alpha.3";
16222
+ const version$1 = "3.4.0-alpha.1";
16043
16223
  let wrappedEmit;
16044
16224
  let takeFullSnapshot$1;
16045
16225
  let canvasManager;
16046
16226
  let recording = false;
16047
16227
  const customEventQueue = [];
16048
16228
  let flushCustomEventQueue$1;
16049
- function waitForDOMStabilization(win) {
16050
- const maxWaitMs = 5e3;
16051
- return new Promise((resolve2) => {
16052
- const captureAfterPaint = () => {
16053
- requestAnimationFrame(() => {
16054
- requestAnimationFrame(() => {
16055
- resolve2();
16056
- });
16057
- });
16058
- };
16059
- const safeResolve = /* @__PURE__ */ (() => {
16060
- let called = false;
16061
- return () => {
16062
- if (!called) {
16063
- called = true;
16064
- captureAfterPaint();
16065
- }
16066
- };
16067
- })();
16068
- if (["interactive", "complete"].includes(win.document.readyState)) {
16069
- safeResolve();
16070
- } else {
16071
- win.addEventListener("DOMContentLoaded", safeResolve, { once: true });
16072
- win.addEventListener("load", safeResolve, { once: true });
16073
- setTimeout(() => {
16074
- safeResolve();
16075
- }, maxWaitMs);
16076
- }
16077
- });
16078
- }
16079
16229
  try {
16080
16230
  if (Array.from([1], (x2) => x2 * 2)[0] !== 2) {
16081
16231
  const cleanFrame = document.createElement("iframe");
@@ -16208,6 +16358,7 @@ function record(options = {}) {
16208
16358
  checkoutDebounceTimer = null;
16209
16359
  checkoutPending = false;
16210
16360
  checkoutFreezeTimestamp = null;
16361
+ navigationManager == null ? void 0 : navigationManager.cancelPending();
16211
16362
  takeFullSnapshot$1(true);
16212
16363
  mutationBuffers.forEach((buf) => {
16213
16364
  buf.resetBuffers();
@@ -16216,6 +16367,9 @@ function record(options = {}) {
16216
16367
  if (visibilityManager) {
16217
16368
  visibilityManager.unsetFrozen();
16218
16369
  }
16370
+ if (navigationManager) {
16371
+ navigationManager.unsetFrozen();
16372
+ }
16219
16373
  };
16220
16374
  wrappedEmit = (r2, isCheckout) => {
16221
16375
  var _a2;
@@ -16225,6 +16379,7 @@ function record(options = {}) {
16225
16379
  if (((_a2 = mutationBuffers[0]) == null ? void 0 : _a2.isFrozen()) && !checkoutPending && e2.type !== EventType.FullSnapshot && !(e2.type === EventType.IncrementalSnapshot && e2.data.source === IncrementalSource.Mutation)) {
16226
16380
  mutationBuffers.forEach((buf) => buf.unfreeze());
16227
16381
  visibilityManager == null ? void 0 : visibilityManager.unfreeze();
16382
+ navigationManager == null ? void 0 : navigationManager.unfreeze();
16228
16383
  }
16229
16384
  if (inEmittingFrame) {
16230
16385
  emit == null ? void 0 : emit(eventProcessor(e2), isCheckout);
@@ -16434,6 +16589,7 @@ function record(options = {}) {
16434
16589
  shadowDomManager.init();
16435
16590
  mutationBuffers.forEach((buf) => buf.lock());
16436
16591
  visibilityManager == null ? void 0 : visibilityManager.lock();
16592
+ navigationManager == null ? void 0 : navigationManager.lock();
16437
16593
  const node2 = snapshot(document, {
16438
16594
  mirror,
16439
16595
  blockClass,
@@ -16485,6 +16641,7 @@ function record(options = {}) {
16485
16641
  );
16486
16642
  mutationBuffers.forEach((buf) => buf.unlock());
16487
16643
  visibilityManager == null ? void 0 : visibilityManager.unlock();
16644
+ navigationManager == null ? void 0 : navigationManager.unlock();
16488
16645
  if (document.adoptedStyleSheets && document.adoptedStyleSheets.length > 0)
16489
16646
  stylesheetManager.adoptStyleSheets(
16490
16647
  document.adoptedStyleSheets,
@@ -16497,6 +16654,31 @@ function record(options = {}) {
16497
16654
  }
16498
16655
  customEventQueue.length = 0;
16499
16656
  };
16657
+ let navigationManager;
16658
+ const navigationSampling = sampling.navigation;
16659
+ if (navigationSampling !== false) {
16660
+ const navConfig = typeof navigationSampling === "object" ? navigationSampling : {};
16661
+ navigationManager = new NavigationManager({
16662
+ doc: document,
16663
+ config: navConfig,
16664
+ onSnapshot: (isCheckout) => {
16665
+ if (checkoutPending) {
16666
+ if (checkoutDebounceTimer) {
16667
+ clearTimeout(checkoutDebounceTimer);
16668
+ checkoutDebounceTimer = null;
16669
+ }
16670
+ checkoutPending = false;
16671
+ checkoutFreezeTimestamp = null;
16672
+ mutationBuffers.forEach((buf) => {
16673
+ buf.resetBuffers();
16674
+ buf.unsetFrozen();
16675
+ });
16676
+ visibilityManager == null ? void 0 : visibilityManager.unsetFrozen();
16677
+ }
16678
+ takeFullSnapshot$1(isCheckout);
16679
+ }
16680
+ });
16681
+ }
16500
16682
  try {
16501
16683
  const handlers = [];
16502
16684
  const observe = (doc) => {
@@ -16527,14 +16709,11 @@ function record(options = {}) {
16527
16709
  }
16528
16710
  }),
16529
16711
  navigationCb: (navData) => {
16530
- console.debug(
16531
- `[${nowTimestamp()}] [rrweb:record/navigation] 🧭 Navigation detected:`,
16532
- navData.navigationType,
16533
- navData.oldHref,
16534
- "→",
16535
- navData.href
16536
- );
16537
- takeFullSnapshot$1(true);
16712
+ if (navigationManager) {
16713
+ navigationManager.handleNavigation(navData);
16714
+ } else {
16715
+ takeFullSnapshot$1(true);
16716
+ }
16538
16717
  },
16539
16718
  inputCb: (v2) => wrappedEmit({
16540
16719
  type: EventType.IncrementalSnapshot,
@@ -16653,23 +16832,6 @@ function record(options = {}) {
16653
16832
  flushCustomEventQueue$1();
16654
16833
  }
16655
16834
  };
16656
- const runInit = async () => {
16657
- if (flushCustomEvent === "before") {
16658
- flushCustomEventQueue$1();
16659
- }
16660
- if (recordAfter === "DOMContentStabilized") {
16661
- console.debug(`[${nowTimestamp()}] [rrweb:record] 🟢 Waiting for DOM stabilization...`);
16662
- await waitForDOMStabilization(window);
16663
- console.debug(`[${nowTimestamp()}] [rrweb:record] ✅ DOM stabilized, starting recording`);
16664
- }
16665
- console.debug(`[${nowTimestamp()}] [rrweb:record] ✅ Init dom and takeFullSnapshot `);
16666
- takeFullSnapshot$1();
16667
- handlers.push(observe(document));
16668
- recording = true;
16669
- if (flushCustomEvent === "after") {
16670
- flushCustomEventQueue$1();
16671
- }
16672
- };
16673
16835
  if (document.readyState === "interactive" || document.readyState === "complete") {
16674
16836
  init();
16675
16837
  } else {
@@ -16703,6 +16865,7 @@ function record(options = {}) {
16703
16865
  }
16704
16866
  flushCustomEventQueue$1();
16705
16867
  handlers.forEach((h) => h());
16868
+ navigationManager == null ? void 0 : navigationManager.destroy();
16706
16869
  processedNodeManager.destroy();
16707
16870
  recording = false;
16708
16871
  unregisterErrorHandler();