@absolutejs/beacon 0.6.8 → 0.6.9

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",
@@ -2217,6 +2235,42 @@ var createBeacon = (options) => {
2217
2235
  if (signals !== null && signals.slowInteractions !== false && typeof PerformanceObserver !== "undefined") {
2218
2236
  const minimum = signals.slowInteractionMs ?? SLOW_INTERACTION_DEFAULT_MS;
2219
2237
  const reported = new Set;
2238
+ const blockingFrames = [];
2239
+ const recordBlockingFrames = (entries) => {
2240
+ for (const entry of entries)
2241
+ blockingFrames.push(entry);
2242
+ if (blockingFrames.length > 50)
2243
+ blockingFrames.splice(0, blockingFrames.length - 50);
2244
+ };
2245
+ let blockingObserver;
2246
+ try {
2247
+ blockingObserver = new PerformanceObserver((list) => {
2248
+ recordBlockingFrames(list.getEntries());
2249
+ });
2250
+ const supportedTypes = PerformanceObserver.supportedEntryTypes;
2251
+ if (supportedTypes?.includes("long-animation-frame")) {
2252
+ blockingObserver.observe({
2253
+ buffered: true,
2254
+ type: "long-animation-frame"
2255
+ });
2256
+ } else if (supportedTypes?.includes("longtask")) {
2257
+ blockingObserver.observe({ buffered: true, type: "longtask" });
2258
+ } else if (supportedTypes === undefined || supportedTypes.length === 0) {
2259
+ blockingObserver.observe({
2260
+ buffered: true,
2261
+ type: "long-animation-frame"
2262
+ });
2263
+ } else {
2264
+ blockingObserver.disconnect();
2265
+ blockingObserver = undefined;
2266
+ }
2267
+ if (blockingObserver !== undefined) {
2268
+ cleanups.push(() => blockingObserver?.disconnect());
2269
+ }
2270
+ } catch {
2271
+ blockingObserver?.disconnect();
2272
+ blockingObserver = undefined;
2273
+ }
2220
2274
  try {
2221
2275
  const observer = new PerformanceObserver((list) => {
2222
2276
  for (const raw of list.getEntries()) {
@@ -2228,10 +2282,34 @@ var createBeacon = (options) => {
2228
2282
  if (reported.has(key))
2229
2283
  continue;
2230
2284
  reported.add(key);
2231
- emitSignal(`Slow interaction — ${entry.name} blocked for ${Math.round(entry.duration)}ms — ${shortUrl(location.href)}`, {
2285
+ if (blockingObserver !== undefined) {
2286
+ recordBlockingFrames(blockingObserver.takeRecords());
2287
+ }
2288
+ const interactionEnd = entry.startTime + entry.duration;
2289
+ const overlappingFrame = blockingFrames.filter((frame) => frame.startTime < interactionEnd && frame.startTime + frame.duration > entry.startTime).sort((left, right) => {
2290
+ const leftBlocking = left.blockingDuration ?? Math.max(0, left.duration - LONG_TASK_MS);
2291
+ const rightBlocking = right.blockingDuration ?? Math.max(0, right.duration - LONG_TASK_MS);
2292
+ return rightBlocking - leftBlocking;
2293
+ })[0];
2294
+ const script = [...overlappingFrame?.scripts ?? []].sort((left, right) => (right.duration ?? 0) - (left.duration ?? 0))[0];
2295
+ const hasPhaseTiming = typeof entry.processingStart === "number" && typeof entry.processingEnd === "number";
2296
+ emitSignal(`Slow interaction — ${entry.name} took ${Math.round(entry.duration)}ms — ${shortUrl(location.href)}`, {
2297
+ ...hasPhaseTiming ? {
2298
+ inputDelayMs: String(Math.round(Math.max(0, entry.processingStart - entry.startTime))),
2299
+ presentationDelayMs: String(Math.round(Math.max(0, interactionEnd - entry.processingEnd))),
2300
+ processingDurationMs: String(Math.round(Math.max(0, entry.processingEnd - entry.processingStart)))
2301
+ } : { phaseAttribution: "unavailable" },
2302
+ ...overlappingFrame === undefined ? { blockingFrameAttribution: "not-observed" } : {
2303
+ blockingDurationMs: String(Math.round(overlappingFrame.blockingDuration ?? Math.max(0, overlappingFrame.duration - LONG_TASK_MS))),
2304
+ blockingEntryType: overlappingFrame.entryType,
2305
+ blockingFrameDurationMs: String(Math.round(overlappingFrame.duration))
2306
+ },
2232
2307
  durationMs: String(Math.round(entry.duration)),
2233
2308
  eventType: entry.name,
2234
2309
  interactionId: String(entry.interactionId),
2310
+ ...script?.functionName === undefined ? {} : { scriptFunction: script.functionName },
2311
+ ...script?.invoker === undefined ? {} : { scriptInvoker: script.invoker },
2312
+ ...script?.sourceURL === undefined ? {} : { scriptSource: shortUrl(script.sourceURL) },
2235
2313
  signal: BEACON_SIGNAL.SLOW_INTERACTION,
2236
2314
  target
2237
2315
  });
@@ -3617,5 +3695,5 @@ export {
3617
3695
  BEACON_ATTRIBUTE
3618
3696
  };
3619
3697
 
3620
- //# debugId=875797C6E48C710C64756E2164756E21
3698
+ //# debugId=D59101AFB8434CF164756E2164756E21
3621
3699
  //# sourceMappingURL=index.js.map