@absolutejs/beacon 0.6.55 → 0.6.57

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
@@ -146,7 +146,8 @@ beacon.captureMessage("checkout started", "info");
146
146
  stalled `EventSource` streams, WebSocket connect/close flapping, request
147
147
  storms (one endpoint hammered in seconds), reload loops, stale releases (a
148
148
  service worker serving a build older than one this browser already ran),
149
- font-face load failures, focus dropped to `<body>` when a dialog unmounts,
149
+ required font-face load failures (excluding intentional optional fallback),
150
+ focus dropped to `<body>` when a dialog unmounts,
150
151
  focus escaping or never entering an explicit modal, browser interventions,
151
152
  enforced CSP violations, repeated visible-page main-thread stalls, and form
152
153
  frustration (identical resubmits / repeated native-validation failures).
package/dist/index.d.ts CHANGED
@@ -107,7 +107,7 @@ export declare const BEACON_ATTRIBUTE: {
107
107
  /** Response header used to correlate a browser signal with its server request. */
108
108
  export declare const BEACON_TRACE_HEADER = "x-absolute-trace-id";
109
109
  /** Beacon package version retained with every captured event. */
110
- export declare const BEACON_SDK_VERSION = "0.6.55";
110
+ export declare const BEACON_SDK_VERSION = "0.6.57";
111
111
  /** Arbitrary event tags, with Beacon's reserved `signal` tag type-checked. */
112
112
  export type BeaconTags = Record<string, string> & {
113
113
  signal?: BeaconSignal;
package/dist/index.js CHANGED
@@ -76,7 +76,7 @@ var BEACON_ATTRIBUTE = {
76
76
  THEME: "data-beacon-theme"
77
77
  };
78
78
  var BEACON_TRACE_HEADER = "x-absolute-trace-id";
79
- var BEACON_SDK_VERSION = "0.6.55";
79
+ var BEACON_SDK_VERSION = "0.6.57";
80
80
  var inBrowser = () => typeof window !== "undefined";
81
81
  var newId = () => {
82
82
  if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
@@ -793,6 +793,7 @@ var createBeacon = (options) => {
793
793
  const NAVIGATION_INTENT_MAX_AGE_MS = 30000;
794
794
  const RELOAD_LOOP_STORAGE_KEY = "beacon:reload-history-v4";
795
795
  const NAVIGATION_INTENT_STORAGE_KEY = "beacon:navigation-intent-v1";
796
+ const SERVICE_WORKER_UPDATE_INTENT_STORAGE_KEY = "beacon:service-worker-update-intent-v1";
796
797
  const STALE_RELEASE_STORAGE_KEY = "beacon:release-first-seen";
797
798
  const STALE_RELEASE_GRACE_MS = 600000;
798
799
  const STALE_RELEASE_HISTORY_LIMIT = 5;
@@ -1086,7 +1087,7 @@ var createBeacon = (options) => {
1086
1087
  push(event);
1087
1088
  };
1088
1089
  const emitSignal = (message, signalTags, traceId, extra, stackBoundary, fallbackFramesToDrop = 1, useDefaultFingerprint = false) => {
1089
- if (staleClientRelease && signalTags.signal !== BEACON_SIGNAL.STALE_RELEASE)
1090
+ if (staleClientRelease && signalTags.signal !== BEACON_SIGNAL.STALE_RELEASE && signalTags.signal !== BEACON_SIGNAL.RELOAD_LOOP)
1090
1091
  return;
1091
1092
  const error = new Error(message);
1092
1093
  const captureStackTrace = Error.captureStackTrace;
@@ -1141,7 +1142,8 @@ var createBeacon = (options) => {
1141
1142
  return;
1142
1143
  staleClientRelease = true;
1143
1144
  for (let index = buffer.length - 1;index >= 0; index -= 1) {
1144
- if (buffer[index]?.tags?.signal !== undefined) {
1145
+ const signal = buffer[index]?.tags?.signal;
1146
+ if (signal !== undefined && signal !== BEACON_SIGNAL.RELOAD_LOOP) {
1145
1147
  buffer.splice(index, 1);
1146
1148
  }
1147
1149
  }
@@ -4055,6 +4057,15 @@ var createBeacon = (options) => {
4055
4057
  });
4056
4058
  } catch {}
4057
4059
  }
4060
+ if (typeof navigator.serviceWorker?.addEventListener === "function" && typeof sessionStorage !== "undefined") {
4061
+ const markServiceWorkerUpdate = () => {
4062
+ try {
4063
+ sessionStorage.setItem(SERVICE_WORKER_UPDATE_INTENT_STORAGE_KEY, String(Date.now()));
4064
+ } catch {}
4065
+ };
4066
+ navigator.serviceWorker.addEventListener("controllerchange", markServiceWorkerUpdate);
4067
+ cleanups.push(() => navigator.serviceWorker?.removeEventListener("controllerchange", markServiceWorkerUpdate));
4068
+ }
4058
4069
  if (signals !== null && signals.reloadLoops !== false && typeof sessionStorage !== "undefined") {
4059
4070
  try {
4060
4071
  const navigation = performance.getEntriesByType("navigation")[0];
@@ -4072,17 +4083,18 @@ var createBeacon = (options) => {
4072
4083
  history2 = [];
4073
4084
  entryKind = "intentional-navigation";
4074
4085
  }
4086
+ const rawServiceWorkerUpdateIntent = sessionStorage.getItem(SERVICE_WORKER_UPDATE_INTENT_STORAGE_KEY);
4087
+ sessionStorage.removeItem(SERVICE_WORKER_UPDATE_INTENT_STORAGE_KEY);
4088
+ const serviceWorkerUpdateIntentAt = Number(rawServiceWorkerUpdateIntent);
4089
+ if (rawServiceWorkerUpdateIntent !== null && Number.isFinite(serviceWorkerUpdateIntentAt) && now - serviceWorkerUpdateIntentAt >= 0 && now - serviceWorkerUpdateIntentAt <= NAVIGATION_INTENT_MAX_AGE_MS) {
4090
+ history2 = [];
4091
+ entryKind = "service-worker-update";
4092
+ }
4075
4093
  if (document.referrer !== "") {
4076
4094
  const referrer = new URL(document.referrer, location.href);
4077
4095
  if (referrer.origin !== location.origin) {
4078
4096
  history2 = [];
4079
4097
  entryKind = "external";
4080
- } else {
4081
- const controllerScript = navigator.serviceWorker?.controller?.scriptURL;
4082
- if (controllerScript !== undefined && new URL(controllerScript, location.href).pathname === referrer.pathname) {
4083
- history2 = [];
4084
- entryKind = "service-worker-update";
4085
- }
4086
4098
  }
4087
4099
  }
4088
4100
  history2.push({ at: now, route });
@@ -4096,12 +4108,16 @@ var createBeacon = (options) => {
4096
4108
  if (loadCount === RELOAD_LOOP_COUNT) {
4097
4109
  const firstLoad = history2.at(-loadCount)?.at ?? now;
4098
4110
  emitSignal(`Reload loop — repeated page loads within a minute — ${shortUrl(location.href)}`, {
4111
+ currentRelease: options.release ?? "unknown",
4099
4112
  entryKind,
4100
4113
  loadCount: String(loadCount),
4101
4114
  navigationType: navigation?.type ?? "unknown",
4115
+ serviceWorkerControlled: String(navigator.serviceWorker?.controller !== null && navigator.serviceWorker?.controller !== undefined),
4116
+ serviceWorkerScript: navigator.serviceWorker?.controller?.scriptURL ?? "none",
4102
4117
  signal: BEACON_SIGNAL.RELOAD_LOOP,
4103
4118
  windowMs: String(now - firstLoad)
4104
4119
  });
4120
+ flush(true);
4105
4121
  }
4106
4122
  }
4107
4123
  } catch {}
@@ -4137,7 +4153,8 @@ var createBeacon = (options) => {
4137
4153
  const reportedFonts = new Set;
4138
4154
  const checkingFonts = new Set;
4139
4155
  const confirmationMs = Math.max(0, signals.fontFailureConfirmMs ?? FONT_FAILURE_CONFIRM_DEFAULT_MS);
4140
- const normalizedFamily = (family) => family.trim().replace(/^(['"])(.*)\1$/u, "$2").toLowerCase();
4156
+ const canonicalFontFamily = (family) => family.trim().replace(/^(['"])(.*)\1$/u, "$2");
4157
+ const normalizedFamily = (family) => canonicalFontFamily(family).toLowerCase();
4141
4158
  const isRendered = (element) => {
4142
4159
  for (let current = element;current !== null; current = current.parentElement) {
4143
4160
  const style = window.getComputedStyle(current);
@@ -4161,9 +4178,10 @@ var createBeacon = (options) => {
4161
4178
  return null;
4162
4179
  };
4163
4180
  const reportFontFailure = (face, element, key) => {
4181
+ const family = canonicalFontFamily(face.family);
4164
4182
  reportedFonts.add(key);
4165
- emitSignal(`Font failure — ${face.family} failed to load — ${shortUrl(location.href)}`, {
4166
- fontFamily: face.family,
4183
+ emitSignal(`Font failure — ${family} failed to load — ${shortUrl(location.href)}`, {
4184
+ fontFamily: family,
4167
4185
  fontStretch: face.stretch,
4168
4186
  fontStyle: face.style,
4169
4187
  fontWeight: face.weight,
@@ -4172,16 +4190,19 @@ var createBeacon = (options) => {
4172
4190
  });
4173
4191
  };
4174
4192
  const verifyFontFailure = async (face) => {
4175
- const key = [face.family, face.style, face.weight, face.stretch].join("|");
4193
+ if (face.display === "optional")
4194
+ return;
4195
+ const family = canonicalFontFamily(face.family);
4196
+ const key = [family, face.style, face.weight, face.stretch].join("|");
4176
4197
  if (reportedFonts.has(key) || checkingFonts.has(key))
4177
4198
  return;
4178
- const element = affectedElement(face.family);
4199
+ const element = affectedElement(family);
4179
4200
  if (element === null)
4180
4201
  return;
4181
4202
  checkingFonts.add(key);
4182
4203
  const fontAvailable = async (consumer) => {
4183
4204
  const sample = consumer.textContent?.trim().slice(0, 64) || "BESbswy";
4184
- const font = `${face.style} ${face.weight} ${face.stretch} 16px ${JSON.stringify(face.family)}`;
4205
+ const font = `${face.style} ${face.weight} ${face.stretch} 16px ${JSON.stringify(family)}`;
4185
4206
  try {
4186
4207
  await document.fonts.load(font, sample);
4187
4208
  return document.fonts.check(font, sample);
@@ -4199,7 +4220,7 @@ var createBeacon = (options) => {
4199
4220
  });
4200
4221
  if (document.visibilityState === "hidden")
4201
4222
  return;
4202
- const confirmedElement = affectedElement(face.family);
4223
+ const confirmedElement = affectedElement(family);
4203
4224
  if (confirmedElement === null)
4204
4225
  return;
4205
4226
  if (await fontAvailable(confirmedElement))
@@ -4517,5 +4538,5 @@ export {
4517
4538
  BEACON_ATTRIBUTE
4518
4539
  };
4519
4540
 
4520
- //# debugId=11D74B10F3D1902364756E2164756E21
4541
+ //# debugId=B8C645D9177F5D9E64756E2164756E21
4521
4542
  //# sourceMappingURL=index.js.map