@absolutejs/beacon 0.7.0-beta.1 → 0.7.0-beta.2

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/index.js CHANGED
@@ -77,9 +77,129 @@ var BEACON_ATTRIBUTE = {
77
77
  THEME: "data-beacon-theme"
78
78
  };
79
79
 
80
+ // src/early.ts
81
+ var HISTORY_LIMIT = 16;
82
+ var ENTRY_LIMIT = 50;
83
+ var now = () => typeof performance === "undefined" ? 0 : performance.now();
84
+ var describeNode = (node) => {
85
+ if (!(node instanceof Element))
86
+ return "unknown";
87
+ const id = node.id === "" ? "" : `#${node.id}`;
88
+ const classes = [...node.classList].slice(0, 3).map((name) => `.${name}`).join("");
89
+ return `${node.tagName.toLowerCase()}${id}${classes}`;
90
+ };
91
+ var copyRect = (rect) => rect === undefined ? undefined : {
92
+ bottom: rect.bottom,
93
+ height: rect.height,
94
+ left: rect.left,
95
+ right: rect.right,
96
+ top: rect.top,
97
+ width: rect.width,
98
+ x: rect.x,
99
+ y: rect.y
100
+ };
101
+ var viewportSnapshot = () => {
102
+ const visual = window.visualViewport;
103
+ return {
104
+ documentHeight: document.documentElement.scrollHeight,
105
+ documentWidth: document.documentElement.scrollWidth,
106
+ innerHeight: window.innerHeight,
107
+ innerWidth: window.innerWidth,
108
+ ...visual == null ? {} : {
109
+ visualHeight: visual.height,
110
+ visualOffsetLeft: visual.offsetLeft,
111
+ visualOffsetTop: visual.offsetTop,
112
+ visualScale: visual.scale,
113
+ visualWidth: visual.width
114
+ }
115
+ };
116
+ };
117
+ var appendLimited = (values, value) => {
118
+ values.push(value);
119
+ if (values.length > HISTORY_LIMIT)
120
+ values.splice(0, values.length - HISTORY_LIMIT);
121
+ };
122
+ var installEarlyLayoutShiftBuffer = () => {
123
+ if (typeof window === "undefined" || typeof document === "undefined" || typeof PerformanceObserver === "undefined" || window.__absoluteBeaconEarlyLayoutShift !== undefined)
124
+ return;
125
+ const interactionTimes = [];
126
+ const resizeTimes = [];
127
+ const entries = [];
128
+ const recordInteraction = () => appendLimited(interactionTimes, now());
129
+ const recordResize = () => appendLimited(resizeTimes, now());
130
+ const recordEntries = (rawEntries) => {
131
+ for (const raw of rawEntries) {
132
+ const entry = raw;
133
+ entries.push({
134
+ documentReadyState: document.readyState,
135
+ hadRecentInput: entry.hadRecentInput === true,
136
+ observedAt: now(),
137
+ sources: (entry.sources ?? []).slice(0, 5).map((source) => ({
138
+ ...source.currentRect === undefined ? {} : { currentRect: copyRect(source.currentRect) },
139
+ ...source.node === undefined || source.node === null ? {} : { node: source.node },
140
+ ...source.previousRect === undefined ? {} : { previousRect: copyRect(source.previousRect) },
141
+ target: describeNode(source.node)
142
+ })),
143
+ startTime: entry.startTime,
144
+ value: entry.value ?? 0,
145
+ viewport: viewportSnapshot()
146
+ });
147
+ }
148
+ if (entries.length > ENTRY_LIMIT)
149
+ entries.splice(0, entries.length - ENTRY_LIMIT);
150
+ };
151
+ try {
152
+ const observerStartedAt = now();
153
+ const observer = new PerformanceObserver((list) => recordEntries(list.getEntries()));
154
+ const interactionEvents = [
155
+ "click",
156
+ "keydown",
157
+ "pointerdown",
158
+ "submit"
159
+ ];
160
+ for (const event of interactionEvents)
161
+ window.addEventListener(event, recordInteraction, true);
162
+ window.addEventListener("resize", recordResize);
163
+ window.visualViewport?.addEventListener("resize", recordResize);
164
+ const cleanup = () => {
165
+ for (const event of interactionEvents)
166
+ window.removeEventListener(event, recordInteraction, true);
167
+ window.removeEventListener("resize", recordResize);
168
+ window.visualViewport?.removeEventListener("resize", recordResize);
169
+ };
170
+ window.__absoluteBeaconEarlyLayoutShift = {
171
+ cleanup,
172
+ entries,
173
+ interactionTimes,
174
+ observer,
175
+ observerStartedAt,
176
+ recordEntries,
177
+ resizeTimes
178
+ };
179
+ observer.observe({ buffered: true, type: "layout-shift" });
180
+ } catch {}
181
+ };
182
+ var consumeEarlyLayoutShiftBuffer = () => {
183
+ if (typeof window === "undefined")
184
+ return;
185
+ const installed = window.__absoluteBeaconEarlyLayoutShift;
186
+ if (installed === undefined)
187
+ return;
188
+ installed.recordEntries(installed.observer.takeRecords());
189
+ installed.observer.disconnect();
190
+ installed.cleanup();
191
+ delete window.__absoluteBeaconEarlyLayoutShift;
192
+ return {
193
+ entries: installed.entries,
194
+ interactionTimes: installed.interactionTimes,
195
+ observerStartedAt: installed.observerStartedAt,
196
+ resizeTimes: installed.resizeTimes
197
+ };
198
+ };
199
+
80
200
  // src/index.ts
