@absolutejs/beacon 0.6.14 → 0.6.16

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,27 @@ 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
+ "blockingDurationMs",
438
+ "blockerLocations",
439
+ "blockerScope",
423
440
  "closeCount",
424
441
  "currentRelease",
425
442
  "durationMs",
@@ -1437,24 +1454,40 @@ var createBeacon = (options) => {
1437
1454
  const navigation = performance.getEntriesByType("navigation")[0];
1438
1455
  if (navigation?.type === "back_forward" && navigation.notRestoredReasons != null) {
1439
1456
  const reasons = new Set;
1440
- const visit = (node) => {
1457
+ const blockers = [];
1458
+ const visit = (node, depth = 0) => {
1441
1459
  if (node === null || typeof node !== "object")
1442
1460
  return;
1443
1461
  const detail = node;
1444
- for (const reason of detail.reasons ?? []) {
1445
- if (typeof reason.reason === "string")
1446
- reasons.add(reason.reason);
1462
+ const nodeReasons = (detail.reasons ?? []).map((reason) => reason.reason).filter((reason) => typeof reason === "string" && reason !== "masked").slice(0, 10);
1463
+ for (const reason of nodeReasons)
1464
+ reasons.add(reason);
1465
+ if (nodeReasons.length > 0 && blockers.length < 10) {
1466
+ const location2 = bfcacheLocation(detail.url ?? detail.src);
1467
+ blockers.push({
1468
+ depth,
1469
+ ...location2 === undefined ? {} : { location: location2 },
1470
+ reasons: nodeReasons
1471
+ });
1447
1472
  }
1448
1473
  for (const child of detail.children ?? [])
1449
- visit(child);
1474
+ visit(child, depth + 1);
1450
1475
  };
1451
1476
  visit(navigation.notRestoredReasons);
1452
- const reasonList = [...reasons].filter((reason) => reason !== "masked").slice(0, 10);
1477
+ const reasonList = [...reasons].slice(0, 10);
1453
1478
  if (reasonList.length > 0) {
1479
+ const hasTopDocumentBlocker = blockers.some((blocker) => blocker.depth === 0);
1480
+ const hasChildFrameBlocker = blockers.some((blocker) => blocker.depth > 0);
1481
+ const blockerScope = hasTopDocumentBlocker && hasChildFrameBlocker ? "mixed" : hasChildFrameBlocker ? "child-frame" : "top-document";
1482
+ const blockerLocations = [
1483
+ ...new Set(blockers.map((blocker) => blocker.location).filter((value) => value !== undefined))
1484
+ ].slice(0, 10);
1454
1485
  emitSignal(`Back-forward cache blocked — ${reasonList.join(", ")} — ${shortUrl(location.href)}`, {
1486
+ ...blockerLocations.length === 0 ? {} : { blockerLocations: blockerLocations.join(",") },
1487
+ blockerScope,
1455
1488
  reasons: reasonList.join(","),
1456
1489
  signal: BEACON_SIGNAL.BFCACHE_BLOCKED
1457
- });
1490
+ }, undefined, { bfcacheBlockers: blockers });
1458
1491
  }
1459
1492
  }
1460
1493
  }
@@ -3755,5 +3788,5 @@ export {
3755
3788
  BEACON_ATTRIBUTE
3756
3789
  };
3757
3790
 
3758
- //# debugId=E73AD95316DDFA6564756E2164756E21
3791
+ //# debugId=94068FA641D0D33A64756E2164756E21
3759
3792
  //# sourceMappingURL=index.js.map