@absolutejs/beacon 0.6.19 → 0.6.21

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
@@ -729,6 +729,7 @@ var createBeacon = (options) => {
729
729
  const STALE_RELEASE_STORAGE_KEY = "beacon:release-first-seen";
730
730
  const STALE_RELEASE_GRACE_MS = 600000;
731
731
  const STALE_RELEASE_HISTORY_LIMIT = 5;
732
+ const RESTORED_SOCKET_CLOSE_GRACE_MS = 1000;
732
733
  const FORM_FRUSTRATION_THRESHOLD = 3;
733
734
  const FORM_FRUSTRATION_WINDOW_MS = 60000;
734
735
  const LAYOUT_SHIFT_RECENT_INTERACTION_MS = 500;
@@ -756,6 +757,8 @@ var createBeacon = (options) => {
756
757
  let clipboardWriteCount = 0;
757
758
  let inSignalConsole = false;
758
759
  let pageLifecycleEnding = false;
760
+ let pageLifecycleGeneration = 0;
761
+ let pageRestoredAt;
759
762
  let recentInteraction;
760
763
  let reportErrorClick = null;
761
764
  let reportFormAbandonmentOnNavigation = null;
@@ -2181,7 +2184,18 @@ var createBeacon = (options) => {
2181
2184
  };
2182
2185
  const loadingFirstSeen = new WeakMap;
2183
2186
  const reportedStuckLoading = new WeakSet;
2187
+ const loadingIndicatorSelector = `[aria-busy="true"], [role="progressbar"], [${BEACON_ATTRIBUTE.LOADING}]`;
2184
2188
  const isPersistentDeterminateProgress = (indicator) => indicator.getAttribute("role") === "progressbar" && indicator.hasAttribute("aria-valuenow") && indicator.getAttribute("aria-busy") !== "true" && !indicator.hasAttribute(BEACON_ATTRIBUTE.LOADING);
2189
+ const hasTrackedLoadingAncestor = (indicator) => {
2190
+ let ancestor = indicator.parentElement?.closest(loadingIndicatorSelector);
2191
+ while (ancestor !== null && ancestor !== undefined) {
2192
+ if (!isPersistentDeterminateProgress(ancestor) && !isScanExempt(ancestor) && !hasHiddenAncestor(ancestor)) {
2193
+ return true;
2194
+ }
2195
+ ancestor = ancestor.parentElement?.closest(loadingIndicatorSelector);
2196
+ }
2197
+ return false;
2198
+ };
2185
2199
  const loadingDeadlineMs = (indicator) => {
2186
2200
  const configured = indicator.getAttribute(BEACON_ATTRIBUTE.LOADING_TIMEOUT)?.trim();
2187
2201
  if (!configured)
@@ -2192,13 +2206,17 @@ var createBeacon = (options) => {
2192
2206
  const checkStuckLoading = () => {
2193
2207
  if (document.visibilityState === "hidden")
2194
2208
  return;
2195
- const indicators = document.querySelectorAll(`[aria-busy="true"], [role="progressbar"], [${BEACON_ATTRIBUTE.LOADING}]`);
2209
+ const indicators = document.querySelectorAll(loadingIndicatorSelector);
2196
2210
  const now = Date.now();
2197
2211
  for (const indicator of Array.from(indicators)) {
2198
2212
  if (isPersistentDeterminateProgress(indicator))
2199
2213
  continue;
2200
2214
  if (isScanExempt(indicator))
2201
2215
  continue;
2216
+ if (hasHiddenAncestor(indicator))
2217
+ continue;
2218
+ if (hasTrackedLoadingAncestor(indicator))
2219
+ continue;
2202
2220
  const rect = indicator.getBoundingClientRect();
2203
2221
  if (rect.width === 0 && rect.height === 0)
2204
2222
  continue;
@@ -3284,6 +3302,7 @@ var createBeacon = (options) => {
3284
3302
  construct(target, args) {
3285
3303
  const socket = Reflect.construct(target, args);
3286
3304
  const label = shortUrl(String(args[0]));
3305
+ const socketLifecycleGeneration = pageLifecycleGeneration;
3287
3306
  let applicationClose = false;
3288
3307
  const originalClose = socket.close.bind(socket);
3289
3308
  socket.close = (code, reason) => {
@@ -3291,7 +3310,8 @@ var createBeacon = (options) => {
3291
3310
  originalClose(code, reason);
3292
3311
  };
3293
3312
  socket.addEventListener("close", (event) => {
3294
- if (pageLifecycleEnding || applicationClose)
3313
+ const restoredLifecycleClose = pageRestoredAt !== undefined && socketLifecycleGeneration < pageLifecycleGeneration && Date.now() - pageRestoredAt <= RESTORED_SOCKET_CLOSE_GRACE_MS;
3314
+ if (pageLifecycleEnding || applicationClose || restoredLifecycleClose)
3295
3315
  return;
3296
3316
  if (signals.socketAbnormalCloses !== false && typeof CloseEvent !== "undefined" && event instanceof CloseEvent && !event.wasClean) {
3297
3317
  const abnormalKey = `${label}|${event.code}`;
@@ -3745,11 +3765,14 @@ var createBeacon = (options) => {
3745
3765
  cleanups.push(() => clearInterval(timer));
3746
3766
  const onPageHide = () => {
3747
3767
  pageLifecycleEnding = true;
3768
+ pageLifecycleGeneration += 1;
3769
+ pageRestoredAt = undefined;
3748
3770
  pendingNetworkFailures.delete("transport");
3749
3771
  flush(true);
3750
3772
  };
3751
- const onPageShow = () => {
3773
+ const onPageShow = (event) => {
3752
3774
  pageLifecycleEnding = false;
3775
+ pageRestoredAt = event.persisted ? Date.now() : undefined;
3753
3776
  };
3754
3777
  const onVisibilityChange = () => {
3755
3778
  if (document.visibilityState === "hidden")
@@ -3803,5 +3826,5 @@ export {
3803
3826
  BEACON_ATTRIBUTE
3804
3827
  };
3805
3828
 
3806
- //# debugId=F9CD9BC8D9B8849F64756E2164756E21
3829
+ //# debugId=031AAABEB97215B864756E2164756E21
3807
3830
  //# sourceMappingURL=index.js.map