@absolutejs/beacon 0.6.8 → 0.6.10

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
@@ -165,9 +165,10 @@ beacon.captureMessage("checkout started", "info");
165
165
  become replay-linked warnings. Normal socket closes, page teardown, hidden-tab
166
166
  SSE errors, and successfully replaced service workers are exempt.
167
167
  - **Attributed reliability signals** — Event Timing identifies genuinely slow
168
- interactions (without treating an ordinary click timer as latency), Layout
169
- Instability names shifted elements, and long animation frames include their
170
- worst script when the browser exposes it. Successful HTTP responses can be
168
+ interactions and separates input delay, handler time, and presentation delay.
169
+ Overlapping long animation frames include their worst script when the browser
170
+ exposes it; missing browser attribution is labeled explicitly. Layout
171
+ Instability names shifted elements. Successful HTTP responses can be
171
172
  classified through the host-owned `instrument.classifyResponse` callback for
172
173
  GraphQL-style errors without Beacon retaining response bodies.
173
174
  - **Lifecycle and platform gaps** — marked empty application roots, marked dirty
package/dist/index.d.ts CHANGED
@@ -475,7 +475,7 @@ export type WebVital = {
475
475
  at: number;
476
476
  /** Optional deployment environment copied from the Beacon configuration. */
477
477
  environment?: string;
478
- /** The 5 Core Web Vitals, plus TBT (Total Blocking Time — long-task overage). */
478
+ /** The 5 Core Web Vitals, plus TBT measured for 10 seconds from FCP. */
479
479
  name: "LCP" | "INP" | "CLS" | "FCP" | "TTFB" | "TBT";
480
480
  /** Metric value (ms for LCP/INP/FCP/TTFB; unitless for CLS). */
481
481
  value: number;
package/dist/index.js CHANGED
@@ -514,29 +514,45 @@ var formStateChanged = (snapshot) => {
514
514
  };
515
515
  var VITAL_NAMES = new Set(["LCP", "INP", "CLS", "FCP", "TTFB", "TBT"]);
516
516
  var LONG_TASK_MS = 50;
517
+ var TBT_WINDOW_MS = 1e4;
517
518
  var TBT_GOOD_MS = 200;
518
519
  var TBT_POOR_MS = 600;
519
520
  var observeLongTasks = (report, navigationType) => {
520
521
  if (typeof PerformanceObserver === "undefined")
521
522
  return;
522
- let totalBlockingMs = 0;
523
- let count = 0;
523
+ const longTasks = [];
524
524
  let reported = false;
525
525
  try {
526
526
  const observer = new PerformanceObserver((list) => {
527
+ const windowStart = performance.getEntriesByName("first-contentful-paint")[0]?.startTime ?? 0;
528
+ const windowEnd = windowStart + TBT_WINDOW_MS;
527
529
  for (const entry of list.getEntries()) {
528
- totalBlockingMs += Math.max(0, entry.duration - LONG_TASK_MS);
529
- count += 1;
530
+ if (entry.startTime < windowStart || entry.startTime >= windowEnd)
531
+ continue;
532
+ longTasks.push({
533
+ duration: entry.duration,
534
+ startTime: entry.startTime
535
+ });
530
536
  }
531
537
  });
532
538
  observer.observe({ buffered: true, type: "longtask" });
533
539
  const flush = () => {
534
- if (reported || count === 0)
540
+ if (reported)
541
+ return;
542
+ const firstContentfulPaint = performance.getEntriesByName("first-contentful-paint")[0]?.startTime;
543
+ const windowStart = firstContentfulPaint ?? 0;
544
+ const windowEnd = windowStart + TBT_WINDOW_MS;
545
+ const tasksInWindow = longTasks.filter(({ startTime }) => startTime >= windowStart && startTime < windowEnd);
546
+ if (tasksInWindow.length === 0)
535
547
  return;
536
548
  reported = true;
537
- const value = Math.round(totalBlockingMs);
549
+ const value = Math.round(tasksInWindow.reduce((total, { duration }) => total + Math.max(0, duration - LONG_TASK_MS), 0));
538
550
  report({
539
- id: `tbt-${navigationType}-${value}`,
551
+ attribution: {
552
+ measurementWindow: firstContentfulPaint === undefined ? "navigation" : "FCP",
553
+ measurementWindowMs: TBT_WINDOW_MS
554
+ },
555
+ id: `tbt-${navigationType}-${TBT_WINDOW_MS}-${value}`,
540
556
  name: "TBT",
541
557
  navigationType,
542
558
  rating: value <= TBT_GOOD_MS ? "good" : value >= TBT_POOR_MS ? "poor" : "needs-improvement",
@@ -563,6 +579,8 @@ var vitalAttribution = (value) => {
563
579
  "largestShiftTarget",
564
580
  "largestShiftValue",
565
581
  "loadState",
582
+ "measurementWindow",
583
+ "measurementWindowMs",
566
584
  "presentationDelay",
567
585
  "processingDuration",
568
586
  "resourceLoadDelay",
@@ -695,6 +713,7 @@ var createBeacon = (options) => {
695
713
  const STALE_RELEASE_HISTORY_LIMIT = 5;
696
714
  const FORM_FRUSTRATION_THRESHOLD = 3;
697
715
  const FORM_FRUSTRATION_WINDOW_MS = 60000;
716
+ const LAYOUT_SHIFT_RECENT_INTERACTION_MS = 500;
698
717
  const FORM_INVALID_BURST_GAP_MS = 100;
699
718
  const SIGNAL_TEXT_MAX = 180;
700
719
  const slowResponseMs = signals?.slowResponseMs ?? SLOW_RESPONSE_DEFAULT_MS;
@@ -1593,6 +1612,7 @@ var createBeacon = (options) => {
1593
1612
  return;
1594
1613
  recentInteraction = {
1595
1614
  at: Date.now(),
1615
+ performanceAt: performance.now(),
1596
1616
  target: targetName,
1597
1617
  type: "click"
1598
1618
  };
@@ -1645,6 +1665,7 @@ var createBeacon = (options) => {
1645
1665
  beginAction("submit", target);
1646
1666
  recentInteraction = {
1647
1667
  at: Date.now(),
1668
+ performanceAt: performance.now(),
1648
1669
  target,
1649
1670
  type: "submit"
1650
1671
  };
@@ -1659,6 +1680,7 @@ var createBeacon = (options) => {
1659
1680
  beginAction("keyboard", targetName);
1660
1681
  recentInteraction = {
1661
1682
  at: Date.now(),
1683
+ performanceAt: performance.now(),
1662
1684
  target: targetName,
1663
1685
  type: "keyboard"
1664
1686
  };
@@ -2196,7 +2218,9 @@ var createBeacon = (options) => {
2196
2218
  const observer = new PerformanceObserver((list) => {
2197
2219
  for (const raw of list.getEntries()) {
2198
2220
  const entry = raw;
2199
- if (entry.hadRecentInput === true || (entry.value ?? 0) < minimum)
2221
+ const interactionAgeMs = recentInteraction === undefined ? undefined : entry.startTime - recentInteraction.performanceAt;
2222
+ const beaconSawRecentInput = interactionAgeMs !== undefined && interactionAgeMs >= 0 && interactionAgeMs <= LAYOUT_SHIFT_RECENT_INTERACTION_MS;
2223
+ if (entry.hadRecentInput === true || beaconSawRecentInput || (entry.value ?? 0) < minimum)
2200
2224
  continue;
2201
2225
  const targets = (entry.sources ?? []).map(({ node }) => node instanceof Element ? describeElement(node) : undefined).filter((target) => target !== undefined).slice(0, 5);
2202
2226
  const key = targets.join(",") || "unknown";
@@ -2217,6 +2241,42 @@ var createBeacon = (options) => {
2217
2241
  if (signals !== null && signals.slowInteractions !== false && typeof PerformanceObserver !== "undefined") {
2218
2242
  const minimum = signals.slowInteractionMs ?? SLOW_INTERACTION_DEFAULT_MS;
2219
2243
  const reported = new Set;
2244
+ const blockingFrames = [];
2245
+ const recordBlockingFrames = (entries) => {
2246
+ for (const entry of entries)
2247
+ blockingFrames.push(entry);
2248
+ if (blockingFrames.length > 50)
2249
+ blockingFrames.splice(0, blockingFrames.length - 50);
2250
+ };
2251
+ let blockingObserver;
2252
+ try {
2253
+ blockingObserver = new PerformanceObserver((list) => {
2254
+ recordBlockingFrames(list.getEntries());
2255
+ });
2256
+ const supportedTypes = PerformanceObserver.supportedEntryTypes;
2257
+ if (supportedTypes?.includes("long-animation-frame")) {
2258
+ blockingObserver.observe({
2259
+ buffered: true,
2260
+ type: "long-animation-frame"
2261
+ });
2262
+ } else if (supportedTypes?.includes("longtask")) {
2263
+ blockingObserver.observe({ buffered: true, type: "longtask" });
2264
+ } else if (supportedTypes === undefined || supportedTypes.length === 0) {
2265
+ blockingObserver.observe({
2266
+ buffered: true,
2267
+ type: "long-animation-frame"
2268
+ });
2269
+ } else {
2270
+ blockingObserver.disconnect();
2271
+ blockingObserver = undefined;
2272
+ }
2273
+ if (blockingObserver !== undefined) {
2274
+ cleanups.push(() => blockingObserver?.disconnect());
2275
+ }
2276
+ } catch {
2277
+ blockingObserver?.disconnect();
2278
+ blockingObserver = undefined;
2279
+ }
2220
2280
  try {
2221
2281
  const observer = new PerformanceObserver((list) => {
2222
2282
  for (const raw of list.getEntries()) {
@@ -2228,10 +2288,34 @@ var createBeacon = (options) => {
2228
2288
  if (reported.has(key))
2229
2289
  continue;
2230
2290
  reported.add(key);
2231
- emitSignal(`Slow interaction — ${entry.name} blocked for ${Math.round(entry.duration)}ms — ${shortUrl(location.href)}`, {
2291
+ if (blockingObserver !== undefined) {
2292
+ recordBlockingFrames(blockingObserver.takeRecords());
2293
+ }
2294
+ const interactionEnd = entry.startTime + entry.duration;
2295
+ const overlappingFrame = blockingFrames.filter((frame) => frame.startTime < interactionEnd && frame.startTime + frame.duration > entry.startTime).sort((left, right) => {
2296
+ const leftBlocking = left.blockingDuration ?? Math.max(0, left.duration - LONG_TASK_MS);
2297
+ const rightBlocking = right.blockingDuration ?? Math.max(0, right.duration - LONG_TASK_MS);
2298
+ return rightBlocking - leftBlocking;
2299
+ })[0];
2300
+ const script = [...overlappingFrame?.scripts ?? []].sort((left, right) => (right.duration ?? 0) - (left.duration ?? 0))[0];
2301
+ const hasPhaseTiming = typeof entry.processingStart === "number" && typeof entry.processingEnd === "number";
2302
+ emitSignal(`Slow interaction — ${entry.name} took ${Math.round(entry.duration)}ms — ${shortUrl(location.href)}`, {
2303
+ ...hasPhaseTiming ? {
2304
+ inputDelayMs: String(Math.round(Math.max(0, entry.processingStart - entry.startTime))),
2305
+ presentationDelayMs: String(Math.round(Math.max(0, interactionEnd - entry.processingEnd))),
2306
+ processingDurationMs: String(Math.round(Math.max(0, entry.processingEnd - entry.processingStart)))
2307
+ } : { phaseAttribution: "unavailable" },
2308
+ ...overlappingFrame === undefined ? { blockingFrameAttribution: "not-observed" } : {
2309
+ blockingDurationMs: String(Math.round(overlappingFrame.blockingDuration ?? Math.max(0, overlappingFrame.duration - LONG_TASK_MS))),
2310
+ blockingEntryType: overlappingFrame.entryType,
2311
+ blockingFrameDurationMs: String(Math.round(overlappingFrame.duration))
2312
+ },
2232
2313
  durationMs: String(Math.round(entry.duration)),
2233
2314
  eventType: entry.name,
2234
2315
  interactionId: String(entry.interactionId),
2316
+ ...script?.functionName === undefined ? {} : { scriptFunction: script.functionName },
2317
+ ...script?.invoker === undefined ? {} : { scriptInvoker: script.invoker },
2318
+ ...script?.sourceURL === undefined ? {} : { scriptSource: shortUrl(script.sourceURL) },
2235
2319
  signal: BEACON_SIGNAL.SLOW_INTERACTION,
2236
2320
  target
2237
2321
  });
@@ -3617,5 +3701,5 @@ export {
3617
3701
  BEACON_ATTRIBUTE
3618
3702
  };
3619
3703
 
3620
- //# debugId=875797C6E48C710C64756E2164756E21
3704
+ //# debugId=FB8AF5475A58E78864756E2164756E21
3621
3705
  //# sourceMappingURL=index.js.map