@absolutejs/beacon 0.7.0-beta.0 → 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.0";
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") {
@@ -486,6 +606,8 @@ var UUID_PATH_SEGMENT = /\b[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-
486
606
  var LONG_IDENTIFIER_SEGMENT = /\b(?:[0-9a-f]{16,}|\d{8,})\b/giu;
487
607
  var VOLATILE_SIGNAL_TAGS = new Set([
488
608
  "actionId",
609
+ "actionTrusted",
610
+ "automation",
489
611
  "attemptCount",
490
612
  "blockingDurationMs",
491
613
  "blockingFrameDurationMs",
@@ -494,12 +616,20 @@ var VOLATILE_SIGNAL_TAGS = new Set([
494
616
  "closeCount",
495
617
  "currentRelease",
496
618
  "durationMs",
619
+ "documentReadyState",
497
620
  "elapsedMs",
498
621
  "errorCount",
622
+ "focusEventTrusted",
499
623
  "inputDelayMs",
500
624
  "interactionId",
501
625
  "interactionAgeMs",
626
+ "lastFocused",
502
627
  "loadCount",
628
+ "layoutShiftBuffered",
629
+ "layoutShiftObservedAtMs",
630
+ "layoutShiftObserverStartedAtMs",
631
+ "layoutShiftSources",
632
+ "layoutShiftStartTimeMs",
503
633
  "newestRelease",
504
634
  "obscuredPx",
505
635
  "presentationDelayMs",
@@ -520,6 +650,15 @@ var VOLATILE_SIGNAL_TAGS = new Set([
520
650
  "thresholdMs",
521
651
  "userAgent",
522
652
  "viewportHeight",
653
+ "viewportDocumentHeight",
654
+ "viewportDocumentWidth",
655
+ "viewportInnerHeight",
656
+ "viewportInnerWidth",
657
+ "viewportVisualHeight",
658
+ "viewportVisualOffsetLeft",
659
+ "viewportVisualOffsetTop",
660
+ "viewportVisualScale",
661
+ "viewportVisualWidth",
523
662
  "viewportWidth",
524
663
  "windowMs"
525
664
  ]);
@@ -925,6 +1064,7 @@ var createBeacon = (options) => {
925
1064
  rating: metric.rating === "good" || metric.rating === "needs-improvement" || metric.rating === "poor" ? metric.rating : "needs-improvement",
926
1065
  ...options.release === undefined ? {} : { release: options.release },
927
1066
  ...replayId === undefined ? {} : { replayId },
1067
+ sessionId,
928
1068
  samplingRate: vitalsOptions.samplingRate ?? 1,
929
1069
  schemaVersion: vitalsOptions.schemaVersion ?? 1,
930
1070
  ...vitalsOptions.sdkVersion === undefined ? {} : { sdkVersion: vitalsOptions.sdkVersion },
@@ -975,12 +1115,13 @@ var createBeacon = (options) => {
975
1115
  let user;
976
1116
  let actionSequence = 0;
977
1117
  let activeAction;
978
- const beginAction = (type, target) => {
1118
+ const beginAction = (type, target, trusted) => {
979
1119
  actionSequence += 1;
980
1120
  activeAction = {
981
1121
  at: Date.now(),
982
1122
  id: `${sessionId}:${actionSequence}`,
983
1123
  target,
1124
+ trusted,
984
1125
  type
985
1126
  };
986
1127
  };
@@ -1026,6 +1167,7 @@ var createBeacon = (options) => {
1026
1167
  ...action === undefined ? {} : {
1027
1168
  actionId: action.id,
1028
1169
  actionTarget: action.target,
1170
+ actionTrusted: String(action.trusted),
1029
1171
  actionType: action.type
1030
1172
  },
1031
1173
  ...event.tags
@@ -1243,9 +1385,9 @@ var createBeacon = (options) => {
1243
1385
  if (signals === null || signals.authFailureStorms === false)
1244
1386
  return false;
1245
1387
  const label = `${method} ${endpoint2}`;
1246
- const now = Date.now();
1247
- const failures = (authFailuresByEndpoint.get(label) ?? []).filter(({ at }) => now - at < authFailureStormWindowMs);
1248
- 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 });
1249
1391
  authFailuresByEndpoint.set(label, failures);
1250
1392
  if (failures.length < authFailureStormCount || reportedAuthFailureStorms.has(label)) {
1251
1393
  return false;
@@ -1949,7 +2091,7 @@ var createBeacon = (options) => {
1949
2091
  if (!(target instanceof Element))
1950
2092
  return;
1951
2093
  const targetName = describeElement(target);
1952
- beginAction("click", targetName);
2094
+ beginAction("click", targetName, event.isTrusted);
1953
2095
  addBreadcrumb({ message: targetName, type: "click" });
1954
2096
  if (signals === null)
1955
2097
  return;
@@ -2005,7 +2147,7 @@ var createBeacon = (options) => {
2005
2147
  if (!(event.target instanceof HTMLFormElement))
2006
2148
  return;
2007
2149
  const target = describeElement(event.target);
2008
- beginAction("submit", target);
2150
+ beginAction("submit", target, event.isTrusted);
2009
2151
  recentInteraction = {
2010
2152
  at: Date.now(),
2011
2153
  performanceAt: performance.now(),
@@ -2020,7 +2162,7 @@ var createBeacon = (options) => {
2020
2162
  if (!(target instanceof Element))
2021
2163
  return;
2022
2164
  const targetName = describeElement(target);
2023
- beginAction("keyboard", targetName);
2165
+ beginAction("keyboard", targetName, event.isTrusted);
2024
2166
  recentInteraction = {
2025
2167
  at: Date.now(),
2026
2168
  performanceAt: performance.now(),
@@ -2633,9 +2775,9 @@ var createBeacon = (options) => {
2633
2775
  const checkStuckLoading = () => {
2634
2776
  if (document.visibilityState === "hidden")
2635
2777
  return;
2636
- const now = Date.now();
2637
- const missedPollWindow = lastLoadingCheckAt !== undefined && now - lastLoadingCheckAt > STUCK_LOADING_POLL_MS * 3;
2638
- lastLoadingCheckAt = now;
2778
+ const now2 = Date.now();
2779
+ const missedPollWindow = lastLoadingCheckAt !== undefined && now2 - lastLoadingCheckAt > STUCK_LOADING_POLL_MS * 3;
2780
+ lastLoadingCheckAt = now2;
2639
2781
  const indicators = Array.from(document.querySelectorAll(loadingIndicatorSelector));
2640
2782
  const activeIndicators = new Set(indicators);
2641
2783
  for (const tracked of trackedLoadingIndicators) {
@@ -2653,22 +2795,22 @@ var createBeacon = (options) => {
2653
2795
  continue;
2654
2796
  }
2655
2797
  if (missedPollWindow && loadingFirstSeen.has(indicator)) {
2656
- loadingFirstSeen.set(indicator, now);
2798
+ loadingFirstSeen.set(indicator, now2);
2657
2799
  }
2658
2800
  const firstSeen = loadingFirstSeen.get(indicator);
2659
2801
  if (firstSeen === undefined) {
2660
- loadingFirstSeen.set(indicator, now);
2802
+ loadingFirstSeen.set(indicator, now2);
2661
2803
  trackedLoadingIndicators.add(indicator);
2662
2804
  continue;
2663
2805
  }
2664
2806
  const deadlineMs = loadingDeadlineMs(indicator);
2665
- if (now - firstSeen < deadlineMs || reportedStuckLoading.has(indicator)) {
2807
+ if (now2 - firstSeen < deadlineMs || reportedStuckLoading.has(indicator)) {
2666
2808
  continue;
2667
2809
  }
2668
2810
  reportedStuckLoading.add(indicator);
2669
2811
  reportScanIssue(indicator, BEACON_SIGNAL.STUCK_LOADING, `Stuck loading — ${describeElement(indicator)} never resolved`, {
2670
2812
  deadlineMs: String(deadlineMs),
2671
- visibleMs: String(now - firstSeen)
2813
+ visibleMs: String(now2 - firstSeen)
2672
2814
  });
2673
2815
  }
2674
2816
  };
@@ -2771,7 +2913,9 @@ var createBeacon = (options) => {
2771
2913
  if (signals !== null && signals.disruptiveLayoutShifts !== false && typeof PerformanceObserver !== "undefined") {
2772
2914
  const minimum = signals.disruptiveLayoutShiftMin ?? DISRUPTIVE_LAYOUT_SHIFT_DEFAULT_MIN;
2773
2915
  const reported = new Set;
2774
- let viewportResizeTimes = [];
2916
+ const earlyBuffer = consumeEarlyLayoutShiftBuffer();
2917
+ let viewportResizeTimes = [...earlyBuffer?.resizeTimes ?? []];
2918
+ const earlyInteractionTimes = earlyBuffer?.interactionTimes ?? [];
2775
2919
  const recordViewportResize = () => {
2776
2920
  viewportResizeTimes.push(performance.now());
2777
2921
  if (viewportResizeTimes.length > VIEWPORT_RESIZE_HISTORY_LIMIT) {
@@ -2781,50 +2925,120 @@ var createBeacon = (options) => {
2781
2925
  window.addEventListener("resize", recordViewportResize);
2782
2926
  window.visualViewport?.addEventListener("resize", recordViewportResize);
2783
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();
2784
3016
  const observer = new PerformanceObserver((list) => {
2785
3017
  for (const raw of list.getEntries()) {
2786
3018
  const entry = raw;
2787
- const interactionAgeMs = recentInteraction === undefined ? undefined : entry.startTime - recentInteraction.performanceAt;
2788
- const beaconSawRecentInput = interactionAgeMs !== undefined && interactionAgeMs >= 0 && interactionAgeMs <= LAYOUT_SHIFT_RECENT_INTERACTION_MS;
2789
- const resizeAdjacent = viewportResizeTimes.some((resizedAt) => {
2790
- const resizeAgeMs = entry.startTime - resizedAt;
2791
- return resizeAgeMs >= 0 && resizeAgeMs <= LAYOUT_SHIFT_VIEWPORT_RESIZE_SETTLE_MS;
2792
- });
2793
- if (entry.hadRecentInput === true || beaconSawRecentInput || resizeAdjacent || mobileKeyboardViewportActive() || (entry.value ?? 0) < minimum)
2794
- continue;
2795
- const sourceElements = (entry.sources ?? []).map(({ node }) => node instanceof Element ? node : undefined).filter((node) => node !== undefined);
2796
- if (sourceElements.length > 0 && sourceElements.every((node) => node.closest(`[${BEACON_ATTRIBUTE.LAYOUT_SHIFT}="allow"]`) !== null)) {
2797
- continue;
2798
- }
2799
- const targets = sourceElements.map((node) => describeElement(node)).slice(0, 5);
2800
- const key = targets.join(",") || "unknown";
2801
- const framePhase = entry.startTime < MAIN_THREAD_STALL_DEFAULT_WINDOW_MS ? "startup" : "runtime";
2802
- const interactionProvenance = key === "unknown" && recentInteraction !== undefined && interactionAgeMs !== undefined && interactionAgeMs >= 0 && interactionAgeMs <= LAYOUT_SHIFT_INTERACTION_PROVENANCE_MS ? recentInteraction : undefined;
2803
- const reportKey = key === "unknown" ? [
2804
- key,
2805
- framePhase,
2806
- interactionProvenance?.type ?? "no-interaction",
2807
- interactionProvenance?.target ?? "unknown"
2808
- ].join("|") : key;
2809
- if (reported.has(reportKey))
2810
- continue;
2811
- reported.add(reportKey);
2812
- emitSignal(`Disruptive layout shift — ${key} — ${shortUrl(location.href)}`, {
2813
- ...key === "unknown" ? {
2814
- framePhase,
2815
- ...interactionProvenance === undefined ? {} : {
2816
- interactionAgeMs: String(Math.round(interactionAgeMs ?? 0)),
2817
- interactionTarget: interactionProvenance.target,
2818
- interactionType: interactionProvenance.type
2819
- }
2820
- } : {},
2821
- shiftValue: String(entry.value ?? 0),
2822
- signal: BEACON_SIGNAL.DISRUPTIVE_LAYOUT_SHIFT,
2823
- 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
2824
3035
  });
2825
3036
  }
2826
3037
  });
2827
- observer.observe({ buffered: true, type: "layout-shift" });
3038
+ observer.observe({
3039
+ buffered: earlyBuffer === undefined,
3040
+ type: "layout-shift"
3041
+ });
2828
3042
  cleanups.push(() => {
2829
3043
  observer.disconnect();
2830
3044
  window.removeEventListener("resize", recordViewportResize);
@@ -3346,16 +3560,16 @@ var createBeacon = (options) => {
3346
3560
  jailBurst = [];
3347
3561
  return;
3348
3562
  }
3349
- const now = Date.now();
3563
+ const now2 = Date.now();
3350
3564
  if (jailScroller !== scroller) {
3351
3565
  jailScroller = scroller;
3352
3566
  jailBurst = [];
3353
3567
  }
3354
- jailBurst = jailBurst.filter((entry) => now - entry.at < SCROLL_JAIL_WINDOW_MS);
3568
+ jailBurst = jailBurst.filter((entry) => now2 - entry.at < SCROLL_JAIL_WINDOW_MS);
3355
3569
  if (jailBurst.length === 0) {
3356
3570
  jailStartingScrollGeneration = scrollActivityGeneration;
3357
3571
  }
3358
- jailBurst.push({ at: now, position: scroller.scrollTop });
3572
+ jailBurst.push({ at: now2, position: scroller.scrollTop });
3359
3573
  if (jailBurst.length < SCROLL_JAIL_EVENT_COUNT)
3360
3574
  return;
3361
3575
  const first = jailBurst[0];
@@ -3414,9 +3628,9 @@ var createBeacon = (options) => {
3414
3628
  previous = { x: event.clientX, y: event.clientY };
3415
3629
  if (Math.hypot(dx, dy) < 8)
3416
3630
  return;
3417
- const now = Date.now();
3418
- points = points.filter((point) => now - point.at < THRASHED_CURSOR_WINDOW_MS);
3419
- 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 });
3420
3634
  let reversals = 0;
3421
3635
  for (let index = 1;index < points.length; index += 1) {
3422
3636
  const prior = points[index - 1];
@@ -3527,19 +3741,29 @@ var createBeacon = (options) => {
3527
3741
  };
3528
3742
  const onFocusOut = (event) => {
3529
3743
  const target = event.target;
3530
- const candidate = target instanceof Element && target.closest(DIALOG_SELECTOR) !== null ? target : null;
3531
- if (candidate === null)
3744
+ if (!(target instanceof Element))
3745
+ return;
3746
+ const dialog = target.closest(DIALOG_SELECTOR);
3747
+ if (dialog === null)
3532
3748
  return;
3749
+ const dialogDescriptor = describeElement(dialog);
3750
+ const focusEventTrusted = event.isTrusted === true;
3533
3751
  setTimeout(() => {
3534
3752
  const active = document.activeElement;
3535
3753
  const focusDropped = active === null || active === document.body;
3536
- if (!focusDropped || candidate.isConnected)
3754
+ if (!focusDropped || target.isConnected)
3537
3755
  return;
3538
- const descriptor = describeElement(candidate);
3756
+ const descriptor = describeElement(target);
3539
3757
  if (reportedFocusLoss.has(descriptor))
3540
3758
  return;
3541
3759
  reportedFocusLoss.add(descriptor);
3542
- emitSignal(`Focus lost — a dialog closed and dropped keyboard focus on body — ${shortUrl(location.href)}`, { lastFocused: descriptor, signal: BEACON_SIGNAL.FOCUS_LOST });
3760
+ emitSignal(`Focus lost — a dialog closed and dropped keyboard focus on body — ${shortUrl(location.href)}`, {
3761
+ dialog: dialogDescriptor,
3762
+ focusEventTrusted: String(focusEventTrusted),
3763
+ lastFocused: descriptor,
3764
+ signal: BEACON_SIGNAL.FOCUS_LOST,
3765
+ ...navigator.webdriver === true ? { automation: "webdriver" } : {}
3766
+ });
3543
3767
  }, 0);
3544
3768
  };
3545
3769
  document.addEventListener("focusin", onFocusIn, true);
@@ -3634,14 +3858,14 @@ var createBeacon = (options) => {
3634
3858
  if (data === null)
3635
3859
  return;
3636
3860
  const activity = activityFor(form);
3637
- const now = Date.now();
3861
+ const now2 = Date.now();
3638
3862
  if (data !== activity.lastData) {
3639
3863
  activity.lastData = data;
3640
- activity.identicalSubmits = [now];
3864
+ activity.identicalSubmits = [now2];
3641
3865
  return;
3642
3866
  }
3643
- activity.identicalSubmits = activity.identicalSubmits.filter((at) => now - at < FORM_FRUSTRATION_WINDOW_MS);
3644
- activity.identicalSubmits.push(now);
3867
+ activity.identicalSubmits = activity.identicalSubmits.filter((at) => now2 - at < FORM_FRUSTRATION_WINDOW_MS);
3868
+ activity.identicalSubmits.push(now2);
3645
3869
  if (activity.identicalSubmits.length >= FORM_FRUSTRATION_THRESHOLD) {
3646
3870
  reportForm(form, "was submitted with identical values repeatedly");
3647
3871
  }
@@ -3652,14 +3876,14 @@ var createBeacon = (options) => {
3652
3876
  if (form === null)
3653
3877
  return;
3654
3878
  const activity = activityFor(form);
3655
- const now = Date.now();
3656
- if (now - activity.lastInvalidAt < FORM_INVALID_BURST_GAP_MS) {
3657
- activity.lastInvalidAt = now;
3879
+ const now2 = Date.now();
3880
+ if (now2 - activity.lastInvalidAt < FORM_INVALID_BURST_GAP_MS) {
3881
+ activity.lastInvalidAt = now2;
3658
3882
  return;
3659
3883
  }
3660
- activity.lastInvalidAt = now;
3661
- activity.invalidBursts = activity.invalidBursts.filter((at) => now - at < FORM_FRUSTRATION_WINDOW_MS);
3662
- 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);
3663
3887
  if (activity.invalidBursts.length >= FORM_FRUSTRATION_THRESHOLD) {
3664
3888
  reportForm(form, "keeps failing native validation");
3665
3889
  }
@@ -3758,9 +3982,9 @@ var createBeacon = (options) => {
3758
3982
  if (signals.sseFlapping === false || pageLifecycleEnding || document.visibilityState === "hidden") {
3759
3983
  return;
3760
3984
  }
3761
- const now = Date.now();
3762
- const errors = (errorsByEndpoint.get(endpointLabel) ?? []).filter((at) => now - at < sseFlapWindowMs);
3763
- errors.push(now);
3985
+ const now2 = Date.now();
3986
+ const errors = (errorsByEndpoint.get(endpointLabel) ?? []).filter((at) => now2 - at < sseFlapWindowMs);
3987
+ errors.push(now2);
3764
3988
  errorsByEndpoint.set(endpointLabel, errors);
3765
3989
  if (errors.length < sseFlapCount || reportedFlappingStreams.has(endpointLabel)) {
3766
3990
  return;
@@ -3850,10 +4074,10 @@ var createBeacon = (options) => {
3850
4074
  }
3851
4075
  if (signals.socketFlapping === false)
3852
4076
  return;
3853
- const now = Date.now();
3854
- 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);
3855
4079
  closes.push({
3856
- at: now,
4080
+ at: now2,
3857
4081
  code: typeof CloseEvent !== "undefined" && event instanceof CloseEvent ? event.code : null,
3858
4082
  wasClean: typeof CloseEvent !== "undefined" && event instanceof CloseEvent ? event.wasClean : null
3859
4083
  });
@@ -3869,7 +4093,7 @@ var createBeacon = (options) => {
3869
4093
  windowMs: String(SOCKET_FLAP_WINDOW_MS)
3870
4094
  }, undefined, {
3871
4095
  closeSamples: closes.map((close) => ({
3872
- ageMs: now - close.at,
4096
+ ageMs: now2 - close.at,
3873
4097
  code: close.code,
3874
4098
  wasClean: close.wasClean
3875
4099
  }))
@@ -4100,23 +4324,23 @@ var createBeacon = (options) => {
4100
4324
  try {
4101
4325
  const navigation = performance.getEntriesByType("navigation")[0];
4102
4326
  if (navigation?.type !== "back_forward") {
4103
- const now = Date.now();
4327
+ const now2 = Date.now();
4104
4328
  const route = shortUrl(location.href);
4105
4329
  const raw = sessionStorage.getItem(RELOAD_LOOP_STORAGE_KEY);
4106
4330
  const parsed = raw === null ? [] : JSON.parse(raw);
4107
- 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);
4108
4332
  let entryKind = "app";
4109
4333
  const rawNavigationIntent = sessionStorage.getItem(NAVIGATION_INTENT_STORAGE_KEY);
4110
4334
  sessionStorage.removeItem(NAVIGATION_INTENT_STORAGE_KEY);
4111
4335
  const navigationIntentAt = Number(rawNavigationIntent);
4112
- 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) {
4113
4337
  history2 = [];
4114
4338
  entryKind = "intentional-navigation";
4115
4339
  }
4116
4340
  const rawServiceWorkerUpdateIntent = sessionStorage.getItem(SERVICE_WORKER_UPDATE_INTENT_STORAGE_KEY);
4117
4341
  sessionStorage.removeItem(SERVICE_WORKER_UPDATE_INTENT_STORAGE_KEY);
4118
4342
  const serviceWorkerUpdateIntentAt = Number(rawServiceWorkerUpdateIntent);
4119
- 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) {
4120
4344
  history2 = [];
4121
4345
  entryKind = "service-worker-update";
4122
4346
  }
@@ -4127,7 +4351,7 @@ var createBeacon = (options) => {
4127
4351
  entryKind = "external";
4128
4352
  }
4129
4353
  }
4130
- history2.push({ at: now, route });
4354
+ history2.push({ at: now2, route });
4131
4355
  sessionStorage.setItem(RELOAD_LOOP_STORAGE_KEY, JSON.stringify(history2));
4132
4356
  let loadCount = 0;
4133
4357
  for (let index = history2.length - 1;index >= 0; index -= 1) {
@@ -4136,7 +4360,7 @@ var createBeacon = (options) => {
4136
4360
  loadCount += 1;
4137
4361
  }
4138
4362
  if (loadCount === RELOAD_LOOP_COUNT) {
4139
- const firstLoad = history2.at(-loadCount)?.at ?? now;
4363
+ const firstLoad = history2.at(-loadCount)?.at ?? now2;
4140
4364
  emitSignal(`Reload loop — repeated page loads within a minute — ${shortUrl(location.href)}`, {
4141
4365
  currentRelease: options.release ?? "unknown",
4142
4366
  entryKind,
@@ -4145,7 +4369,7 @@ var createBeacon = (options) => {
4145
4369
  serviceWorkerControlled: String(navigator.serviceWorker?.controller !== null && navigator.serviceWorker?.controller !== undefined),
4146
4370
  serviceWorkerScript: navigator.serviceWorker?.controller?.scriptURL ?? "none",
4147
4371
  signal: BEACON_SIGNAL.RELOAD_LOOP,
4148
- windowMs: String(now - firstLoad)
4372
+ windowMs: String(now2 - firstLoad)
4149
4373
  });
4150
4374
  flush(true);
4151
4375
  }
@@ -4155,7 +4379,7 @@ var createBeacon = (options) => {
4155
4379
  if (signals !== null && signals.staleReleases !== false && typeof localStorage !== "undefined" && typeof options.release === "string" && options.release !== "") {
4156
4380
  try {
4157
4381
  const currentRelease = options.release;
4158
- const now = Date.now();
4382
+ const now2 = Date.now();
4159
4383
  const raw = localStorage.getItem(STALE_RELEASE_STORAGE_KEY);
4160
4384
  const parsed = raw === null ? {} : JSON.parse(raw);
4161
4385
  const firstSeenByRelease = {};
@@ -4165,10 +4389,10 @@ var createBeacon = (options) => {
4165
4389
  firstSeenByRelease[release] = at;
4166
4390
  }
4167
4391
  }
4168
- const currentFirstSeen = firstSeenByRelease[currentRelease] ?? now;
4392
+ const currentFirstSeen = firstSeenByRelease[currentRelease] ?? now2;
4169
4393
  firstSeenByRelease[currentRelease] = currentFirstSeen;
4170
4394
  const newest = Object.entries(firstSeenByRelease).filter(([release, at]) => release !== currentRelease && at > currentFirstSeen).sort((left, right) => right[1] - left[1])[0];
4171
- if (newest !== undefined && now - newest[1] > STALE_RELEASE_GRACE_MS) {
4395
+ if (newest !== undefined && now2 - newest[1] > STALE_RELEASE_GRACE_MS) {
4172
4396
  emitSignal(`Stale release — this page is running a build older than one this browser already saw — ${shortUrl(location.href)}`, {
4173
4397
  currentRelease,
4174
4398
  newestRelease: newest[0],
@@ -4288,9 +4512,9 @@ var createBeacon = (options) => {
4288
4512
  const reportedStorms = new Set;
4289
4513
  recordRequestForStorm = (url, method) => {
4290
4514
  const label = `${method.toUpperCase()} ${shortUrl(url)}`;
4291
- const now = Date.now();
4292
- const hits = (hitsByEndpoint.get(label) ?? []).filter((at) => now - at < stormWindowMs);
4293
- hits.push(now);
4515
+ const now2 = Date.now();
4516
+ const hits = (hitsByEndpoint.get(label) ?? []).filter((at) => now2 - at < stormWindowMs);
4517
+ hits.push(now2);
4294
4518
  hitsByEndpoint.set(label, hits);
4295
4519
  if (hits.length < stormCount || reportedStorms.has(label))
4296
4520
  return;
@@ -4568,5 +4792,5 @@ export {
4568
4792
  redactBeaconEvent
4569
4793
  };
4570
4794
 
4571
- //# debugId=2893EF726AC7EB0764756E2164756E21
4795
+ //# debugId=777EFA57561DC75664756E2164756E21
4572
4796
  //# sourceMappingURL=index.js.map