@absolutejs/beacon 0.6.13 → 0.6.15

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
@@ -416,10 +416,26 @@ var shortUrl = (url) => {
416
416
  return url.slice(0, SHORT_URL_MAX);
417
417
  }
418
418
  };
419
+ var BFCACHE_LOCATION_MAX = 240;
420
+ var bfcacheLocation = (value) => {
421
+ if (typeof value !== "string" || value === "")
422
+ return;
423
+ try {
424
+ const parsed = new URL(value, location.href);
425
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
426
+ return;
427
+ }
428
+ return `${parsed.origin}${normalizeSignalIdentityPart(parsed.pathname)}`.slice(0, BFCACHE_LOCATION_MAX);
429
+ } catch {
430
+ return;
431
+ }
432
+ };
419
433
  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
434
  var LONG_IDENTIFIER_SEGMENT = /\b(?:[0-9a-f]{16,}|\d{8,})\b/giu;
421
435
  var VOLATILE_SIGNAL_TAGS = new Set([
422
436
  "actionId",
437
+ "blockerLocations",
438
+ "blockerScope",
423
439
  "closeCount",
424
440
  "currentRelease",
425
441
  "durationMs",
@@ -714,6 +730,8 @@ var createBeacon = (options) => {
714
730
  const FORM_FRUSTRATION_THRESHOLD = 3;
715
731
  const FORM_FRUSTRATION_WINDOW_MS = 60000;
716
732
  const LAYOUT_SHIFT_RECENT_INTERACTION_MS = 500;
733
+ const LAYOUT_SHIFT_VIEWPORT_RESIZE_SETTLE_MS = 500;
734
+ const VIEWPORT_RESIZE_HISTORY_LIMIT = 8;
717
735
  const FORM_INVALID_BURST_GAP_MS = 100;
718
736
  const SIGNAL_TEXT_MAX = 180;
719
737
  const NON_TEXT_ENTRY_INPUT_TYPES = new Set([
@@ -1435,24 +1453,40 @@ var createBeacon = (options) => {
1435
1453
  const navigation = performance.getEntriesByType("navigation")[0];
1436
1454
  if (navigation?.type === "back_forward" && navigation.notRestoredReasons != null) {
1437
1455
  const reasons = new Set;
1438
- const visit = (node) => {
1456
+ const blockers = [];
1457
+ const visit = (node, depth = 0) => {
1439
1458
  if (node === null || typeof node !== "object")
1440
1459
  return;
1441
1460
  const detail = node;
1442
- for (const reason of detail.reasons ?? []) {
1443
- if (typeof reason.reason === "string")
1444
- reasons.add(reason.reason);
1461
+ const nodeReasons = (detail.reasons ?? []).map((reason) => reason.reason).filter((reason) => typeof reason === "string" && reason !== "masked").slice(0, 10);
1462
+ for (const reason of nodeReasons)
1463
+ reasons.add(reason);
1464
+ if (nodeReasons.length > 0 && blockers.length < 10) {
1465
+ const location2 = bfcacheLocation(detail.url ?? detail.src);
1466
+ blockers.push({
1467
+ depth,
1468
+ ...location2 === undefined ? {} : { location: location2 },
1469
+ reasons: nodeReasons
1470
+ });
1445
1471
  }
1446
1472
  for (const child of detail.children ?? [])
1447
- visit(child);
1473
+ visit(child, depth + 1);
1448
1474
  };
1449
1475
  visit(navigation.notRestoredReasons);
1450
- const reasonList = [...reasons].filter((reason) => reason !== "masked").slice(0, 10);
1476
+ const reasonList = [...reasons].slice(0, 10);
1451
1477
  if (reasonList.length > 0) {
1478
+ const hasTopDocumentBlocker = blockers.some((blocker) => blocker.depth === 0);
1479
+ const hasChildFrameBlocker = blockers.some((blocker) => blocker.depth > 0);
1480
+ const blockerScope = hasTopDocumentBlocker && hasChildFrameBlocker ? "mixed" : hasChildFrameBlocker ? "child-frame" : "top-document";
1481
+ const blockerLocations = [
1482
+ ...new Set(blockers.map((blocker) => blocker.location).filter((value) => value !== undefined))
1483
+ ].slice(0, 10);
1452
1484
  emitSignal(`Back-forward cache blocked — ${reasonList.join(", ")} — ${shortUrl(location.href)}`, {
1485
+ ...blockerLocations.length === 0 ? {} : { blockerLocations: blockerLocations.join(",") },
1486
+ blockerScope,
1453
1487
  reasons: reasonList.join(","),
1454
1488
  signal: BEACON_SIGNAL.BFCACHE_BLOCKED
1455
- });
1489
+ }, undefined, { bfcacheBlockers: blockers });
1456
1490
  }
1457
1491
  }
1458
1492
  }
@@ -2241,13 +2275,26 @@ var createBeacon = (options) => {
2241
2275
  if (signals !== null && signals.disruptiveLayoutShifts !== false && typeof PerformanceObserver !== "undefined") {
2242
2276
  const minimum = signals.disruptiveLayoutShiftMin ?? DISRUPTIVE_LAYOUT_SHIFT_DEFAULT_MIN;
2243
2277
  const reported = new Set;
2278
+ let viewportResizeTimes = [];
2279
+ const recordViewportResize = () => {
2280
+ viewportResizeTimes.push(performance.now());
2281
+ if (viewportResizeTimes.length > VIEWPORT_RESIZE_HISTORY_LIMIT) {
2282
+ viewportResizeTimes = viewportResizeTimes.slice(-VIEWPORT_RESIZE_HISTORY_LIMIT);
2283
+ }
2284
+ };
2285
+ window.addEventListener("resize", recordViewportResize);
2286
+ window.visualViewport?.addEventListener("resize", recordViewportResize);
2244
2287
  try {
2245
2288
  const observer = new PerformanceObserver((list) => {
2246
2289
  for (const raw of list.getEntries()) {
2247
2290
  const entry = raw;
2248
2291
  const interactionAgeMs = recentInteraction === undefined ? undefined : entry.startTime - recentInteraction.performanceAt;
2249
2292
  const beaconSawRecentInput = interactionAgeMs !== undefined && interactionAgeMs >= 0 && interactionAgeMs <= LAYOUT_SHIFT_RECENT_INTERACTION_MS;
2250
- if (entry.hadRecentInput === true || beaconSawRecentInput || mobileKeyboardViewportActive() || (entry.value ?? 0) < minimum)
2293
+ const resizeAdjacent = viewportResizeTimes.some((resizedAt) => {
2294
+ const resizeAgeMs = entry.startTime - resizedAt;
2295
+ return resizeAgeMs >= 0 && resizeAgeMs <= LAYOUT_SHIFT_VIEWPORT_RESIZE_SETTLE_MS;
2296
+ });
2297
+ if (entry.hadRecentInput === true || beaconSawRecentInput || resizeAdjacent || mobileKeyboardViewportActive() || (entry.value ?? 0) < minimum)
2251
2298
  continue;
2252
2299
  const targets = (entry.sources ?? []).map(({ node }) => node instanceof Element ? describeElement(node) : undefined).filter((target) => target !== undefined).slice(0, 5);
2253
2300
  const key = targets.join(",") || "unknown";
@@ -2262,8 +2309,15 @@ var createBeacon = (options) => {
2262
2309
  }
2263
2310
  });
2264
2311
  observer.observe({ buffered: true, type: "layout-shift" });
2265
- cleanups.push(() => observer.disconnect());
2266
- } catch {}
2312
+ cleanups.push(() => {
2313
+ observer.disconnect();
2314
+ window.removeEventListener("resize", recordViewportResize);
2315
+ window.visualViewport?.removeEventListener("resize", recordViewportResize);
2316
+ });
2317
+ } catch {
2318
+ window.removeEventListener("resize", recordViewportResize);
2319
+ window.visualViewport?.removeEventListener("resize", recordViewportResize);
2320
+ }
2267
2321
  }
2268
2322
  if (signals !== null && signals.slowInteractions !== false && typeof PerformanceObserver !== "undefined") {
2269
2323
  const minimum = signals.slowInteractionMs ?? SLOW_INTERACTION_DEFAULT_MS;
@@ -3733,5 +3787,5 @@ export {
3733
3787
  BEACON_ATTRIBUTE
3734
3788
  };
3735
3789
 
3736
- //# debugId=67D5901DFC5C25F064756E2164756E21
3790
+ //# debugId=DFFE57CC9874C7F464756E2164756E21
3737
3791
  //# sourceMappingURL=index.js.map