@absolutejs/beacon 0.5.0 → 0.6.0

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/README.md CHANGED
@@ -70,7 +70,9 @@ beacon.captureMessage("checkout started", "info");
70
70
  - **Stable semantic grouping** — pass `groupingKey` for synthetic or provider
71
71
  failures whose stack or wording can move between releases. The matching
72
72
  `@absolutejs/errors` ingest service validates and hashes it server-side;
73
- clients never choose raw fingerprints.
73
+ clients never choose raw fingerprints. Beacon's built-in signals always add
74
+ a stable grouping key derived from the normalized route and semantic target,
75
+ excluding durations, counts, release ids, entity UUIDs, and collector stacks.
74
76
  - **Cause chains** — preserves nested `Error.cause` stacks and diagnostic fields
75
77
  in `extra.errorCauses`, including database driver error codes and details.
76
78
  - **Sampling + redaction** — `sampleRate`, a `beforeSend(event)` hook
@@ -81,7 +83,9 @@ beacon.captureMessage("checkout started", "info");
81
83
  it.
82
84
  - **Noise filtering** — known browser-host/scanner failures such as CefSharp's
83
85
  `Object Not Found Matching Id` rejection and confirmed Meta in-app-browser
84
- native-bridge injection failures are dropped by default
86
+ native-bridge injection failures are dropped by default. Known crawler and
87
+ security-scanner user agents are dropped before they can create synthetic UI,
88
+ service-worker, or transport issues
85
89
  (`filterKnownNoise: false` opts out).
86
90
  - **Resource policy** — `instrument.resourceErrors` accepts a predicate so
87
91
  expected failures such as optional cross-origin images can become grouped
@@ -111,8 +115,9 @@ beacon.captureMessage("checkout started", "info");
111
115
  child painting past a non-scrolling parent (the flex-squeeze cutoff), and
112
116
  content cut by `overflow: hidden` without an ellipsis treatment. Issues
113
117
  group per element, kind, and viewport bucket (`xs/sm/md/lg/xl`), with the
114
- spill size in tags. Subtrees of scroll containers and absolutely positioned
115
- escapees (badges, popovers, drawers) are skipped by design; mark deliberate
118
+ spill size in tags. Hidden/off-canvas subtrees, icon-font glyph paint bounds,
119
+ scroll containers, and absolutely positioned escapees (badges, popovers,
120
+ drawers) are skipped by design; mark deliberate
116
121
  bleeds with `data-beacon-overflow="allow"`.
117
122
  - **Ambient watchdogs** — silent failures users abandon instead of reporting
118
123
  become warning issues: scroll jail (a leaked modal scroll lock), stuck
@@ -128,6 +133,9 @@ beacon.captureMessage("checkout started", "info");
128
133
  frustration (identical resubmits / repeated native-validation failures).
129
134
  Each is individually toggleable on `signals`, deduped, capped, and exempts
130
135
  `data-beacon-scan="allow"` subtrees where a DOM scan is involved.
136
+ Reload loops require repeated loads of the same normalized route; ordinary
137
+ navigation across several pages does not qualify. Occlusion scans exclude
138
+ hidden, inert, transparent, and pointer-disabled control subtrees.
131
139
  - **Theme and loading contracts** — mark an application boundary with
132
140
  `data-beacon-theme="adaptive"` to report large opaque surfaces whose
133
141
  luminance polarity contradicts the active light/dark mode. Intentional
package/dist/index.js CHANGED
@@ -315,8 +315,9 @@ var META_IOS_WEBKIT_BRIDGE_FAILURE = "TypeError: undefined is not an object (eva
315
315
  var isInstagramIosBridgeInjection = (event, userAgent) => INSTAGRAM_IOS_IN_APP_BROWSER.test(userAgent) && event.message === META_IOS_WEBKIT_BRIDGE_FAILURE && event.stack?.includes("sendDataToNative") === true && event.stack.includes("sendPageHideMessage");