81
201
  var BEACON_TRACE_HEADER = "x-absolute-trace-id";
82
- var BEACON_SDK_VERSION = "0.7.0-beta.1";
202
+ var BEACON_SDK_VERSION = "0.7.0-beta.2";
83
203
  var inBrowser = () => typeof window !== "undefined";
84
204
  var newId = () => {
85
205
  if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
@@ -496,6 +616,7 @@ var VOLATILE_SIGNAL_TAGS = new Set([
496
616
  "closeCount",
497
617
  "currentRelease",
498
618
  "durationMs",
619
+ "documentReadyState",
499
620
  "elapsedMs",
500
621
  "errorCount",
501
622
  "focusEventTrusted",
@@ -504,6 +625,11 @@ var VOLATILE_SIGNAL_TAGS = new Set([
504
625
  "interactionAgeMs",
505
626
  "lastFocused",
506
627
  "loadCount",
628
+ "layoutShiftBuffered",
629
+ "layoutShiftObservedAtMs",
630
+ "layoutShiftObserverStartedAtMs",
631
+ "layoutShiftSources",
632
+ "layoutShiftStartTimeMs",
507
633
  "newestRelease",
508
634
  "obscuredPx",
509
635
  "presentationDelayMs",
@@ -524,6 +650,15 @@ var VOLATILE_SIGNAL_TAGS = new Set([
524
650
  "thresholdMs",
525
651
  "userAgent",
526
652
  "viewportHeight",
653
+ "viewportDocumentHeight",
654
+ "viewportDocumentWidth",
655
+ "viewportInnerHeight",
656
+ "viewportInnerWidth",
657
+ "viewportVisualHeight",
658
+ "viewportVisualOffsetLeft",
659
+ "viewportVisualOffsetTop",
660
+ "viewportVisualScale",
661
+ "viewportVisualWidth",
527
662
  "viewportWidth",
528
663
  "windowMs"
529
664
  ]);
@@ -929,6 +1064,7 @@ var createBeacon = (options) => {
929
1064
  rating: metric.rating === "good" || metric.rating === "needs-improvement" || metric.rating === "poor" ? metric.rating : "needs-improvement",
930
1065
  ...options.release === undefined ? {} : { release: options.release },
931
1066
  ...replayId === undefined ? {} : { replayId },
1067
+ sessionId,
932
1068
  samplingRate: vitalsOptions.samplingRate ?? 1,
933
1069
  schemaVersion: vitalsOptions.schemaVersion ?? 1,
934
1070
  ...vitalsOptions.sdkVersion === undefined ? {} : { sdkVersion: vitalsOptions.sdkVersion },
@@ -1249,9 +1385,9 @@ var createBeacon = (options) => {
1249
1385
  if (signals === null || signals.authFailureStorms === false)
1250
1386
  return false;
1251
1387
  const label = `${method} ${endpoint2}`;
1252
- const now = Date.now();
1253
- const failures = (authFailuresByEndpoint.get(label) ?? []).filter(({ at }) => now - at < authFailureStormWindowMs);
1254
- failures.push({ at: now, status });
1388
+ const now2 = Date.now();
1389
+ const failures = (authFailuresByEndpoint.get(label) ?? []).filter(({ at }) => now2 - at < authFailureStormWindowMs);
1390
+ failures.push({ at: now2, status });
1255
1391
  authFailuresByEndpoint.set(label, failures);
1256
1392
  if (failures.length < authFailureStormCount || reportedAuthFailureStorms.has(label)) {
1257
1393
  return false;
@@ -2639,9 +2775,9 @@ var createBeacon = (options) => {
2639
2775
  const checkStuckLoading = () => {
2640
2776
  if (document.visibilityState === "hidden")
2641
2777
  return;
2642
- const now = Date.now();
2643
- const missedPollWindow = lastLoadingCheckAt !== undefined && now - lastLoadingCheckAt > STUCK_LOADING_POLL_MS * 3;
2644
- lastLoadingCheckAt = now;
2778
+ const now2 = Date.now();
2779
+ const missedPollWindow = lastLoadingCheckAt !== undefined && now2 - lastLoadingCheckAt > STUCK_LOADING_POLL_MS * 3;
2780
+ lastLoadingCheckAt = now2;
2645
2781
  const indicators = Array.from(document.querySelectorAll(loadingIndicatorSelector));
2646
2782
  const activeIndicators = new Set(indicators);
2647
2783
  for (const tracked of trackedLoadingIndicators) {
@@ -2659,22 +2795,22 @@ var createBeacon = (options) => {
2659
2795
  continue;
2660
2796
  }
2661
2797
  if (missedPollWindow && loadingFirstSeen.has(indicator)) {
2662
- loadingFirstSeen.set(indicator, now);
2798
+ loadingFirstSeen.set(indicator, now2);
2663
2799
  }
2664
2800
  const firstSeen = loadingFirstSeen.get(indicator);
2665
2801
  if (firstSeen === undefined) {
2666
- loadingFirstSeen.set(indicator, now);
2802
+ loadingFirstSeen.set(indicator, now2);
2667
2803
  trackedLoadingIndicators.add(indicator);
2668
2804
  continue;
2669
2805
  }
2670
2806
  const deadlineMs = loadingDeadlineMs(indicator);
2671
- if (now - firstSeen < deadlineMs || reportedStuckLoading.has(indicator)) {
2807
+ if (now2 - firstSeen < deadlineMs || reportedStuckLoading.has(indicator)) {
2672
2808
  continue;
2673
2809
  }
2674
2810
  reportedStuckLoading.add(indicator);
2675
2811
  reportScanIssue(indicator, BEACON_SIGNAL.STUCK_LOADING, `Stuck loading — ${describeElement(indicator)} never resolved`, {
2676
2812
  deadlineMs: String(deadlineMs),
2677
- visibleMs: String(now - firstSeen)
2813
+ visibleMs: String(now2 - firstSeen)
2678
2814
  });
2679
2815
  }
2680
2816
  };
@@ -2777,7 +2913,9 @@ var createBeacon = (options) => {
2777
2913
  if (signals !== null && signals.disruptiveLayoutShifts !== false && typeof PerformanceObserver !== "undefined") {
2778
2914
  const minimum = signals.disruptiveLayoutShiftMin ?? DISRUPTIVE_LAYOUT_SHIFT_DEFAULT_MIN;
2779
2915
  const reported = new Set;
2780
- let viewportResizeTimes = [];
2916
+ const earlyBuffer = consumeEarlyLayoutShiftBuffer();
2917
+ let viewportResizeTimes = [...earlyBuffer?.resizeTimes ?? []];
2918
+ const earlyInteractionTimes = earlyBuffer?.interactionTimes ?? [];
2781
2919
  const recordViewportResize = () => {
2782
2920
  viewportResizeTimes.push(performance.now());
2783
2921
  if (viewportResizeTimes.length > VIEWPORT_RESIZE_HISTORY_LIMIT) {
@@ -2787,50 +2925,120 @@ var createBeacon = (options) => {
2787
2925
  window.addEventListener("resize", recordViewportResize);
2788
2926
  window.visualViewport?.addEventListener("resize", recordViewportResize);
2789
2927
  try {
2928
+ const currentViewport = () => {
2929
+ const visual = window.visualViewport;
2930
+ return {
2931
+ documentHeight: document.documentElement.scrollHeight,
2932
+ documentWidth: document.documentElement.scrollWidth,
2933
+ innerHeight: window.innerHeight,
2934
+ innerWidth: window.innerWidth,
2935
+ ...visual == null ? {} : {
2936
+ visualHeight: visual.height,
2937
+ visualOffsetLeft: visual.offsetLeft,
2938
+ visualOffsetTop: visual.offsetTop,
2939
+ visualScale: visual.scale,
2940
+ visualWidth: visual.width
2941
+ }
2942
+ };
2943
+ };
2944
+ const processLayoutShift = (entry) => {
2945
+ const interactionTimes = [
2946
+ ...earlyInteractionTimes,
2947
+ ...recentInteraction === undefined ? [] : [recentInteraction.performanceAt]
2948
+ ];
2949
+ const interactionAgeMs = interactionTimes.map((interactionAt) => entry.startTime - interactionAt).filter((age) => age >= 0).sort((left, right) => left - right)[0];
2950
+ const beaconSawRecentInput = interactionAgeMs !== undefined && interactionAgeMs <= LAYOUT_SHIFT_RECENT_INTERACTION_MS;
2951
+ const resizeAdjacent = viewportResizeTimes.some((resizedAt) => {
2952
+ const resizeAgeMs = entry.startTime - resizedAt;
2953
+ return resizeAgeMs >= 0 && resizeAgeMs <= LAYOUT_SHIFT_VIEWPORT_RESIZE_SETTLE_MS;
2954
+ });
2955
+ if (entry.hadRecentInput || beaconSawRecentInput || resizeAdjacent || mobileKeyboardViewportActive() || entry.value < minimum)
2956
+ return;
2957
+ const sourceElements = entry.sources.map(({ node }) => node instanceof Element ? node : undefined).filter((node) => node !== undefined);
2958
+ if (sourceElements.length > 0 && sourceElements.every((node) => node.closest(`[${BEACON_ATTRIBUTE.LAYOUT_SHIFT}="allow"]`) !== null))
2959
+ return;
2960
+ const targets = entry.sources.map((source) => source.node instanceof Element ? describeElement(source.node) : source.target).filter((target) => target !== "unknown").slice(0, 5);
2961
+ const key = targets.join(",") || "unknown";
2962
+ const framePhase = entry.startTime < MAIN_THREAD_STALL_DEFAULT_WINDOW_MS ? "startup" : "runtime";
2963
+ const interactionProvenance = key === "unknown" && recentInteraction !== undefined && interactionAgeMs !== undefined && interactionAgeMs <= LAYOUT_SHIFT_INTERACTION_PROVENANCE_MS ? recentInteraction : undefined;
2964
+ const reportKey = key === "unknown" ? [
2965
+ key,
2966
+ framePhase,
2967
+ interactionProvenance?.type ?? "no-interaction",
2968
+ interactionProvenance?.target ?? "unknown"
2969
+ ].join("|") : key;
2970
+ if (reported.has(reportKey))
2971
+ return;
2972
+ reported.add(reportKey);
2973
+ emitSignal(`Disruptive layout shift — ${key} — ${shortUrl(location.href)}`, {
2974
+ documentReadyState: entry.documentReadyState,
2975
+ ...key === "unknown" ? {
2976
+ framePhase,
2977
+ ...interactionProvenance === undefined ? {} : {
2978
+ interactionAgeMs: String(Math.round(interactionAgeMs ?? 0)),
2979
+ interactionTarget: interactionProvenance.target,
2980
+ interactionType: interactionProvenance.type
2981
+ }
2982
+ } : {},
2983
+ layoutShiftBuffered: String(entry.buffered),
2984
+ layoutShiftObservedAtMs: String(Math.round(entry.observedAt)),
2985
+ layoutShiftObserverStartedAtMs: String(Math.round(entry.observerStartedAt)),
2986
+ layoutShiftSources: JSON.stringify(entry.sources.map(({ currentRect, previousRect, target }) => ({
2987
+ currentRect,
2988
+ previousRect,
2989
+ target
2990
+ }))),
2991
+ layoutShiftStartTimeMs: String(Math.round(entry.startTime)),
2992
+ shiftValue: String(entry.value),
2993
+ signal: BEACON_SIGNAL.DISRUPTIVE_LAYOUT_SHIFT,
2994
+ target: key,
2995
+ viewportDocumentHeight: String(entry.viewport.documentHeight),
2996
+ viewportDocumentWidth: String(entry.viewport.documentWidth),
2997
+ viewportInnerHeight: String(entry.viewport.innerHeight),
2998
+ viewportInnerWidth: String(entry.viewport.innerWidth),
2999
+ ...entry.viewport.visualHeight === undefined ? {} : {
3000
+ viewportVisualHeight: String(entry.viewport.visualHeight),
3001
+ viewportVisualOffsetLeft: String(entry.viewport.visualOffsetLeft),
3002
+ viewportVisualOffsetTop: String(entry.viewport.visualOffsetTop),
3003
+ viewportVisualScale: String(entry.viewport.visualScale),
3004
+ viewportVisualWidth: String(entry.viewport.visualWidth)
3005
+ }
3006
+ });
3007
+ };
3008
+ for (const entry of earlyBuffer?.entries ?? []) {
3009
+ processLayoutShift({
3010
+ ...entry,
3011
+ buffered: true,
3012
+ observerStartedAt: earlyBuffer?.observerStartedAt ?? 0
3013
+ });
3014
+ }
3015
+ const observerStartedAt = performance.now();
2790
3016
  const observer = new PerformanceObserver((list) => {
2791
3017
  for (const raw of list.getEntries()) {
2792
3018
  const entry = raw;
2793
- const interactionAgeMs = recentInteraction === undefined ? undefined : entry.startTime - recentInteraction.performanceAt;
2794
- const beaconSawRecentInput = interactionAgeMs !== undefined && interactionAgeMs >= 0 && interactionAgeMs <= LAYOUT_SHIFT_RECENT_INTERACTION_MS;
2795
- const resizeAdjacent = viewportResizeTimes.some((resizedAt) => {
2796
- const resizeAgeMs = entry.startTime - resizedAt;
2797
- return resizeAgeMs >= 0 && resizeAgeMs <= LAYOUT_SHIFT_VIEWPORT_RESIZE_SETTLE_MS;
2798
- });
2799
- if (entry.hadRecentInput === true || beaconSawRecentInput || resizeAdjacent || mobileKeyboardViewportActive() || (entry.value ?? 0) < minimum)
2800
- continue;
2801
- const sourceElements = (entry.sources ?? []).map(({ node }) => node instanceof Element ? node : undefined).filter((node) => node !== undefined);
2802
- if (sourceElements.length > 0 && sourceElements.every((node) => node.closest(`[${BEACON_ATTRIBUTE.LAYOUT_SHIFT}="allow"]`) !== null)) {
2803
- continue;
2804
- }
2805
- const targets = sourceElements.map((node) => describeElement(node)).slice(0, 5);
2806
- const key = targets.join(",") || "unknown";
2807
- const framePhase = entry.startTime < MAIN_THREAD_STALL_DEFAULT_WINDOW_MS ? "startup" : "runtime";
2808
- const interactionProvenance = key === "unknown" && recentInteraction !== undefined && interactionAgeMs !== undefined && interactionAgeMs >= 0 && interactionAgeMs <= LAYOUT_SHIFT_INTERACTION_PROVENANCE_MS ? recentInteraction : undefined;
2809
- const reportKey = key === "unknown" ? [
2810
- key,
2811
- framePhase,
2812
- interactionProvenance?.type ?? "no-interaction",
2813
- interactionProvenance?.target ?? "unknown"
2814
- ].join("|") : key;
2815
- if (reported.has(reportKey))
2816
- continue;
2817
- reported.add(reportKey);
2818
- emitSignal(`Disruptive layout shift — ${key} — ${shortUrl(location.href)}`, {
2819
- ...key === "unknown" ? {
2820
- framePhase,
2821
- ...interactionProvenance === undefined ? {} : {
2822
- interactionAgeMs: String(Math.round(interactionAgeMs ?? 0)),
2823
- interactionTarget: interactionProvenance.target,
2824
- interactionType: interactionProvenance.type
2825
- }
2826
- } : {},
2827
- shiftValue: String(entry.value ?? 0),
2828
- signal: BEACON_SIGNAL.DISRUPTIVE_LAYOUT_SHIFT,
2829
- target: key
3019
+ const viewport = currentViewport();
3020
+ processLayoutShift({
3021
+ buffered: entry.startTime < observerStartedAt,
3022
+ documentReadyState: document.readyState,
3023
+ hadRecentInput: entry.hadRecentInput === true,
3024
+ observedAt: performance.now(),
3025
+ observerStartedAt,
3026
+ sources: (entry.sources ?? []).map((source) => ({
3027
+ currentRect: source.currentRect,
3028
+ ...source.node === undefined || source.node === null ? {} : { node: source.node },
3029
+ previousRect: source.previousRect,
3030
+ target: source.node instanceof Element ? describeElement(source.node) : "unknown"
3031
+ })),
3032
+ startTime: entry.startTime,
3033
+ value: entry.value ?? 0,
3034
+ viewport
2830
3035
  });
2831
3036
  }
2832
3037
  });
2833
- observer.observe({ buffered: true, type: "layout-shift" });
3038
+ observer.observe({
3039
+ buffered: earlyBuffer === undefined,
3040
+ type: "layout-shift"
3041
+ });
2834
3042
  cleanups.push(() => {
2835
3043
  observer.disconnect();
2836
3044
  window.removeEventListener("resize", recordViewportResize);
@@ -3352,16 +3560,16 @@ var createBeacon = (options) => {
3352
3560
  jailBurst = [];
3353
3561
  return;
3354
3562
  }
3355
- const now = Date.now();
3563
+ const now2 = Date.now();
3356
3564
  if (jailScroller !== scroller) {
3357
3565
  jailScroller = scroller;
3358
3566
  jailBurst = [];
3359
3567
  }
3360
- jailBurst = jailBurst.filter((entry) => now - entry.at < SCROLL_JAIL_WINDOW_MS);
3568
+ jailBurst = jailBurst.filter((entry) => now2 - entry.at < SCROLL_JAIL_WINDOW_MS);
3361
3569
  if (jailBurst.length === 0) {
3362
3570
  jailStartingScrollGeneration = scrollActivityGeneration;
3363
3571
  }
3364
- jailBurst.push({ at: now, position: scroller.scrollTop });
3572
+ jailBurst.push({ at: now2, position: scroller.scrollTop });
3365
3573
  if (jailBurst.length < SCROLL_JAIL_EVENT_COUNT)
3366
3574
  return;
3367
3575
  const first = jailBurst[0];
@@ -3420,9 +3628,9 @@ var createBeacon = (options) => {
3420
3628
  previous = { x: event.clientX, y: event.clientY };
3421
3629
  if (Math.hypot(dx, dy) < 8)
3422
3630
  return;
3423
- const now = Date.now();
3424
- points = points.filter((point) => now - point.at < THRASHED_CURSOR_WINDOW_MS);
3425
- points.push({ at: now, dx, dy });
3631
+ const now2 = Date.now();
3632
+ points = points.filter((point) => now2 - point.at < THRASHED_CURSOR_WINDOW_MS);
3633
+ points.push({ at: now2, dx, dy });
3426
3634
  let reversals = 0;
3427
3635
  for (let index = 1;index < points.length; index += 1) {
3428
3636
  const prior = points[index - 1];
@@ -3650,14 +3858,14 @@ var createBeacon = (options) => {
3650
3858
  if (data === null)
3651
3859
  return;
3652
3860
  const activity = activityFor(form);
3653
- const now = Date.now();
3861
+ const now2 = Date.now();
3654
3862
  if (data !== activity.lastData) {
3655
3863
  activity.lastData = data;
3656
- activity.identicalSubmits = [now];
3864
+ activity.identicalSubmits = [now2];
3657
3865
  return;
3658
3866
  }
3659
- activity.identicalSubmits = activity.identicalSubmits.filter((at) => now - at < FORM_FRUSTRATION_WINDOW_MS);
3660
- activity.identicalSubmits.push(now);
3867
+ activity.identicalSubmits = activity.identicalSubmits.filter((at) => now2 - at < FORM_FRUSTRATION_WINDOW_MS);
3868
+ activity.identicalSubmits.push(now2);
3661
3869
  if (activity.identicalSubmits.length >= FORM_FRUSTRATION_THRESHOLD) {
3662
3870
  reportForm(form, "was submitted with identical values repeatedly");
3663
3871
  }
@@ -3668,14 +3876,14 @@ var createBeacon = (options) => {
3668
3876
  if (form === null)
3669
3877
  return;
3670
3878
  const activity = activityFor(form);
3671
- const now = Date.now();
3672
- if (now - activity.lastInvalidAt < FORM_INVALID_BURST_GAP_MS) {
3673
- activity.lastInvalidAt = now;
3879
+ const now2 = Date.now();
3880
+ if (now2 - activity.lastInvalidAt < FORM_INVALID_BURST_GAP_MS) {
3881
+ activity.lastInvalidAt = now2;
3674
3882
  return;
3675
3883
  }
3676
- activity.lastInvalidAt = now;
3677
- activity.invalidBursts = activity.invalidBursts.filter((at) => now - at < FORM_FRUSTRATION_WINDOW_MS);
3678
- activity.invalidBursts.push(now);
3884
+ activity.lastInvalidAt = now2;
3885
+ activity.invalidBursts = activity.invalidBursts.filter((at) => now2 - at < FORM_FRUSTRATION_WINDOW_MS);
3886
+ activity.invalidBursts.push(now2);
3679
3887
  if (activity.invalidBursts.length >= FORM_FRUSTRATION_THRESHOLD) {
3680
3888
  reportForm(form, "keeps failing native validation");
3681
3889
  }
@@ -3774,9 +3982,9 @@ var createBeacon = (options) => {
3774
3982
  if (signals.sseFlapping === false || pageLifecycleEnding || document.visibilityState === "hidden") {
3775
3983
  return;
3776
3984
  }
3777
- const now = Date.now();
3778
- const errors = (errorsByEndpoint.get(endpointLabel) ?? []).filter((at) => now - at < sseFlapWindowMs);
3779
- errors.push(now);
3985
+ const now2 = Date.now();
3986
+ const errors = (errorsByEndpoint.get(endpointLabel) ?? []).filter((at) => now2 - at < sseFlapWindowMs);
3987
+ errors.push(now2);
3780
3988
  errorsByEndpoint.set(endpointLabel, errors);
3781
3989
  if (errors.length < sseFlapCount || reportedFlappingStreams.has(endpointLabel)) {
3782
3990
  return;
@@ -3866,10 +4074,10 @@ var createBeacon = (options) => {
3866
4074
  }
3867
4075
  if (signals.socketFlapping === false)
3868
4076
  return;
3869
- const now = Date.now();
3870
- const closes = (closesByUrl.get(label) ?? []).filter((close) => now - close.at < SOCKET_FLAP_WINDOW_MS);
4077
+ const now2 = Date.now();
4078
+ const closes = (closesByUrl.get(label) ?? []).filter((close) => now2 - close.at < SOCKET_FLAP_WINDOW_MS);
3871
4079
  closes.push({
3872
- at: now,
4080
+ at: now2,
3873
4081
  code: typeof CloseEvent !== "undefined" && event instanceof CloseEvent ? event.code : null,
3874
4082
  wasClean: typeof CloseEvent !== "undefined" && event instanceof CloseEvent ? event.wasClean : null
3875
4083
  });
@@ -3885,7 +4093,7 @@ var createBeacon = (options) => {
3885
4093
  windowMs: String(SOCKET_FLAP_WINDOW_MS)
3886
4094
  }, undefined, {
3887
4095
  closeSamples: closes.map((close) => ({
3888
- ageMs: now - close.at,
4096
+ ageMs: now2 - close.at,
3889
4097
  code: close.code,
3890
4098
  wasClean: close.wasClean
3891
4099
  }))
@@ -4116,23 +4324,23 @@ var createBeacon = (options) => {
4116
4324
  try {
4117
4325
  const navigation = performance.getEntriesByType("navigation")[0];
4118
4326
  if (navigation?.type !== "back_forward") {
4119
- const now = Date.now();
4327
+ const now2 = Date.now();
4120
4328
  const route = shortUrl(location.href);
4121
4329
  const raw = sessionStorage.getItem(RELOAD_LOOP_STORAGE_KEY);
4122
4330
  const parsed = raw === null ? [] : JSON.parse(raw);
4123
- let history2 = (Array.isArray(parsed) ? parsed : []).filter((entry) => entry !== null && typeof entry === "object" && typeof entry.at === "number" && typeof entry.route === "string" && now - entry.at < RELOAD_LOOP_WINDOW_MS);
4331
+ let history2 = (Array.isArray(parsed) ? parsed : []).filter((entry) => entry !== null && typeof entry === "object" && typeof entry.at === "number" && typeof entry.route === "string" && now2 - entry.at < RELOAD_LOOP_WINDOW_MS);
4124
4332
  let entryKind = "app";
4125
4333
  const rawNavigationIntent = sessionStorage.getItem(NAVIGATION_INTENT_STORAGE_KEY);
4126
4334
  sessionStorage.removeItem(NAVIGATION_INTENT_STORAGE_KEY);
4127
4335
  const navigationIntentAt = Number(rawNavigationIntent);
4128
- if (rawNavigationIntent !== null && Number.isFinite(navigationIntentAt) && now - navigationIntentAt >= 0 && now - navigationIntentAt <= NAVIGATION_INTENT_MAX_AGE_MS) {
4336
+ if (rawNavigationIntent !== null && Number.isFinite(navigationIntentAt) && now2 - navigationIntentAt >= 0 && now2 - navigationIntentAt <= NAVIGATION_INTENT_MAX_AGE_MS) {
4129
4337
  history2 = [];
4130
4338
  entryKind = "intentional-navigation";
4131
4339
  }
4132
4340
  const rawServiceWorkerUpdateIntent = sessionStorage.getItem(SERVICE_WORKER_UPDATE_INTENT_STORAGE_KEY);
4133
4341
  sessionStorage.removeItem(SERVICE_WORKER_UPDATE_INTENT_STORAGE_KEY);
4134
4342
  const serviceWorkerUpdateIntentAt = Number(rawServiceWorkerUpdateIntent);
4135
- if (rawServiceWorkerUpdateIntent !== null && Number.isFinite(serviceWorkerUpdateIntentAt) && now - serviceWorkerUpdateIntentAt >= 0 && now - serviceWorkerUpdateIntentAt <= NAVIGATION_INTENT_MAX_AGE_MS) {
4343
+ if (rawServiceWorkerUpdateIntent !== null && Number.isFinite(serviceWorkerUpdateIntentAt) && now2 - serviceWorkerUpdateIntentAt >= 0 && now2 - serviceWorkerUpdateIntentAt <= NAVIGATION_INTENT_MAX_AGE_MS) {
4136
4344
  history2 = [];
4137
4345
  entryKind = "service-worker-update";
4138
4346
  }
@@ -4143,7 +4351,7 @@ var createBeacon = (options) => {
4143
4351
  entryKind = "external";
4144
4352
  }
4145
4353
  }
4146
- history2.push({ at: now, route });
4354
+ history2.push({ at: now2, route });
4147
4355
  sessionStorage.setItem(RELOAD_LOOP_STORAGE_KEY, JSON.stringify(history2));
4148
4356
  let loadCount = 0;
4149
4357
  for (let index = history2.length - 1;index >= 0; index -= 1) {
@@ -4152,7 +4360,7 @@ var createBeacon = (options) => {
4152
4360
  loadCount += 1;
4153
4361
  }
4154
4362
  if (loadCount === RELOAD_LOOP_COUNT) {
4155
- const firstLoad = history2.at(-loadCount)?.at ?? now;
4363
+ const firstLoad = history2.at(-loadCount)?.at ?? now2;
4156
4364
  emitSignal(`Reload loop — repeated page loads within a minute — ${shortUrl(location.href)}`, {
4157
4365
  currentRelease: options.release ?? "unknown",
4158
4366
  entryKind,
@@ -4161,7 +4369,7 @@ var createBeacon = (options) => {
4161
4369
  serviceWorkerControlled: String(navigator.serviceWorker?.controller !== null && navigator.serviceWorker?.controller !== undefined),
4162
4370
  serviceWorkerScript: navigator.serviceWorker?.controller?.scriptURL ?? "none",
4163
4371
  signal: BEACON_SIGNAL.RELOAD_LOOP,
4164
- windowMs: String(now - firstLoad)
4372
+ windowMs: String(now2 - firstLoad)
4165
4373
  });
4166
4374
  flush(true);
4167
4375
  }
@@ -4171,7 +4379,7 @@ var createBeacon = (options) => {
4171
4379
  if (signals !== null && signals.staleReleases !== false && typeof localStorage !== "undefined" && typeof options.release === "string" && options.release !== "") {
4172
4380
  try {
4173
4381
  const currentRelease = options.release;
4174
- const now = Date.now();
4382
+ const now2 = Date.now();
4175
4383
  const raw = localStorage.getItem(STALE_RELEASE_STORAGE_KEY);
4176
4384
  const parsed = raw === null ? {} : JSON.parse(raw);
4177
4385
  const firstSeenByRelease = {};
@@ -4181,10 +4389,10 @@ var createBeacon = (options) => {
4181
4389
  firstSeenByRelease[release] = at;
4182
4390
  }
4183
4391
  }
4184
- const currentFirstSeen = firstSeenByRelease[currentRelease] ?? now;
4392
+ const currentFirstSeen = firstSeenByRelease[currentRelease] ?? now2;
4185
4393
  firstSeenByRelease[currentRelease] = currentFirstSeen;
4186
4394
  const newest = Object.entries(firstSeenByRelease).filter(([release, at]) => release !== currentRelease && at > currentFirstSeen).sort((left, right) => right[1] - left[1])[0];
4187
- if (newest !== undefined && now - newest[1] > STALE_RELEASE_GRACE_MS) {
4395
+ if (newest !== undefined && now2 - newest[1] > STALE_RELEASE_GRACE_MS) {
4188
4396
  emitSignal(`Stale release — this page is running a build older than one this browser already saw — ${shortUrl(location.href)}`, {
4189
4397
  currentRelease,
4190
4398
  newestRelease: newest[0],
@@ -4304,9 +4512,9 @@ var createBeacon = (options) => {
4304
4512
  const reportedStorms = new Set;
4305
4513
  recordRequestForStorm = (url, method) => {
4306
4514
  const label = `${method.toUpperCase()} ${shortUrl(url)}`;
4307
- const now = Date.now();
4308
- const hits = (hitsByEndpoint.get(label) ?? []).filter((at) => now - at < stormWindowMs);
4309
- hits.push(now);
4515
+ const now2 = Date.now();
4516
+ const hits = (hitsByEndpoint.get(label) ?? []).filter((at) => now2 - at < stormWindowMs);
4517
+ hits.push(now2);
4310
4518
  hitsByEndpoint.set(label, hits);
4311
4519
  if (hits.length < stormCount || reportedStorms.has(label))
4312
4520
  return;
@@ -4584,5 +4792,5 @@ export {
4584
4792
  redactBeaconEvent
4585
4793
  };
4586
4794
 
4587
- //# debugId=5C89D1E136B8537164756E2164756E21
4795
+ //# debugId=777EFA57561DC75664756E2164756E21
4588
4796
  //# sourceMappingURL=index.js.map