@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.
@@ -16315,6 +16315,7 @@ function initNavigationObserver({
16315
16315
  doc,
16316
16316
  sampling
16317
16317
  }) {
16318
+ var _a2;
16318
16319
  if (sampling.navigation === false) {
16319
16320
  return () => {
16320
16321
  };
@@ -16365,6 +16366,30 @@ function initNavigationObserver({
16365
16366
  handlers.push(restoreReplaceState);
16366
16367
  handlers.push(on("popstate", () => emitNavigation("popstate"), win));
16367
16368
  handlers.push(on("hashchange", () => emitNavigation("hashchange"), win));
16369
+ const useNavigationAPI = typeof sampling.navigation === "object" ? (_a2 = sampling.navigation.useNavigationAPI) != null ? _a2 : true : true;
16370
+ if (useNavigationAPI && "navigation" in win) {
16371
+ try {
16372
+ const nav = win.navigation;
16373
+ const handler = (event) => {
16374
+ var _a22;
16375
+ const navEvent = event;
16376
+ if (navEvent.navigationType === "push" || navEvent.navigationType === "replace") {
16377
+ const destUrl = (_a22 = navEvent.destination) == null ? void 0 : _a22.url;
16378
+ if (destUrl && destUrl !== lastHref) {
16379
+ navigationCb({
16380
+ href: destUrl,
16381
+ oldHref: lastHref,
16382
+ navigationType: "navigate"
16383
+ });
16384
+ lastHref = destUrl;
16385
+ }
16386
+ }
16387
+ };
16388
+ nav.addEventListener("navigate", handler);
16389
+ handlers.push(() => nav.removeEventListener("navigate", handler));
16390
+ } catch (e2) {
16391
+ }
16392
+ }
16368
16393
  return callbackWrapper(() => {
16369
16394
  handlers.forEach((h) => h());
16370
16395
  });
@@ -18513,6 +18538,170 @@ class VisibilityManager {
18513
18538
  }
18514
18539
  }
18515
18540
  }
18541
+ const DEFAULT_SETTLE_TIMEOUT = 150;
18542
+ const DEFAULT_MAX_WAIT = 5e3;
18543
+ const DEFAULT_DEBOUNCE = 100;
18544
+ class NavigationManager {
18545
+ constructor(options) {
18546
+ var _a2, _b, _c;
18547
+ __publicField(this, "frozen", false);
18548
+ __publicField(this, "locked", false);
18549
+ __publicField(this, "disabled", false);
18550
+ __publicField(this, "settleTimeout");
18551
+ __publicField(this, "maxWait");
18552
+ __publicField(this, "debounceMs");
18553
+ __publicField(this, "settlingObserver", null);
18554
+ __publicField(this, "debounceTimer", null);
18555
+ __publicField(this, "settleCheckTimer", null);
18556
+ __publicField(this, "maxWaitTimer", null);
18557
+ __publicField(this, "lastMutationTime", 0);
18558
+ __publicField(this, "pendingNavigation", null);
18559
+ __publicField(this, "doc");
18560
+ __publicField(this, "onSnapshot");
18561
+ const { doc, config, onSnapshot } = options;
18562
+ this.doc = doc;
18563
+ this.onSnapshot = callbackWrapper(onSnapshot);
18564
+ this.settleTimeout = (_a2 = config.settleTimeout) != null ? _a2 : DEFAULT_SETTLE_TIMEOUT;
18565
+ this.maxWait = (_b = config.maxWait) != null ? _b : DEFAULT_MAX_WAIT;
18566
+ this.debounceMs = (_c = config.debounce) != null ? _c : DEFAULT_DEBOUNCE;
18567
+ }
18568
+ handleNavigation(data) {
18569
+ if (this.disabled)
18570
+ return;
18571
+ if (this.locked)
18572
+ return;
18573
+ this.cancelTimers();
18574
+ this.disconnectSettlingObserver();
18575
+ this.pendingNavigation = data;
18576
+ if (this.frozen) {
18577
+ return;
18578
+ }
18579
+ this.startDebounce();
18580
+ }
18581
+ cancelPending() {
18582
+ this.cancelTimers();
18583
+ this.disconnectSettlingObserver();
18584
+ this.pendingNavigation = null;
18585
+ }
18586
+ freeze() {
18587
+ this.frozen = true;
18588
+ this.cancelTimers();
18589
+ this.disconnectSettlingObserver();
18590
+ }
18591
+ unfreeze() {
18592
+ this.frozen = false;
18593
+ if (this.pendingNavigation && !this.locked && !this.disabled) {
18594
+ this.startDebounce();
18595
+ }
18596
+ }
18597
+ lock() {
18598
+ this.locked = true;
18599
+ this.cancelTimers();
18600
+ this.disconnectSettlingObserver();
18601
+ }
18602
+ unlock() {
18603
+ this.locked = false;
18604
+ this.pendingNavigation = null;
18605
+ }
18606
+ unsetFrozen() {
18607
+ this.frozen = false;
18608
+ }
18609
+ reset() {
18610
+ this.cancelTimers();
18611
+ this.disconnectSettlingObserver();
18612
+ this.pendingNavigation = null;
18613
+ this.frozen = false;
18614
+ this.locked = false;
18615
+ }
18616
+ destroy() {
18617
+ this.reset();
18618
+ this.disabled = true;
18619
+ }
18620
+ startDebounce() {
18621
+ this.debounceTimer = setTimeout(() => {
18622
+ this.debounceTimer = null;
18623
+ this.startDOMSettling();
18624
+ }, this.debounceMs);
18625
+ }
18626
+ startDOMSettling() {
18627
+ if (this.frozen || this.locked || this.disabled)
18628
+ return;
18629
+ this.lastMutationTime = performance.now();
18630
+ const ObserverCtor = mutationObserverCtor();
18631
+ this.settlingObserver = new ObserverCtor(() => {
18632
+ this.lastMutationTime = performance.now();
18633
+ if (this.settleCheckTimer !== null) {
18634
+ clearTimeout(this.settleCheckTimer);
18635
+ }
18636
+ this.settleCheckTimer = setTimeout(
18637
+ () => this.checkSettled(),
18638
+ this.settleTimeout
18639
+ );
18640
+ });
18641
+ this.settlingObserver.observe(this.doc, {
18642
+ childList: true,
18643
+ subtree: true,
18644
+ attributes: true,
18645
+ characterData: true
18646
+ });
18647
+ this.settleCheckTimer = setTimeout(
18648
+ () => this.checkSettled(),
18649
+ this.settleTimeout
18650
+ );
18651
+ this.maxWaitTimer = setTimeout(() => {
18652
+ this.maxWaitTimer = null;
18653
+ this.completeSettling();
18654
+ }, this.maxWait);
18655
+ }
18656
+ checkSettled() {
18657
+ this.settleCheckTimer = null;
18658
+ const elapsed = performance.now() - this.lastMutationTime;
18659
+ if (elapsed >= this.settleTimeout) {
18660
+ this.completeSettling();
18661
+ } else {
18662
+ this.settleCheckTimer = setTimeout(
18663
+ () => this.checkSettled(),
18664
+ this.settleTimeout - elapsed
18665
+ );
18666
+ }
18667
+ }
18668
+ completeSettling() {
18669
+ if (this.frozen || this.locked || this.disabled)
18670
+ return;
18671
+ if (!this.pendingNavigation)
18672
+ return;
18673
+ this.cancelTimers();
18674
+ this.disconnectSettlingObserver();
18675
+ this.pendingNavigation = null;
18676
+ requestAnimationFrame(() => {
18677
+ requestAnimationFrame(() => {
18678
+ if (!this.frozen && !this.locked && !this.disabled) {
18679
+ this.onSnapshot(true);
18680
+ }
18681
+ });
18682
+ });
18683
+ }
18684
+ cancelTimers() {
18685
+ if (this.debounceTimer !== null) {
18686
+ clearTimeout(this.debounceTimer);
18687
+ this.debounceTimer = null;
18688
+ }
18689
+ if (this.settleCheckTimer !== null) {
18690
+ clearTimeout(this.settleCheckTimer);
18691
+ this.settleCheckTimer = null;
18692
+ }
18693
+ if (this.maxWaitTimer !== null) {
18694
+ clearTimeout(this.maxWaitTimer);
18695
+ this.maxWaitTimer = null;
18696
+ }
18697
+ }
18698
+ disconnectSettlingObserver() {
18699
+ if (this.settlingObserver) {
18700
+ this.settlingObserver.disconnect();
18701
+ this.settlingObserver = null;
18702
+ }
18703
+ }
18704
+ }
18516
18705
  class StylesheetManager {
18517
18706
  constructor(options) {
18518
18707
  __publicField(this, "trackedLinkElements", /* @__PURE__ */ new WeakSet());
@@ -18600,43 +18789,13 @@ class ProcessedNodeManager {
18600
18789
  destroy() {
18601
18790
  }
18602
18791
  }
18603
- const version$1 = "3.2.0-alpha.1";
18792
+ const version$1 = "3.3.0-alpha.1";
18604
18793
  let wrappedEmit;
18605
18794
  let takeFullSnapshot$1;
18606
18795
  let canvasManager;
18607
18796
  let recording = false;
18608
18797
  const customEventQueue = [];
18609
18798
  let flushCustomEventQueue$1;
18610
- function waitForDOMStabilization(win) {
18611
- const maxWaitMs = 5e3;
18612
- return new Promise((resolve2) => {
18613
- const captureAfterPaint = () => {
18614
- requestAnimationFrame(() => {
18615
- requestAnimationFrame(() => {
18616
- resolve2();
18617
- });
18618
- });
18619
- };
18620
- const safeResolve = /* @__PURE__ */ (() => {
18621
- let called = false;
18622
- return () => {
18623
- if (!called) {
18624
- called = true;
18625
- captureAfterPaint();
18626
- }
18627
- };
18628
- })();
18629
- if (["interactive", "complete"].includes(win.document.readyState)) {
18630
- safeResolve();
18631
- } else {
18632
- win.addEventListener("DOMContentLoaded", safeResolve, { once: true });
18633
- win.addEventListener("load", safeResolve, { once: true });
18634
- setTimeout(() => {
18635
- safeResolve();
18636
- }, maxWaitMs);
18637
- }
18638
- });
18639
- }
18640
18799
  try {
18641
18800
  if (Array.from([1], (x2) => x2 * 2)[0] !== 2) {
18642
18801
  const cleanFrame = document.createElement("iframe");
@@ -18769,6 +18928,7 @@ function record(options = {}) {
18769
18928
  checkoutDebounceTimer = null;
18770
18929
  checkoutPending = false;
18771
18930
  checkoutFreezeTimestamp = null;
18931
+ navigationManager == null ? void 0 : navigationManager.cancelPending();
18772
18932
  takeFullSnapshot$1(true);
18773
18933
  mutationBuffers.forEach((buf) => {
18774
18934
  buf.resetBuffers();
@@ -18777,6 +18937,9 @@ function record(options = {}) {
18777
18937
  if (visibilityManager) {
18778
18938
  visibilityManager.unsetFrozen();
18779
18939
  }
18940
+ if (navigationManager) {
18941
+ navigationManager.unsetFrozen();
18942
+ }
18780
18943
  };
18781
18944
  wrappedEmit = (r2, isCheckout) => {
18782
18945
  var _a2;
@@ -18786,6 +18949,7 @@ function record(options = {}) {
18786
18949
  if (((_a2 = mutationBuffers[0]) == null ? void 0 : _a2.isFrozen()) && !checkoutPending && e2.type !== EventType.FullSnapshot && !(e2.type === EventType.IncrementalSnapshot && e2.data.source === IncrementalSource.Mutation)) {
18787
18950
  mutationBuffers.forEach((buf) => buf.unfreeze());
18788
18951
  visibilityManager == null ? void 0 : visibilityManager.unfreeze();
18952
+ navigationManager == null ? void 0 : navigationManager.unfreeze();
18789
18953
  }
18790
18954
  if (inEmittingFrame) {
18791
18955
  emit == null ? void 0 : emit(eventProcessor(e2), isCheckout);
@@ -18990,6 +19154,7 @@ function record(options = {}) {
18990
19154
  shadowDomManager.init();
18991
19155
  mutationBuffers.forEach((buf) => buf.lock());
18992
19156
  visibilityManager == null ? void 0 : visibilityManager.lock();
19157
+ navigationManager == null ? void 0 : navigationManager.lock();
18993
19158
  const node2 = snapshot(document, {
18994
19159
  mirror,
18995
19160
  blockClass,
@@ -19041,6 +19206,7 @@ function record(options = {}) {
19041
19206
  );
19042
19207
  mutationBuffers.forEach((buf) => buf.unlock());
19043
19208
  visibilityManager == null ? void 0 : visibilityManager.unlock();
19209
+ navigationManager == null ? void 0 : navigationManager.unlock();
19044
19210
  if (document.adoptedStyleSheets && document.adoptedStyleSheets.length > 0)
19045
19211
  stylesheetManager.adoptStyleSheets(
19046
19212
  document.adoptedStyleSheets,
@@ -19053,6 +19219,31 @@ function record(options = {}) {
19053
19219
  }
19054
19220
  customEventQueue.length = 0;
19055
19221
  };
19222
+ let navigationManager;
19223
+ const navigationSampling = sampling.navigation;
19224
+ if (navigationSampling !== false) {
19225
+ const navConfig = typeof navigationSampling === "object" ? navigationSampling : {};
19226
+ navigationManager = new NavigationManager({
19227
+ doc: document,
19228
+ config: navConfig,
19229
+ onSnapshot: (isCheckout) => {
19230
+ if (checkoutPending) {
19231
+ if (checkoutDebounceTimer) {
19232
+ clearTimeout(checkoutDebounceTimer);
19233
+ checkoutDebounceTimer = null;
19234
+ }
19235
+ checkoutPending = false;
19236
+ checkoutFreezeTimestamp = null;
19237
+ mutationBuffers.forEach((buf) => {
19238
+ buf.resetBuffers();
19239
+ buf.unsetFrozen();
19240
+ });
19241
+ visibilityManager == null ? void 0 : visibilityManager.unsetFrozen();
19242
+ }
19243
+ takeFullSnapshot$1(isCheckout);
19244
+ }
19245
+ });
19246
+ }
19056
19247
  try {
19057
19248
  const handlers = [];
19058
19249
  const observe = (doc) => {
@@ -19081,14 +19272,11 @@ function record(options = {}) {
19081
19272
  }, d)
19082
19273
  }),
19083
19274
  navigationCb: (navData) => {
19084
- console.debug(
19085
- `[${nowTimestamp()}] [rrweb:record/navigation] \u{1F9ED} Navigation detected:`,
19086
- navData.navigationType,
19087
- navData.oldHref,
19088
- "\u2192",
19089
- navData.href
19090
- );
19091
- takeFullSnapshot$1(true);
19275
+ if (navigationManager) {
19276
+ navigationManager.handleNavigation(navData);
19277
+ } else {
19278
+ takeFullSnapshot$1(true);
19279
+ }
19092
19280
  },
19093
19281
  inputCb: (v2) => wrappedEmit({
19094
19282
  type: EventType.IncrementalSnapshot,
@@ -19200,23 +19388,6 @@ function record(options = {}) {
19200
19388
  flushCustomEventQueue$1();
19201
19389
  }
19202
19390
  };
19203
- const runInit = async () => {
19204
- if (flushCustomEvent === "before") {
19205
- flushCustomEventQueue$1();
19206
- }
19207
- if (recordAfter === "DOMContentStabilized") {
19208
- console.debug(`[${nowTimestamp()}] [rrweb:record] \u{1F7E2} Waiting for DOM stabilization...`);
19209
- await waitForDOMStabilization(window);
19210
- console.debug(`[${nowTimestamp()}] [rrweb:record] \u2705 DOM stabilized, starting recording`);
19211
- }
19212
- console.debug(`[${nowTimestamp()}] [rrweb:record] \u2705 Init dom and takeFullSnapshot `);
19213
- takeFullSnapshot$1();
19214
- handlers.push(observe(document));
19215
- recording = true;
19216
- if (flushCustomEvent === "after") {
19217
- flushCustomEventQueue$1();
19218
- }
19219
- };
19220
19391
  if (document.readyState === "interactive" || document.readyState === "complete") {
19221
19392
  init();
19222
19393
  } else {
@@ -19252,6 +19423,7 @@ function record(options = {}) {
19252
19423
  }
19253
19424
  flushCustomEventQueue$1();
19254
19425
  handlers.forEach((h) => h());
19426
+ navigationManager == null ? void 0 : navigationManager.destroy();
19255
19427
  processedNodeManager.destroy();
19256
19428
  recording = false;
19257
19429
  unregisterErrorHandler();
@@ -22216,7 +22388,7 @@ class Replayer {
22216
22388
  this.config.logger.log(REPLAY_CONSOLE_PREFIX, ...args);
22217
22389
  }
22218
22390
  }
22219
- const version = "3.2.0-alpha.1";
22391
+ const version = "3.3.0-alpha.1";
22220
22392
  const { getVersion } = record;
22221
22393
  const { isRecording } = record;
22222
22394
  const { flushCustomEventQueue } = record;