316
316
  var FACEBOOK_ANDROID_DETACHED_BRIDGE_MESSAGE = "Error invoking postMessage: Java object is gone";
317
317
  var FACEBOOK_ANDROID_PERFORMANCE_LOGGER = "iabjs://navigation_performance_logger_android";
318
+ var KNOWN_CRAWLER_USER_AGENT = /(?:AdsBot-Google|Googlebot|bingbot|Baiduspider|YandexBot|DuckDuckBot|Applebot|Bytespider|PetalBot|SemrushBot|AhrefsBot|DotBot|MJ12bot|GPTBot|ClaudeBot|PerplexityBot|Google-NotebookLM|BitSightBot|Dataprovider\.com)/i;
318
319
  var browserUserAgent = () => typeof navigator === "undefined" ? "" : navigator.userAgent;
319
- var isKnownBeaconNoise = (event, userAgent = browserUserAgent()) => event.name === "UnhandledRejection" && CEF_SHARP_REJECTION.test(event.message) || FACEBOOK_IOS_IN_APP_BROWSER.test(userAgent) && FACEBOOK_IOS_HOST_INJECTION.has(event.message) || isInstagramIosBridgeInjection(event, userAgent) || event.name === "Error" && event.message === FACEBOOK_ANDROID_DETACHED_BRIDGE_MESSAGE && event.tags?.errorFilename === FACEBOOK_ANDROID_PERFORMANCE_LOGGER && event.stack?.includes(FACEBOOK_ANDROID_PERFORMANCE_LOGGER) === true;
320
+ var isKnownBeaconNoise = (event, userAgent = browserUserAgent()) => KNOWN_CRAWLER_USER_AGENT.test(userAgent) || event.name === "UnhandledRejection" && CEF_SHARP_REJECTION.test(event.message) || FACEBOOK_IOS_IN_APP_BROWSER.test(userAgent) && FACEBOOK_IOS_HOST_INJECTION.has(event.message) || isInstagramIosBridgeInjection(event, userAgent) || event.name === "Error" && event.message === FACEBOOK_ANDROID_DETACHED_BRIDGE_MESSAGE && event.tags?.errorFilename === FACEBOOK_ANDROID_PERFORMANCE_LOGGER && event.stack?.includes(FACEBOOK_ANDROID_PERFORMANCE_LOGGER) === true;
320
321
  var errorWithStack = (name, message, location2) => {
321
322
  const error = new Error(message);
322
323
  error.name = name;
@@ -415,6 +416,48 @@ var shortUrl = (url) => {
415
416
  return url.slice(0, SHORT_URL_MAX);
416
417
  }
417
418
  };
