@absolutejs/beacon 0.7.0-beta.12 → 0.7.0-beta.13

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
@@ -1,11 +1,3 @@
1
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
- }) : x)(function(x) {
4
- if (typeof require !== "undefined")
5
- return require.apply(this, arguments);
6
- throw Error('Dynamic require of "' + x + '" is not supported');
7
- });
8
-
9
1
  // src/contracts.ts
10
2
  var BEACON_SIGNAL = {
11
3
  AUTH_FAILURE_STORM: "auth_failure_storm",
@@ -199,7 +191,7 @@ var consumeEarlyLayoutShiftBuffer = () => {
199
191
 
200
192
  // src/index.ts
201
193
  var BEACON_TRACE_HEADER = "x-absolute-trace-id";
202
- var BEACON_SDK_VERSION = "0.7.0-beta.12";
194
+ var BEACON_SDK_VERSION = "0.7.0-beta.13";
203
195
  var inBrowser = () => typeof window !== "undefined";
204
196
  var newId = () => {
205
197
  if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
@@ -1033,12 +1025,12 @@ var createBeacon = (options) => {
1033
1025
  let recentInteraction;
1034
1026
  let recentNavigation;
1035
1027
  let reportErrorClick = null;
1036
- const reportCapturedErrorClick = (error, tags2) => {
1028
+ const reportCapturedErrorClick = (error, tags) => {
1037
1029
  if (filterKnownNoise && isKnownBeaconNoise({
1038
1030
  message: error.message,
1039
1031
  name: error.name,
1040
1032
  stack: error.stack,
1041
- tags: tags2
1033
+ tags
1042
1034
  }))
1043
1035
  return;
1044
1036
  reportErrorClick?.(error.name);
@@ -1381,15 +1373,15 @@ var createBeacon = (options) => {
1381
1373
  }
1382
1374
  };
1383
1375
  const interval = window.setInterval(checkWhenVisible, Math.max(1000, probe.intervalMs ?? 60000));
1384
- const onVisibilityChange2 = () => checkWhenVisible();
1376
+ const onVisibilityChange = () => checkWhenVisible();
1385
1377
  window.addEventListener("focus", checkWhenVisible);
1386
1378
  window.addEventListener("online", checkWhenVisible);
1387
- document.addEventListener("visibilitychange", onVisibilityChange2);
1379
+ document.addEventListener("visibilitychange", onVisibilityChange);
1388
1380
  cleanups.push(() => {
1389
1381
  window.clearInterval(interval);
1390
1382
  window.removeEventListener("focus", checkWhenVisible);
1391
1383
  window.removeEventListener("online", checkWhenVisible);
1392
- document.removeEventListener("visibilitychange", onVisibilityChange2);
1384
+ document.removeEventListener("visibilitychange", onVisibilityChange);
1393
1385
  });
1394
1386
  checkServingRelease();
1395
1387
  }
@@ -1437,13 +1429,13 @@ var createBeacon = (options) => {
1437
1429
  const authFailureStormWindowMs = signals?.authFailureStormWindowMs ?? AUTH_FAILURE_STORM_DEFAULT_WINDOW_MS;
1438
1430
  const authFailuresByEndpoint = new Map;
1439
1431
  const reportedAuthFailureStorms = new Set;
1440
- const recordAuthFailure = (endpoint2, method, status) => {
1432
+ const recordAuthFailure = (endpoint, method, status) => {
1441
1433
  if (signals === null || signals.authFailureStorms === false)
1442
1434
  return false;
1443
- const label = `${method} ${endpoint2}`;
1444
- const now2 = Date.now();
1445
- const failures = (authFailuresByEndpoint.get(label) ?? []).filter(({ at }) => now2 - at < authFailureStormWindowMs);
1446
- failures.push({ at: now2, status });
1435
+ const label = `${method} ${endpoint}`;
1436
+ const now = Date.now();
1437
+ const failures = (authFailuresByEndpoint.get(label) ?? []).filter(({ at }) => now - at < authFailureStormWindowMs);
1438
+ failures.push({ at: now, status });
1447
1439
  authFailuresByEndpoint.set(label, failures);
1448
1440
  if (failures.length < authFailureStormCount || reportedAuthFailureStorms.has(label)) {
1449
1441
  return false;
@@ -1451,7 +1443,7 @@ var createBeacon = (options) => {
1451
1443
  reportedAuthFailureStorms.add(label);
1452
1444
  const statuses = [...new Set(failures.map((failure) => failure.status))];
1453
1445
  emitSignal(`Authorization failure storm — ${label} repeatedly rejected requests — ${shortUrl(location.href)}`, {
1454
- endpoint: endpoint2,
1446
+ endpoint,
1455
1447
  failureCount: String(failures.length),
1456
1448
  method,
1457
1449
  signal: BEACON_SIGNAL.AUTH_FAILURE_STORM,
@@ -1545,14 +1537,14 @@ var createBeacon = (options) => {
1545
1537
  const newestFailureAt = Math.max(...failures.map(({ at }) => at));
1546
1538
  const reportDelayMs = Math.max(0, Date.now() - newestFailureAt);
1547
1539
  const endpoints = [
1548
- ...new Set(failures.map(({ endpoint: endpoint2 }) => endpoint2))
1540
+ ...new Set(failures.map(({ endpoint }) => endpoint))
1549
1541
  ].sort();
1550
1542
  const methods = [...new Set(failures.map(({ method }) => method))].sort();
1551
1543
  const onlineStates = [
1552
1544
  ...new Set(failures.map(({ online }) => String(online)))
1553
1545
  ].sort();
1554
1546
  const transports = [
1555
- ...new Set(failures.map(({ transport: transport2 }) => transport2))
1547
+ ...new Set(failures.map(({ transport }) => transport))
1556
1548
  ].sort();
1557
1549
  const visibilityStates = [
1558
1550
  ...new Set(failures.map(({ visibilityState }) => visibilityState))
@@ -1653,7 +1645,7 @@ var createBeacon = (options) => {
1653
1645
  let mutated = false;
1654
1646
  let extended = false;
1655
1647
  let finished = false;
1656
- let timer2;
1648
+ let timer;
1657
1649
  const observeRouterAcceptance = (handledEvent) => {
1658
1650
  if (handledEvent !== event)
1659
1651
  return;
@@ -1666,8 +1658,8 @@ var createBeacon = (options) => {
1666
1658
  finished = true;
1667
1659
  observer.disconnect();
1668
1660
  control.removeEventListener("click", observeRouterAcceptance);
1669
- if (timer2 !== undefined)
1670
- window.clearTimeout(timer2);
1661
+ if (timer !== undefined)
1662
+ window.clearTimeout(timer);
1671
1663
  pendingClickCleanups.delete(cancel);
1672
1664
  report(didRespond, navigationStalled);
1673
1665
  };
@@ -1677,8 +1669,8 @@ var createBeacon = (options) => {
1677
1669
  finished = true;
1678
1670
  observer.disconnect();
1679
1671
  control.removeEventListener("click", observeRouterAcceptance);
1680
- if (timer2 !== undefined)
1681
- window.clearTimeout(timer2);
1672
+ if (timer !== undefined)
1673
+ window.clearTimeout(timer);
1682
1674
  };
1683
1675
  const observer = new MutationObserver(() => {
1684
1676
  mutated = true;
@@ -1691,7 +1683,7 @@ var createBeacon = (options) => {
1691
1683
  });
1692
1684
  pendingClickCleanups.add(cancel);
1693
1685
  control.addEventListener("click", observeRouterAcceptance, { once: true });
1694
- timer2 = window.setTimeout(() => {
1686
+ timer = window.setTimeout(() => {
1695
1687
  if (responded()) {
1696
1688
  finish(true);
1697
1689
  return;
@@ -1701,7 +1693,7 @@ var createBeacon = (options) => {
1701
1693
  return;
1702
1694
  }
1703
1695
  extended = true;
1704
- timer2 = window.setTimeout(() => {
1696
+ timer = window.setTimeout(() => {
1705
1697
  const didRespond = responded();
1706
1698
  finish(didRespond, !didRespond);
1707
1699
  }, navigationResponseMs - DEAD_CLICK_WINDOW_MS);
@@ -2532,12 +2524,12 @@ var createBeacon = (options) => {
2532
2524
  if (first.element.parentElement === second.element.parentElement && (first.positioned || second.positioned)) {
2533
2525
  continue;
2534
2526
  }
2535
- const axis2 = overlapY <= overlapX ? "vertical" : "horizontal";
2527
+ const axis = overlapY <= overlapX ? "vertical" : "horizontal";
2536
2528
  reportScanIssue(first.element, BEACON_SIGNAL.CONTROL_COLLISION, `Control collision — ${describeElement(first.element)} overlaps ${describeElement(second.element)}`, {
2537
2529
  collidesWith: describeElement(second.element),
2538
- collisionAxis: axis2,
2530
+ collisionAxis: axis,
2539
2531
  collisionKind: "overlap",
2540
- overlapPx: String(Math.round(axis2 === "vertical" ? overlapY : overlapX))
2532
+ overlapPx: String(Math.round(axis === "vertical" ? overlapY : overlapX))
2541
2533
  }, scanLayoutContext(first.element, second.element));
2542
2534
  continue;
2543
2535
  }
@@ -2882,9 +2874,9 @@ var createBeacon = (options) => {
2882
2874
  const checkStuckLoading = () => {
2883
2875
  if (document.visibilityState === "hidden")
2884
2876
  return;
2885
- const now2 = Date.now();
2886
- const missedPollWindow = lastLoadingCheckAt !== undefined && now2 - lastLoadingCheckAt > STUCK_LOADING_POLL_MS * 3;
2887
- lastLoadingCheckAt = now2;
2877
+ const now = Date.now();
2878
+ const missedPollWindow = lastLoadingCheckAt !== undefined && now - lastLoadingCheckAt > STUCK_LOADING_POLL_MS * 3;
2879
+ lastLoadingCheckAt = now;
2888
2880
  const indicators = Array.from(document.querySelectorAll(loadingIndicatorSelector));
2889
2881
  const activeIndicators = new Set(indicators);
2890
2882
  for (const tracked of trackedLoadingIndicators) {
@@ -2902,22 +2894,22 @@ var createBeacon = (options) => {
2902
2894
  continue;
2903
2895
  }
2904
2896
  if (missedPollWindow && loadingFirstSeen.has(indicator)) {
2905
- loadingFirstSeen.set(indicator, now2);
2897
+ loadingFirstSeen.set(indicator, now);
2906
2898
  }
2907
2899
  const firstSeen = loadingFirstSeen.get(indicator);
2908
2900
  if (firstSeen === undefined) {
2909
- loadingFirstSeen.set(indicator, now2);
2901
+ loadingFirstSeen.set(indicator, now);
2910
2902
  trackedLoadingIndicators.add(indicator);
2911
2903
  continue;
2912
2904
  }
2913
2905
  const deadlineMs = loadingDeadlineMs(indicator);
2914
- if (now2 - firstSeen < deadlineMs || reportedStuckLoading.has(indicator)) {
2906
+ if (now - firstSeen < deadlineMs || reportedStuckLoading.has(indicator)) {
2915
2907
  continue;
2916
2908
  }
2917
2909
  reportedStuckLoading.add(indicator);
2918
2910
  reportScanIssue(indicator, BEACON_SIGNAL.STUCK_LOADING, `Stuck loading — ${describeElement(indicator)} never resolved`, {
2919
2911
  deadlineMs: String(deadlineMs),
2920
- visibleMs: String(now2 - firstSeen)
2912
+ visibleMs: String(now - firstSeen)
2921
2913
  });
2922
2914
  }
2923
2915
  };
@@ -3315,7 +3307,7 @@ var createBeacon = (options) => {
3315
3307
  if (name === null)
3316
3308
  return;
3317
3309
  const onLoad = () => stopWatching(frame);
3318
- const timer2 = setTimeout(() => {
3310
+ const timer = setTimeout(() => {
3319
3311
  stopWatching(frame);
3320
3312
  if (pageLifecycleEnding || document.visibilityState === "hidden" || !frame.isConnected) {
3321
3313
  return;
@@ -3332,7 +3324,7 @@ var createBeacon = (options) => {
3332
3324
  target: describeElement(frame)
3333
3325
  });
3334
3326
  }, stallMs);
3335
- watched.set(frame, { onLoad, timer: timer2 });
3327
+ watched.set(frame, { onLoad, timer });
3336
3328
  frame.addEventListener("load", onLoad, { once: true });
3337
3329
  };
3338
3330
  const discoverFrames = (root) => {
@@ -3531,9 +3523,9 @@ var createBeacon = (options) => {
3531
3523
  const pending = new Map;
3532
3524
  const reported = new WeakSet;
3533
3525
  const clearPending = (canvas) => {
3534
- const timer2 = pending.get(canvas);
3535
- if (timer2 !== undefined)
3536
- clearTimeout(timer2);
3526
+ const timer = pending.get(canvas);
3527
+ if (timer !== undefined)
3528
+ clearTimeout(timer);
3537
3529
  pending.delete(canvas);
3538
3530
  };
3539
3531
  const onLost = (event) => {
@@ -3541,7 +3533,7 @@ var createBeacon = (options) => {
3541
3533
  return;
3542
3534
  const canvas = event.target;
3543
3535
  clearPending(canvas);
3544
- const timer2 = setTimeout(() => {
3536
+ const timer = setTimeout(() => {
3545
3537
  pending.delete(canvas);
3546
3538
  if (reported.has(canvas) || pageLifecycleEnding || document.visibilityState === "hidden" || !canvas.isConnected) {
3547
3539
  return;
@@ -3558,7 +3550,7 @@ var createBeacon = (options) => {
3558
3550
  target: describeElement(canvas)
3559
3551
  });
3560
3552
  }, graceMs);
3561
- pending.set(canvas, timer2);
3553
+ pending.set(canvas, timer);
3562
3554
  };
3563
3555
  const onRestored = (event) => {
3564
3556
  if (event.target instanceof HTMLCanvasElement)
@@ -3569,8 +3561,8 @@ var createBeacon = (options) => {
3569
3561
  cleanups.push(() => {
3570
3562
  document.removeEventListener("webglcontextlost", onLost, true);
3571
3563
  document.removeEventListener("webglcontextrestored", onRestored, true);
3572
- for (const timer2 of pending.values())
3573
- clearTimeout(timer2);
3564
+ for (const timer of pending.values())
3565
+ clearTimeout(timer);
3574
3566
  pending.clear();
3575
3567
  });
3576
3568
  }
@@ -3579,9 +3571,9 @@ var createBeacon = (options) => {
3579
3571
  const visualViewport = window.visualViewport;
3580
3572
  const settleMs = signals.focusedControlSettleMs ?? FOCUSED_CONTROL_SETTLE_DEFAULT_MS;
3581
3573
  const reported = new Set;
3582
- let timer2;
3574
+ let timer;
3583
3575
  const checkFocusedControl = () => {
3584
- timer2 = undefined;
3576
+ timer = undefined;
3585
3577
  if (pageLifecycleEnding || document.visibilityState === "hidden" || visualViewport.height >= window.innerHeight * KEYBOARD_VIEWPORT_HEIGHT_RATIO_MAX) {
3586
3578
  return;
3587
3579
  }
@@ -3611,9 +3603,9 @@ var createBeacon = (options) => {
3611
3603
  });
3612
3604
  };
3613
3605
  const scheduleCheck = () => {
3614
- if (timer2 !== undefined)
3615
- clearTimeout(timer2);
3616
- timer2 = setTimeout(checkFocusedControl, settleMs);
3606
+ if (timer !== undefined)
3607
+ clearTimeout(timer);
3608
+ timer = setTimeout(checkFocusedControl, settleMs);
3617
3609
  };
3618
3610
  document.addEventListener("focusin", scheduleCheck, true);
3619
3611
  visualViewport.addEventListener("resize", scheduleCheck);
@@ -3622,8 +3614,8 @@ var createBeacon = (options) => {
3622
3614
  document.removeEventListener("focusin", scheduleCheck, true);
3623
3615
  visualViewport.removeEventListener("resize", scheduleCheck);
3624
3616
  visualViewport.removeEventListener("scroll", scheduleCheck);
3625
- if (timer2 !== undefined)
3626
- clearTimeout(timer2);
3617
+ if (timer !== undefined)
3618
+ clearTimeout(timer);
3627
3619
  });
3628
3620
  }
3629
3621
  if (signals.scrollJail !== false) {
@@ -3680,16 +3672,16 @@ var createBeacon = (options) => {
3680
3672
  jailBurst = [];
3681
3673
  return;
3682
3674
  }
3683
- const now2 = Date.now();
3675
+ const now = Date.now();
3684
3676
  if (jailScroller !== scroller) {
3685
3677
  jailScroller = scroller;
3686
3678
  jailBurst = [];
3687
3679
  }
3688
- jailBurst = jailBurst.filter((entry) => now2 - entry.at < SCROLL_JAIL_WINDOW_MS && !entry.event.defaultPrevented);
3680
+ jailBurst = jailBurst.filter((entry) => now - entry.at < SCROLL_JAIL_WINDOW_MS && !entry.event.defaultPrevented);
3689
3681
  if (jailBurst.length === 0) {
3690
3682
  jailStartingScrollGeneration = scrollActivityGeneration;
3691
3683
  }
3692
- jailBurst.push({ at: now2, position: scroller.scrollTop, event });
3684
+ jailBurst.push({ at: now, position: scroller.scrollTop, event });
3693
3685
  if (jailBurst.length < SCROLL_JAIL_EVENT_COUNT)
3694
3686
  return;
3695
3687
  const first = jailBurst[0];
@@ -3724,7 +3716,7 @@ var createBeacon = (options) => {
3724
3716
  scroller: descriptor,
3725
3717
  direction: scrollingDown ? "down" : "up",
3726
3718
  wheelCount: confirmedBurst.length,
3727
- burstDurationMs: now2 - (confirmedBurst[0]?.at ?? now2),
3719
+ burstDurationMs: now - (confirmedBurst[0]?.at ?? now),
3728
3720
  scrollTop: scroller.scrollTop,
3729
3721
  scrollHeight: scroller.scrollHeight,
3730
3722
  clientHeight: scroller.clientHeight,
@@ -3773,9 +3765,9 @@ var createBeacon = (options) => {
3773
3765
  previous = { x: event.clientX, y: event.clientY };
3774
3766
  if (Math.hypot(dx, dy) < 8)
3775
3767
  return;
3776
- const now2 = Date.now();
3777
- points = points.filter((point) => now2 - point.at < THRASHED_CURSOR_WINDOW_MS);
3778
- points.push({ at: now2, dx, dy });
3768
+ const now = Date.now();
3769
+ points = points.filter((point) => now - point.at < THRASHED_CURSOR_WINDOW_MS);
3770
+ points.push({ at: now, dx, dy });
3779
3771
  let reversals = 0;
3780
3772
  for (let index = 1;index < points.length; index += 1) {
3781
3773
  const prior = points[index - 1];
@@ -3839,8 +3831,8 @@ var createBeacon = (options) => {
3839
3831
  };
3840
3832
  const openModals = () => Array.from(document.querySelectorAll(MODAL_SELECTOR)).filter(isRenderedModal);
3841
3833
  const checkInitialModalFocus = (modal) => {
3842
- const timer2 = setTimeout(() => {
3843
- modalTimers.delete(timer2);
3834
+ const timer = setTimeout(() => {
3835
+ modalTimers.delete(timer);
3844
3836
  if (!isRenderedModal(modal))
3845
3837
  return;
3846
3838
  const active = document.activeElement instanceof Element ? document.activeElement : null;
@@ -3848,7 +3840,7 @@ var createBeacon = (options) => {
3848
3840
  return;
3849
3841
  reportModalEscape(modal, active, "initial-focus-missing");
3850
3842
  }, MODAL_FOCUS_SETTLE_MS);
3851
- modalTimers.add(timer2);
3843
+ modalTimers.add(timer);
3852
3844
  };
3853
3845
  const updateModalVisibility = (modal) => {
3854
3846
  knownModals.add(modal);
@@ -3871,8 +3863,8 @@ var createBeacon = (options) => {
3871
3863
  const modals = openModals();
3872
3864
  if (modals.length > 0 && !modals.some((modal) => modal.contains(target))) {
3873
3865
  const modal = modals[modals.length - 1];
3874
- const timer2 = setTimeout(() => {
3875
- modalTimers.delete(timer2);
3866
+ const timer = setTimeout(() => {
3867
+ modalTimers.delete(timer);
3876
3868
  if (!isRenderedModal(modal))
3877
3869
  return;
3878
3870
  const active = document.activeElement instanceof Element ? document.activeElement : null;
@@ -3880,7 +3872,7 @@ var createBeacon = (options) => {
3880
3872
  return;
3881
3873
  reportModalEscape(modal, active, "escaped");
3882
3874
  }, 0);
3883
- modalTimers.add(timer2);
3875
+ modalTimers.add(timer);
3884
3876
  }
3885
3877
  }
3886
3878
  };
@@ -3957,8 +3949,8 @@ var createBeacon = (options) => {
3957
3949
  document.removeEventListener("focusin", onFocusIn, true);
3958
3950
  document.removeEventListener("focusout", onFocusOut, true);
3959
3951
  modalObserver?.disconnect();
3960
- for (const timer2 of modalTimers)
3961
- clearTimeout(timer2);
3952
+ for (const timer of modalTimers)
3953
+ clearTimeout(timer);
3962
3954
  modalTimers.clear();
3963
3955
  knownModals.clear();
3964
3956
  });
@@ -4003,14 +3995,14 @@ var createBeacon = (options) => {
4003
3995
  if (data === null)
4004
3996
  return;
4005
3997
  const activity = activityFor(form);
4006
- const now2 = Date.now();
3998
+ const now = Date.now();
4007
3999
  if (data !== activity.lastData) {
4008
4000
  activity.lastData = data;
4009
- activity.identicalSubmits = [now2];
4001
+ activity.identicalSubmits = [now];
4010
4002
  return;
4011
4003
  }
4012
- activity.identicalSubmits = activity.identicalSubmits.filter((at) => now2 - at < FORM_FRUSTRATION_WINDOW_MS);
4013
- activity.identicalSubmits.push(now2);
4004
+ activity.identicalSubmits = activity.identicalSubmits.filter((at) => now - at < FORM_FRUSTRATION_WINDOW_MS);
4005
+ activity.identicalSubmits.push(now);
4014
4006
  if (activity.identicalSubmits.length >= FORM_FRUSTRATION_THRESHOLD) {
4015
4007
  reportForm(form, "was submitted with identical values repeatedly");
4016
4008
  }
@@ -4021,14 +4013,14 @@ var createBeacon = (options) => {
4021
4013
  if (form === null)
4022
4014
  return;
4023
4015
  const activity = activityFor(form);
4024
- const now2 = Date.now();
4025
- if (now2 - activity.lastInvalidAt < FORM_INVALID_BURST_GAP_MS) {
4026
- activity.lastInvalidAt = now2;
4016
+ const now = Date.now();
4017
+ if (now - activity.lastInvalidAt < FORM_INVALID_BURST_GAP_MS) {
4018
+ activity.lastInvalidAt = now;
4027
4019
  return;
4028
4020
  }
4029
- activity.lastInvalidAt = now2;
4030
- activity.invalidBursts = activity.invalidBursts.filter((at) => now2 - at < FORM_FRUSTRATION_WINDOW_MS);
4031
- activity.invalidBursts.push(now2);
4021
+ activity.lastInvalidAt = now;
4022
+ activity.invalidBursts = activity.invalidBursts.filter((at) => now - at < FORM_FRUSTRATION_WINDOW_MS);
4023
+ activity.invalidBursts.push(now);
4032
4024
  if (activity.invalidBursts.length >= FORM_FRUSTRATION_THRESHOLD) {
4033
4025
  reportForm(form, "keeps failing native validation");
4034
4026
  }
@@ -4127,9 +4119,9 @@ var createBeacon = (options) => {
4127
4119
  if (signals.sseFlapping === false || pageLifecycleEnding || document.visibilityState === "hidden") {
4128
4120
  return;
4129
4121
  }
4130
- const now2 = Date.now();
4131
- const errors = (errorsByEndpoint.get(endpointLabel) ?? []).filter((at) => now2 - at < sseFlapWindowMs);
4132
- errors.push(now2);
4122
+ const now = Date.now();
4123
+ const errors = (errorsByEndpoint.get(endpointLabel) ?? []).filter((at) => now - at < sseFlapWindowMs);
4124
+ errors.push(now);
4133
4125
  errorsByEndpoint.set(endpointLabel, errors);
4134
4126
  if (errors.length < sseFlapCount || reportedFlappingStreams.has(endpointLabel)) {
4135
4127
  return;
@@ -4150,13 +4142,13 @@ var createBeacon = (options) => {
4150
4142
  };
4151
4143
  const originalAddEventListener = source.addEventListener.bind(source);
4152
4144
  const armedTypes = new Set(["error", "message", "open"]);
4153
- source.addEventListener = (type, listener, options2) => {
4145
+ source.addEventListener = (type, listener, options) => {
4154
4146
  if (!armedTypes.has(type)) {
4155
4147
  armedTypes.add(type);
4156
4148
  originalAddEventListener(type, arm);
4157
4149
  }
4158
4150
  if (listener !== null) {
4159
- originalAddEventListener(type, listener, options2);
4151
+ originalAddEventListener(type, listener, options);
4160
4152
  }
4161
4153
  };
4162
4154
  originalAddEventListener("open", arm);
@@ -4222,10 +4214,10 @@ var createBeacon = (options) => {
4222
4214
  }
4223
4215
  if (signals.socketFlapping === false)
4224
4216
  return;
4225
- const now2 = Date.now();
4226
- const closes = (closesByUrl.get(label) ?? []).filter((close) => now2 - close.at < SOCKET_FLAP_WINDOW_MS);
4217
+ const now = Date.now();
4218
+ const closes = (closesByUrl.get(label) ?? []).filter((close) => now - close.at < SOCKET_FLAP_WINDOW_MS);
4227
4219
  closes.push({
4228
- at: now2,
4220
+ at: now,
4229
4221
  code: typeof CloseEvent !== "undefined" && event instanceof CloseEvent ? event.code : null,
4230
4222
  wasClean: typeof CloseEvent !== "undefined" && event instanceof CloseEvent ? event.wasClean : null
4231
4223
  });
@@ -4241,7 +4233,7 @@ var createBeacon = (options) => {
4241
4233
  windowMs: String(SOCKET_FLAP_WINDOW_MS)
4242
4234
  }, undefined, {
4243
4235
  closeSamples: closes.map((close) => ({
4244
- ageMs: now2 - close.at,
4236
+ ageMs: now - close.at,
4245
4237
  code: close.code,
4246
4238
  wasClean: close.wasClean
4247
4239
  }))
@@ -4265,14 +4257,14 @@ var createBeacon = (options) => {
4265
4257
  cleanup();
4266
4258
  }
4267
4259
  });
4268
- const reportWorkerFailure = (workerType, endpointLabel, failureKind2, error) => {
4269
- const key = `${workerType}|${endpointLabel}|${failureKind2}`;
4260
+ const reportWorkerFailure = (workerType, endpointLabel, failureKind, error) => {
4261
+ const key = `${workerType}|${endpointLabel}|${failureKind}`;
4270
4262
  if (reportedWorkerFailures.has(key))
4271
4263
  return;
4272
4264
  reportedWorkerFailures.add(key);
4273
4265
  emitSignal(`Worker failure — ${workerType} worker ${endpointLabel} failed — ${shortUrl(location.href)}`, {
4274
4266
  endpoint: endpointLabel,
4275
- failureKind: failureKind2,
4267
+ failureKind,
4276
4268
  signal: BEACON_SIGNAL.WORKER_FAILURE,
4277
4269
  workerType
4278
4270
  }, undefined, error === undefined ? undefined : {
@@ -4359,14 +4351,14 @@ var createBeacon = (options) => {
4359
4351
  "TimeoutError",
4360
4352
  "TypeError"
4361
4353
  ]);
4362
- const reportServiceWorkerFailure = (endpointLabel, failureKind2, error) => {
4363
- const key = `${endpointLabel}|${failureKind2}`;
4354
+ const reportServiceWorkerFailure = (endpointLabel, failureKind, error) => {
4355
+ const key = `${endpointLabel}|${failureKind}`;
4364
4356
  if (reportedServiceWorkerFailures.has(key))
4365
4357
  return;
4366
4358
  reportedServiceWorkerFailures.add(key);
4367
- emitSignal(`Service worker failure — ${endpointLabel} failed during ${failureKind2} — ${shortUrl(location.href)}`, {
4359
+ emitSignal(`Service worker failure — ${endpointLabel} failed during ${failureKind} — ${shortUrl(location.href)}`, {
4368
4360
  endpoint: endpointLabel,
4369
- failureKind: failureKind2,
4361
+ failureKind,
4370
4362
  signal: BEACON_SIGNAL.SERVICE_WORKER_FAILURE
4371
4363
  }, undefined, error === undefined ? undefined : {
4372
4364
  serviceWorkerError: {
@@ -4376,12 +4368,15 @@ var createBeacon = (options) => {
4376
4368
  }
4377
4369
  });
4378
4370
  };
4379
- const watchInstallingWorker = (worker) => {
4380
- let activated = worker.state === "activated";
4371
+ const watchInstallingWorker = (worker, registration) => {
4372
+ let settled = worker.state === "installed" || worker.state === "activated";
4381
4373
  const onStateChange = () => {
4382
- if (worker.state === "activated")
4383
- activated = true;
4384
- if (worker.state !== "redundant" || activated)
4374
+ if (worker.state === "installed" || worker.state === "activated")
4375
+ settled = true;
4376
+ if (worker.state !== "redundant" || settled)
4377
+ return;
4378
+ const successor = registration?.installing ?? registration?.waiting;
4379
+ if (successor !== null && successor !== undefined && successor !== worker)
4385
4380
  return;
4386
4381
  reportServiceWorkerFailure(shortUrl(worker.scriptURL), "installation");
4387
4382
  };
@@ -4390,11 +4385,11 @@ var createBeacon = (options) => {
4390
4385
  };
4391
4386
  const watchRegistration = (registration) => {
4392
4387
  if (registration.installing !== null) {
4393
- watchInstallingWorker(registration.installing);
4388
+ watchInstallingWorker(registration.installing, registration);
4394
4389
  }
4395
4390
  const onUpdateFound = () => {
4396
4391
  if (registration.installing !== null) {
4397
- watchInstallingWorker(registration.installing);
4392
+ watchInstallingWorker(registration.installing, registration);
4398
4393
  }
4399
4394
  };
4400
4395
  registration.addEventListener("updatefound", onUpdateFound);
@@ -4472,23 +4467,23 @@ var createBeacon = (options) => {
4472
4467
  try {
4473
4468
  const navigation = performance.getEntriesByType("navigation")[0];
4474
4469
  if (navigation?.type !== "back_forward") {
4475
- const now2 = Date.now();
4470
+ const now = Date.now();
4476
4471
  const route = shortUrl(location.href);
4477
4472
  const raw = sessionStorage.getItem(RELOAD_LOOP_STORAGE_KEY);
4478
4473
  const parsed = raw === null ? [] : JSON.parse(raw);
4479
- 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);
4474
+ 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);
4480
4475
  let entryKind = "app";
4481
4476
  const rawNavigationIntent = sessionStorage.getItem(NAVIGATION_INTENT_STORAGE_KEY);
4482
4477
  sessionStorage.removeItem(NAVIGATION_INTENT_STORAGE_KEY);
4483
4478
  const navigationIntentAt = Number(rawNavigationIntent);
4484
- if (rawNavigationIntent !== null && Number.isFinite(navigationIntentAt) && now2 - navigationIntentAt >= 0 && now2 - navigationIntentAt <= NAVIGATION_INTENT_MAX_AGE_MS) {
4479
+ if (rawNavigationIntent !== null && Number.isFinite(navigationIntentAt) && now - navigationIntentAt >= 0 && now - navigationIntentAt <= NAVIGATION_INTENT_MAX_AGE_MS) {
4485
4480
  history2 = [];
4486
4481
  entryKind = "intentional-navigation";
4487
4482
  }
4488
4483
  const rawServiceWorkerUpdateIntent = sessionStorage.getItem(SERVICE_WORKER_UPDATE_INTENT_STORAGE_KEY);
4489
4484
  sessionStorage.removeItem(SERVICE_WORKER_UPDATE_INTENT_STORAGE_KEY);
4490
4485
  const serviceWorkerUpdateIntentAt = Number(rawServiceWorkerUpdateIntent);
4491
- if (rawServiceWorkerUpdateIntent !== null && Number.isFinite(serviceWorkerUpdateIntentAt) && now2 - serviceWorkerUpdateIntentAt >= 0 && now2 - serviceWorkerUpdateIntentAt <= NAVIGATION_INTENT_MAX_AGE_MS) {
4486
+ if (rawServiceWorkerUpdateIntent !== null && Number.isFinite(serviceWorkerUpdateIntentAt) && now - serviceWorkerUpdateIntentAt >= 0 && now - serviceWorkerUpdateIntentAt <= NAVIGATION_INTENT_MAX_AGE_MS) {
4492
4487
  history2 = [];
4493
4488
  entryKind = "service-worker-update";
4494
4489
  }
@@ -4499,7 +4494,7 @@ var createBeacon = (options) => {
4499
4494
  entryKind = "external";
4500
4495
  }
4501
4496
  }
4502
- history2.push({ at: now2, route });
4497
+ history2.push({ at: now, route });
4503
4498
  sessionStorage.setItem(RELOAD_LOOP_STORAGE_KEY, JSON.stringify(history2));
4504
4499
  let loadCount = 0;
4505
4500
  for (let index = history2.length - 1;index >= 0; index -= 1) {
@@ -4508,7 +4503,7 @@ var createBeacon = (options) => {
4508
4503
  loadCount += 1;
4509
4504
  }
4510
4505
  if (loadCount === RELOAD_LOOP_COUNT) {
4511
- const firstLoad = history2.at(-loadCount)?.at ?? now2;
4506
+ const firstLoad = history2.at(-loadCount)?.at ?? now;
4512
4507
  emitSignal(`Reload loop — repeated page loads within a minute — ${shortUrl(location.href)}`, {
4513
4508
  currentRelease: options.release ?? "unknown",
4514
4509
  entryKind,
@@ -4517,7 +4512,7 @@ var createBeacon = (options) => {
4517
4512
  serviceWorkerControlled: String(navigator.serviceWorker?.controller !== null && navigator.serviceWorker?.controller !== undefined),
4518
4513
  serviceWorkerScript: navigator.serviceWorker?.controller?.scriptURL ?? "none",
4519
4514
  signal: BEACON_SIGNAL.RELOAD_LOOP,
4520
- windowMs: String(now2 - firstLoad)
4515
+ windowMs: String(now - firstLoad)
4521
4516
  });
4522
4517
  flush(true);
4523
4518
  }
@@ -4527,7 +4522,7 @@ var createBeacon = (options) => {
4527
4522
  if (signals !== null && signals.staleReleases !== false && typeof localStorage !== "undefined" && typeof options.release === "string" && options.release !== "") {
4528
4523
  try {
4529
4524
  const currentRelease = options.release;
4530
- const now2 = Date.now();
4525
+ const now = Date.now();
4531
4526
  const raw = localStorage.getItem(STALE_RELEASE_STORAGE_KEY);
4532
4527
  const parsed = raw === null ? {} : JSON.parse(raw);
4533
4528
  const firstSeenByRelease = {};
@@ -4537,10 +4532,10 @@ var createBeacon = (options) => {
4537
4532
  firstSeenByRelease[release] = at;
4538
4533
  }
4539
4534
  }
4540
- const currentFirstSeen = firstSeenByRelease[currentRelease] ?? now2;
4535
+ const currentFirstSeen = firstSeenByRelease[currentRelease] ?? now;
4541
4536
  firstSeenByRelease[currentRelease] = currentFirstSeen;
4542
4537
  const newest = Object.entries(firstSeenByRelease).filter(([release, at]) => release !== currentRelease && at > currentFirstSeen).sort((left, right) => right[1] - left[1])[0];
4543
- if (newest !== undefined && now2 - newest[1] > STALE_RELEASE_GRACE_MS) {
4538
+ if (newest !== undefined && now - newest[1] > STALE_RELEASE_GRACE_MS) {
4544
4539
  emitSignal(`Stale release — this page is running a build older than one this browser already saw — ${shortUrl(location.href)}`, {
4545
4540
  currentRelease,
4546
4541
  newestRelease: newest[0],
@@ -4617,8 +4612,8 @@ var createBeacon = (options) => {
4617
4612
  return;
4618
4613
  if (confirmationMs > 0) {
4619
4614
  await new Promise((resolve) => {
4620
- const timer2 = window.setTimeout(resolve, confirmationMs);
4621
- cleanups.push(() => window.clearTimeout(timer2));
4615
+ const timer = window.setTimeout(resolve, confirmationMs);
4616
+ cleanups.push(() => window.clearTimeout(timer));
4622
4617
  });
4623
4618
  if (document.visibilityState === "hidden")
4624
4619
  return;
@@ -4660,9 +4655,9 @@ var createBeacon = (options) => {
4660
4655
  const reportedStorms = new Set;
4661
4656
  recordRequestForStorm = (url, method) => {
4662
4657
  const label = `${method.toUpperCase()} ${shortUrl(url)}`;
4663
- const now2 = Date.now();
4664
- const hits = (hitsByEndpoint.get(label) ?? []).filter((at) => now2 - at < stormWindowMs);
4665
- hits.push(now2);
4658
+ const now = Date.now();
4659
+ const hits = (hitsByEndpoint.get(label) ?? []).filter((at) => now - at < stormWindowMs);
4660
+ hits.push(now);
4666
4661
  hitsByEndpoint.set(label, hits);
4667
4662
  if (hits.length < stormCount || reportedStorms.has(label))
4668
4663
  return;
@@ -4948,5 +4943,5 @@ export {
4948
4943
  redactBeaconEvent
4949
4944
  };
4950
4945
 
4951
- //# debugId=508A7FF4EEF1B17D64756E2164756E21
4946
+ //# debugId=8F6B8B9D4A41867164756E2164756E21
4952
4947
  //# sourceMappingURL=index.js.map