@absolutejs/beacon 0.6.7 → 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 +4 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +127 -15
- package/dist/index.js.map +3 -3
- package/package.json +1 -1
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
|
|
169
|
-
|
|
170
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
529
|
-
|
|
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
|
|
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(
|
|
549
|
+
const value = Math.round(tasksInWindow.reduce((total, { duration }) => total + Math.max(0, duration - LONG_TASK_MS), 0));
|
|
538
550
|
report({
|
|
539
|
-
|
|
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",
|
|
@@ -1799,6 +1817,40 @@ var createBeacon = (options) => {
|
|
|
1799
1817
|
};
|
|
1800
1818
|
visit(body, null);
|
|
1801
1819
|
};
|
|
1820
|
+
const clipsAxis = (overflow) => overflow === "auto" || overflow === "scroll" || overflow === "hidden" || overflow === "clip";
|
|
1821
|
+
const visibleControlRect = (control, rect, viewportWidth, viewportHeight) => {
|
|
1822
|
+
const visible = {
|
|
1823
|
+
bottom: Math.min(rect.bottom, viewportHeight),
|
|
1824
|
+
left: Math.max(rect.left, 0),
|
|
1825
|
+
right: Math.min(rect.right, viewportWidth),
|
|
1826
|
+
top: Math.max(rect.top, 0)
|
|
1827
|
+
};
|
|
1828
|
+
for (let ancestor = control.parentElement;ancestor; ancestor = ancestor.parentElement) {
|
|
1829
|
+
const style = window.getComputedStyle(ancestor);
|
|
1830
|
+
const clipX = clipsAxis(style.overflowX);
|
|
1831
|
+
const clipY = clipsAxis(style.overflowY);
|
|
1832
|
+
if (!clipX && !clipY)
|
|
1833
|
+
continue;
|
|
1834
|
+
const ancestorRect = ancestor.getBoundingClientRect();
|
|
1835
|
+
if (clipX) {
|
|
1836
|
+
visible.left = Math.max(visible.left, ancestorRect.left);
|
|
1837
|
+
visible.right = Math.min(visible.right, ancestorRect.right);
|
|
1838
|
+
}
|
|
1839
|
+
if (clipY) {
|
|
1840
|
+
visible.top = Math.max(visible.top, ancestorRect.top);
|
|
1841
|
+
visible.bottom = Math.min(visible.bottom, ancestorRect.bottom);
|
|
1842
|
+
}
|
|
1843
|
+
if (visible.left >= visible.right || visible.top >= visible.bottom) {
|
|
1844
|
+
return null;
|
|
1845
|
+
}
|
|
1846
|
+
}
|
|
1847
|
+
const centerX = (rect.left + rect.right) / 2;
|
|
1848
|
+
const centerY = (rect.top + rect.bottom) / 2;
|
|
1849
|
+
if (centerX < visible.left || centerX > visible.right || centerY < visible.top || centerY > visible.bottom) {
|
|
1850
|
+
return null;
|
|
1851
|
+
}
|
|
1852
|
+
return visible;
|
|
1853
|
+
};
|
|
1802
1854
|
const scanForOcclusion = () => {
|
|
1803
1855
|
if (typeof document.elementFromPoint !== "function")
|
|
1804
1856
|
return;
|
|
@@ -1816,18 +1868,18 @@ var createBeacon = (options) => {
|
|
|
1816
1868
|
const rect = control.getBoundingClientRect();
|
|
1817
1869
|
if (rect.width === 0 || rect.height === 0)
|
|
1818
1870
|
continue;
|
|
1819
|
-
|
|
1871
|
+
const visibleRect = visibleControlRect(control, rect, viewportWidth, viewportHeight);
|
|
1872
|
+
if (visibleRect === null)
|
|
1820
1873
|
continue;
|
|
1821
|
-
}
|
|
1822
1874
|
sampled += 1;
|
|
1823
|
-
const top = document.elementFromPoint((
|
|
1875
|
+
const top = document.elementFromPoint((visibleRect.left + visibleRect.right) / 2, (visibleRect.top + visibleRect.bottom) / 2);
|
|
1824
1876
|
if (top === null || top === control || control.contains(top) || top.contains(control)) {
|
|
1825
1877
|
continue;
|
|
1826
1878
|
}
|
|
1827
1879
|
const topRect = top.getBoundingClientRect();
|
|
1828
|
-
const overlapX = Math.min(
|
|
1829
|
-
const overlapY = Math.min(
|
|
1830
|
-
const coverage = Math.max(overlapX, 0) * Math.max(overlapY, 0) / (
|
|
1880
|
+
const overlapX = Math.min(visibleRect.right, topRect.right) - Math.max(visibleRect.left, topRect.left);
|
|
1881
|
+
const overlapY = Math.min(visibleRect.bottom, topRect.bottom) - Math.max(visibleRect.top, topRect.top);
|
|
1882
|
+
const coverage = Math.max(overlapX, 0) * Math.max(overlapY, 0) / ((visibleRect.right - visibleRect.left) * (visibleRect.bottom - visibleRect.top));
|
|
1831
1883
|
if (coverage < OCCLUSION_COVERAGE_MIN)
|
|
1832
1884
|
continue;
|
|
1833
1885
|
reportScanIssue(control, BEACON_SIGNAL.OCCLUDED_CONTROL, `Occluded control — ${describeElement(control)} is covered by ${describeElement(top)}`, { coveredBy: describeElement(top) });
|
|
@@ -2183,6 +2235,42 @@ var createBeacon = (options) => {
|
|
|
2183
2235
|
if (signals !== null && signals.slowInteractions !== false && typeof PerformanceObserver !== "undefined") {
|
|
2184
2236
|
const minimum = signals.slowInteractionMs ?? SLOW_INTERACTION_DEFAULT_MS;
|
|
2185
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
|
+
}
|
|
2186
2274
|
try {
|
|
2187
2275
|
const observer = new PerformanceObserver((list) => {
|
|
2188
2276
|
for (const raw of list.getEntries()) {
|
|
@@ -2194,10 +2282,34 @@ var createBeacon = (options) => {
|
|
|
2194
2282
|
if (reported.has(key))
|
|
2195
2283
|
continue;
|
|
2196
2284
|
reported.add(key);
|
|
2197
|
-
|
|
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
|
+
},
|
|
2198
2307
|
durationMs: String(Math.round(entry.duration)),
|
|
2199
2308
|
eventType: entry.name,
|
|
2200
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) },
|
|
2201
2313
|
signal: BEACON_SIGNAL.SLOW_INTERACTION,
|
|
2202
2314
|
target
|
|
2203
2315
|
});
|
|
@@ -3583,5 +3695,5 @@ export {
|
|
|
3583
3695
|
BEACON_ATTRIBUTE
|
|
3584
3696
|
};
|
|
3585
3697
|
|
|
3586
|
-
//# debugId=
|
|
3698
|
+
//# debugId=D59101AFB8434CF164756E2164756E21
|
|
3587
3699
|
//# sourceMappingURL=index.js.map
|