419
+ var UUID_PATH_SEGMENT = /\b[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\b/giu;
420
+ var LONG_IDENTIFIER_SEGMENT = /\b(?:[0-9a-f]{16,}|\d{8,})\b/giu;
421
+ var VOLATILE_SIGNAL_TAGS = new Set([
422
+ "actionId",
423
+ "closeCount",
424
+ "currentRelease",
425
+ "durationMs",
426
+ "elapsedMs",
427
+ "errorCount",
428
+ "interactionId",
429
+ "loadCount",
430
+ "newestRelease",
431
+ "obscuredPx",
432
+ "responseMs",
433
+ "shiftValue",
434
+ "signal",
435
+ "spillPx",
436
+ "stallCount",
437
+ "thresholdMs",
438
+ "userAgent",
439
+ "viewportHeight",
440
+ "viewportWidth",
441
+ "windowMs"
442
+ ]);
443
+ var normalizeSignalIdentityPart = (value) => value.replace(UUID_PATH_SEGMENT, ":id").replace(LONG_IDENTIFIER_SEGMENT, ":id").slice(0, SIGNAL_IDENTITY_PART_MAX);
444
+ var SIGNAL_IDENTITY_PART_MAX = 160;
445
+ var stableIdentityHash = (value, seed) => {
446
+ let hash = seed;
447
+ for (let index = 0;index < value.length; index += 1) {
448
+ hash ^= value.charCodeAt(index);
449
+ hash = Math.imul(hash, 16777619);
450
+ }
451
+ return (hash >>> 0).toString(16).padStart(8, "0");
452
+ };
453
+ var signalGroupingKey = (signalTags) => {
454
+ const identity = [
455
+ `route=${normalizeSignalIdentityPart(shortUrl(location.href))}`,
456
+ ...Object.entries(signalTags).filter(([key]) => !VOLATILE_SIGNAL_TAGS.has(key)).sort(([left], [right]) => left.localeCompare(right)).map(([key, value]) => `${key}=${normalizeSignalIdentityPart(String(value))}`)
457
+ ].join("|");
458
+ const hash = stableIdentityHash(identity, 2166136261) + stableIdentityHash(identity, 2654435769);
459
+ return `beacon-signal:${signalTags.signal}:${hash}`;
460
+ };
418
461
  var isInvisibleAnchor = (anchor) => {
419
462
  if (anchor.target === "_blank" || anchor.hasAttribute("download"))
420
463
  return true;
@@ -646,7 +689,7 @@ var createBeacon = (options) => {
646
689
  const MAIN_THREAD_STALL_DEFAULT_WINDOW_MS = 1e4;
647
690
  const RELOAD_LOOP_COUNT = 4;
648
691
  const RELOAD_LOOP_WINDOW_MS = 60000;
649
- const RELOAD_LOOP_STORAGE_KEY = "beacon:reload-times";
692
+ const RELOAD_LOOP_STORAGE_KEY = "beacon:reload-history-v2";
650
693
  const STALE_RELEASE_STORAGE_KEY = "beacon:release-first-seen";
651
694
  const STALE_RELEASE_GRACE_MS = 600000;
652
695
  const STALE_RELEASE_HISTORY_LIMIT = 5;
@@ -896,6 +939,7 @@ var createBeacon = (options) => {
896
939
  `);
897
940
  }
898
941
  captureException(error, {
942
+ groupingKey: signalGroupingKey(signalTags),
899
943
  level: "warning",
900
944
  tags: signalTags,
901
945
  ...traceId !== undefined ? { traceId } : {},
@@ -1354,11 +1398,13 @@ var createBeacon = (options) => {
1354
1398
  visit(child);
1355
1399
  };
1356
1400
  visit(navigation.notRestoredReasons);
1357
- const reasonList = [...reasons].slice(0, 10);
1358
- emitSignal(`Back-forward cache blocked — ${reasonList.join(", ") || "unknown reason"} — ${shortUrl(location.href)}`, {
1359
- reasons: reasonList.join(",") || "unknown",
1360
- signal: BEACON_SIGNAL.BFCACHE_BLOCKED
1361
- });
1401
+ const reasonList = [...reasons].filter((reason) => reason !== "masked").slice(0, 10);
1402
+ if (reasonList.length > 0) {
1403
+ emitSignal(`Back-forward cache blocked — ${reasonList.join(", ")} — ${shortUrl(location.href)}`, {
1404
+ reasons: reasonList.join(","),
1405
+ signal: BEACON_SIGNAL.BFCACHE_BLOCKED
1406
+ });
1407
+ }
1362
1408
  }
1363
1409
  }
1364
1410
  }
@@ -1647,6 +1693,21 @@ var createBeacon = (options) => {
1647
1693
  return "xl";
1648
1694
  };
1649
1695
  const isScanExempt = (element) => element.closest(`[${BEACON_ATTRIBUTE.SCAN}="allow"]`) !== null;
1696
+ const hasHiddenAncestor = (element, requirePointerEvents = false) => {
1697
+ let current = element;
1698
+ while (current !== null) {
1699
+ if (current.hasAttribute("hidden") || current.hasAttribute("inert") || current.getAttribute("aria-hidden") === "true") {
1700
+ return true;
1701
+ }
1702
+ const style = window.getComputedStyle(current);
1703
+ if (style.display === "none" || style.visibility === "hidden" || style.visibility === "collapse" || Number.parseFloat(style.opacity || "1") <= 0.01 || requirePointerEvents && style.pointerEvents === "none") {
1704
+ return true;
1705
+ }
1706
+ current = current.parentElement;
1707
+ }
1708
+ return false;
1709
+ };
1710
+ const isMaterialIconGlyph = (element) => [...element.classList].some((name) => name === "material-icons" || name.startsWith("material-symbols"));
1650
1711
  const seenScanIssues = new Set;
1651
1712
  let scanIssueReports = 0;
1652
1713
  const SCAN_ISSUE_MAX_REPORTS = 10;
@@ -1694,13 +1755,16 @@ var createBeacon = (options) => {
1694
1755
  if (element.getAttribute(BEACON_ATTRIBUTE.OVERFLOW) === "allow")
1695
1756
  return;
1696
1757
  const style = window.getComputedStyle(element);
1697
- if (style.display === "none" || style.visibility === "hidden")
1758
+ if (hasHiddenAncestor(element))
1698
1759
  return;
1699
1760
  const rect = element.getBoundingClientRect();
1700
1761
  if (rect.width === 0 && rect.height === 0)
1701
1762
  return;
1763
+ if ((style.position === "absolute" || style.position === "fixed") && (rect.right <= 0 || rect.left >= viewportRight || rect.bottom <= 0 || rect.top >= document.documentElement.clientHeight)) {
1764
+ return;
1765
+ }
1702
1766
  const inFlow = style.position !== "absolute" && style.position !== "fixed";
1703
- if (inFlow) {
1767
+ if (inFlow && !isMaterialIconGlyph(element)) {
1704
1768
  const viewportSpill = Math.max(rect.right - viewportRight, -rect.left);
1705
1769
  if (viewportSpill > LAYOUT_OVERFLOW_VIEWPORT_TOLERANCE_PX) {
1706
1770
  reportOverflow(element, "viewport", "spills past the viewport edge", viewportSpill);
@@ -1742,7 +1806,7 @@ var createBeacon = (options) => {
1742
1806
  for (const control of Array.from(controls)) {
1743
1807
  if (sampled >= OCCLUSION_SAMPLE_LIMIT)
1744
1808
  return;
1745
- if (isScanExempt(control))
1809
+ if (isScanExempt(control) || hasHiddenAncestor(control, true))
1746
1810
  continue;
1747
1811
  const rect = control.getBoundingClientRect();
1748
1812
  if (rect.width === 0 || rect.height === 0)
@@ -2118,17 +2182,17 @@ var createBeacon = (options) => {
2118
2182
  const observer = new PerformanceObserver((list) => {
2119
2183
  for (const raw of list.getEntries()) {
2120
2184
  const entry = raw;
2121
- if (entry.duration < minimum)
2185
+ if (entry.duration < minimum || entry.interactionId === undefined || entry.interactionId <= 0)
2122
2186
  continue;
2123
2187
  const target = entry.target instanceof Element ? describeElement(entry.target) : "unknown";
2124
- const key = entry.interactionId ?? `${entry.name}|${target}`;
2188
+ const key = entry.interactionId;
2125
2189
  if (reported.has(key))
2126
2190
  continue;
2127
2191
  reported.add(key);
2128
2192
  emitSignal(`Slow interaction — ${entry.name} blocked for ${Math.round(entry.duration)}ms — ${shortUrl(location.href)}`, {
2129
2193
  durationMs: String(Math.round(entry.duration)),
2130
2194
  eventType: entry.name,
2131
- ...entry.interactionId === undefined ? {} : { interactionId: String(entry.interactionId) },
2195
+ interactionId: String(entry.interactionId),
2132
2196
  signal: BEACON_SIGNAL.SLOW_INTERACTION,
2133
2197
  target
2134
2198
  });
@@ -2919,10 +2983,16 @@ var createBeacon = (options) => {
2919
2983
  construct(target, args) {
2920
2984
  const socket = Reflect.construct(target, args);
2921
2985
  const label = shortUrl(String(args[0]));
2986
+ let applicationClose = false;
2987
+ const originalClose = socket.close.bind(socket);
2988
+ socket.close = (code, reason) => {
2989
+ applicationClose = true;
2990
+ originalClose(code, reason);
2991
+ };
2922
2992
  socket.addEventListener("close", (event) => {
2923
- if (pageLifecycleEnding)
2993
+ if (pageLifecycleEnding || applicationClose)
2924
2994
  return;
2925
- if (signals.socketAbnormalCloses !== false && typeof CloseEvent !== "undefined" && event instanceof CloseEvent && (!event.wasClean || event.code !== 1000 && event.code !== 1001)) {
2995
+ if (signals.socketAbnormalCloses !== false && typeof CloseEvent !== "undefined" && event instanceof CloseEvent && !event.wasClean) {
2926
2996
  const abnormalKey = `${label}|${event.code}`;
2927
2997
  if (!reportedAbnormalCloses.has(abnormalKey)) {
2928
2998
  reportedAbnormalCloses.add(abnormalKey);
@@ -3125,17 +3195,22 @@ var createBeacon = (options) => {
3125
3195
  }
3126
3196
  if (signals !== null && signals.reloadLoops !== false && typeof sessionStorage !== "undefined") {
3127
3197
  try {
3128
- const now = Date.now();
3129
- const raw = sessionStorage.getItem(RELOAD_LOOP_STORAGE_KEY);
3130
- const parsed = raw === null ? [] : JSON.parse(raw);
3131
- const times = (Array.isArray(parsed) ? parsed : []).filter((at) => typeof at === "number" && now - at < RELOAD_LOOP_WINDOW_MS);
3132
- times.push(now);
3133
- sessionStorage.setItem(RELOAD_LOOP_STORAGE_KEY, JSON.stringify(times));
3134
- if (times.length >= RELOAD_LOOP_COUNT) {
3135
- emitSignal(`Reload loop — repeated page loads within a minute — ${shortUrl(location.href)}`, {
3136
- loadCount: String(times.length),
3137
- signal: BEACON_SIGNAL.RELOAD_LOOP
3138
- });
3198
+ const navigation = performance.getEntriesByType("navigation")[0];
3199
+ if (navigation?.type !== "back_forward") {
3200
+ const now = Date.now();
3201
+ const route = normalizeSignalIdentityPart(shortUrl(location.href));
3202
+ const raw = sessionStorage.getItem(RELOAD_LOOP_STORAGE_KEY);
3203
+ const parsed = raw === null ? [] : JSON.parse(raw);
3204
+ const 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);
3205
+ history2.push({ at: now, route });
3206
+ sessionStorage.setItem(RELOAD_LOOP_STORAGE_KEY, JSON.stringify(history2));
3207
+ const routeLoads = history2.filter((entry) => entry.route === route);
3208
+ if (routeLoads.length >= RELOAD_LOOP_COUNT) {
3209
+ emitSignal(`Reload loop — repeated page loads within a minute — ${shortUrl(location.href)}`, {
3210
+ loadCount: String(routeLoads.length),
3211
+ signal: BEACON_SIGNAL.RELOAD_LOOP
3212
+ });
3213
+ }
3139
3214
  }
3140
3215
  } catch {}
3141
3216
  }
@@ -3427,5 +3502,5 @@ export {
3427
3502
  BEACON_ATTRIBUTE
3428
3503
  };
3429
3504
 
3430
- //# debugId=3F33DA64F851A28864756E2164756E21
3505
+ //# debugId=76E798F97A6224E464756E2164756E21
3431
3506
  //# sourceMappingURL=index.js.map