@absolutejs/beacon 0.6.38 → 0.6.40
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.d.ts +3 -0
- package/dist/index.js +81 -17
- package/dist/index.js.map +3 -3
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -214,6 +214,9 @@ export type BeaconResourceFailure = {
|
|
|
214
214
|
export type BeaconSignals = {
|
|
215
215
|
/** Back/forward navigations the browser could not restore from bfcache. */
|
|
216
216
|
bfcacheBlocks?: boolean;
|
|
217
|
+
/** Browser-specific bfcache reason strings that are inherent to an
|
|
218
|
+
* application's required capabilities and therefore not actionable. */
|
|
219
|
+
ignoredBfcacheReasons?: string[];
|
|
217
220
|
/** Marked application roots that settle without meaningful visible content. */
|
|
218
221
|
blankAppRoots?: boolean;
|
|
219
222
|
/** Delay before an application root is evaluated. Default 3000ms. */
|
package/dist/index.js
CHANGED
|
@@ -764,7 +764,9 @@ var createBeacon = (options) => {
|
|
|
764
764
|
const MAIN_THREAD_STALL_DEFAULT_WINDOW_MS = 1e4;
|
|
765
765
|
const RELOAD_LOOP_COUNT = 4;
|
|
766
766
|
const RELOAD_LOOP_WINDOW_MS = 60000;
|
|
767
|
-
const
|
|
767
|
+
const NAVIGATION_INTENT_MAX_AGE_MS = 30000;
|
|
768
|
+
const RELOAD_LOOP_STORAGE_KEY = "beacon:reload-history-v4";
|
|
769
|
+
const NAVIGATION_INTENT_STORAGE_KEY = "beacon:navigation-intent-v1";
|
|
768
770
|
const STALE_RELEASE_STORAGE_KEY = "beacon:release-first-seen";
|
|
769
771
|
const STALE_RELEASE_GRACE_MS = 600000;
|
|
770
772
|
const STALE_RELEASE_HISTORY_LIMIT = 5;
|
|
@@ -910,6 +912,7 @@ var createBeacon = (options) => {
|
|
|
910
912
|
pendingClickCleanups.clear();
|
|
911
913
|
});
|
|
912
914
|
let flushPendingNetworkFailures = () => {};
|
|
915
|
+
let pendingNavigationIntentAt;
|
|
913
916
|
let tags = {};
|
|
914
917
|
let user;
|
|
915
918
|
let actionSequence = 0;
|
|
@@ -1451,9 +1454,9 @@ var createBeacon = (options) => {
|
|
|
1451
1454
|
const blockingDuration = entry.entryType === "long-animation-frame" && animationFrame.blockingDuration !== undefined ? animationFrame.blockingDuration : entry.duration;
|
|
1452
1455
|
if (blockingDuration < stallMs)
|
|
1453
1456
|
continue;
|
|
1454
|
-
const
|
|
1455
|
-
stallTimes = stallTimes.filter((at) =>
|
|
1456
|
-
stallTimes.push(
|
|
1457
|
+
const entryAt = entry.startTime;
|
|
1458
|
+
stallTimes = stallTimes.filter((at) => entryAt >= at && entryAt - at < stallWindowMs);
|
|
1459
|
+
stallTimes.push(entryAt);
|
|
1457
1460
|
if (stallTimes.length < stallCount)
|
|
1458
1461
|
continue;
|
|
1459
1462
|
reported = true;
|
|
@@ -1498,6 +1501,7 @@ var createBeacon = (options) => {
|
|
|
1498
1501
|
emitSignal(`Document discarded — the browser reloaded a discarded tab — ${shortUrl(location.href)}`, { signal: BEACON_SIGNAL.DOCUMENT_DISCARDED });
|
|
1499
1502
|
}
|
|
1500
1503
|
if (signals.bfcacheBlocks !== false && typeof performance !== "undefined") {
|
|
1504
|
+
const ignoredBfcacheReasons = new Set(signals.ignoredBfcacheReasons ?? []);
|
|
1501
1505
|
const navigation = performance.getEntriesByType("navigation")[0];
|
|
1502
1506
|
if (navigation?.type === "back_forward" && navigation.notRestoredReasons != null) {
|
|
1503
1507
|
const reasons = new Set;
|
|
@@ -1506,7 +1510,7 @@ var createBeacon = (options) => {
|
|
|
1506
1510
|
if (node === null || typeof node !== "object")
|
|
1507
1511
|
return;
|
|
1508
1512
|
const detail = node;
|
|
1509
|
-
const nodeReasons = (detail.reasons ?? []).map((reason) => reason.reason).filter((reason) => typeof reason === "string" && reason !== "masked").slice(0, 10);
|
|
1513
|
+
const nodeReasons = (detail.reasons ?? []).map((reason) => reason.reason).filter((reason) => typeof reason === "string" && reason !== "masked" && !ignoredBfcacheReasons.has(reason)).slice(0, 10);
|
|
1510
1514
|
for (const reason of nodeReasons)
|
|
1511
1515
|
reasons.add(reason);
|
|
1512
1516
|
if (nodeReasons.length > 0 && blockers.length < 10) {
|
|
@@ -1943,6 +1947,9 @@ var createBeacon = (options) => {
|
|
|
1943
1947
|
const rect = element.getBoundingClientRect();
|
|
1944
1948
|
if (rect.width === 0 && rect.height === 0)
|
|
1945
1949
|
return;
|
|
1950
|
+
if (rect.width <= 2 && rect.height <= 2 && (style.overflowX === "hidden" || style.overflowX === "clip" || style.overflowY === "hidden" || style.overflowY === "clip")) {
|
|
1951
|
+
return;
|
|
1952
|
+
}
|
|
1946
1953
|
if ((style.position === "absolute" || style.position === "fixed") && (rect.right <= 0 || rect.left >= viewportRight || rect.bottom <= 0 || rect.top >= document.documentElement.clientHeight)) {
|
|
1947
1954
|
return;
|
|
1948
1955
|
}
|
|
@@ -2364,7 +2371,31 @@ var createBeacon = (options) => {
|
|
|
2364
2371
|
};
|
|
2365
2372
|
const loadingFirstSeen = new WeakMap;
|
|
2366
2373
|
const reportedStuckLoading = new WeakSet;
|
|
2374
|
+
const trackedLoadingIndicators = new Set;
|
|
2367
2375
|
const loadingIndicatorSelector = `[aria-busy="true"], [role="progressbar"], [${BEACON_ATTRIBUTE.LOADING}]`;
|
|
2376
|
+
const resetLoadingIndicator = (indicator) => {
|
|
2377
|
+
loadingFirstSeen.delete(indicator);
|
|
2378
|
+
reportedStuckLoading.delete(indicator);
|
|
2379
|
+
trackedLoadingIndicators.delete(indicator);
|
|
2380
|
+
};
|
|
2381
|
+
const loadingLifecycleObserver = new MutationObserver((records) => {
|
|
2382
|
+
for (const record of records) {
|
|
2383
|
+
if (!(record.target instanceof Element))
|
|
2384
|
+
continue;
|
|
2385
|
+
resetLoadingIndicator(record.target);
|
|
2386
|
+
}
|
|
2387
|
+
});
|
|
2388
|
+
loadingLifecycleObserver.observe(document.documentElement, {
|
|
2389
|
+
attributeFilter: [
|
|
2390
|
+
"aria-busy",
|
|
2391
|
+
"role",
|
|
2392
|
+
BEACON_ATTRIBUTE.LOADING,
|
|
2393
|
+
BEACON_ATTRIBUTE.LOADING_TIMEOUT
|
|
2394
|
+
],
|
|
2395
|
+
attributes: true,
|
|
2396
|
+
subtree: true
|
|
2397
|
+
});
|
|
2398
|
+
cleanups.push(() => loadingLifecycleObserver.disconnect());
|
|
2368
2399
|
const isPersistentDeterminateProgress = (indicator) => indicator.getAttribute("role") === "progressbar" && indicator.hasAttribute("aria-valuenow") && indicator.getAttribute("aria-busy") !== "true" && !indicator.hasAttribute(BEACON_ATTRIBUTE.LOADING);
|
|
2369
2400
|
const hasTrackedLoadingAncestor = (indicator) => {
|
|
2370
2401
|
let ancestor = indicator.parentElement?.closest(loadingIndicatorSelector);
|
|
@@ -2386,23 +2417,27 @@ var createBeacon = (options) => {
|
|
|
2386
2417
|
const checkStuckLoading = () => {
|
|
2387
2418
|
if (document.visibilityState === "hidden")
|
|
2388
2419
|
return;
|
|
2389
|
-
const indicators = document.querySelectorAll(loadingIndicatorSelector);
|
|
2420
|
+
const indicators = Array.from(document.querySelectorAll(loadingIndicatorSelector));
|
|
2421
|
+
const activeIndicators = new Set(indicators);
|
|
2422
|
+
for (const tracked of trackedLoadingIndicators) {
|
|
2423
|
+
if (!activeIndicators.has(tracked))
|
|
2424
|
+
resetLoadingIndicator(tracked);
|
|
2425
|
+
}
|
|
2390
2426
|
const now = Date.now();
|
|
2391
|
-
for (const indicator of
|
|
2392
|
-
if (isPersistentDeterminateProgress(indicator))
|
|
2393
|
-
|
|
2394
|
-
if (isScanExempt(indicator))
|
|
2395
|
-
continue;
|
|
2396
|
-
if (hasHiddenAncestor(indicator))
|
|
2397
|
-
continue;
|
|
2398
|
-
if (hasTrackedLoadingAncestor(indicator))
|
|
2427
|
+
for (const indicator of indicators) {
|
|
2428
|
+
if (isPersistentDeterminateProgress(indicator) || isScanExempt(indicator) || hasHiddenAncestor(indicator) || hasTrackedLoadingAncestor(indicator)) {
|
|
2429
|
+
resetLoadingIndicator(indicator);
|
|
2399
2430
|
continue;
|
|
2431
|
+
}
|
|
2400
2432
|
const rect = indicator.getBoundingClientRect();
|
|
2401
|
-
if (rect.width === 0 && rect.height === 0)
|
|
2433
|
+
if (rect.width === 0 && rect.height === 0) {
|
|
2434
|
+
resetLoadingIndicator(indicator);
|
|
2402
2435
|
continue;
|
|
2436
|
+
}
|
|
2403
2437
|
const firstSeen = loadingFirstSeen.get(indicator);
|
|
2404
2438
|
if (firstSeen === undefined) {
|
|
2405
2439
|
loadingFirstSeen.set(indicator, now);
|
|
2440
|
+
trackedLoadingIndicators.add(indicator);
|
|
2406
2441
|
continue;
|
|
2407
2442
|
}
|
|
2408
2443
|
const deadlineMs = loadingDeadlineMs(indicator);
|
|
@@ -3744,6 +3779,13 @@ var createBeacon = (options) => {
|
|
|
3744
3779
|
const parsed = raw === null ? [] : JSON.parse(raw);
|
|
3745
3780
|
let history2 = (Array.isArray(parsed) ? parsed : []).filter((entry) => entry !== null && typeof entry === "object" && typeof entry.at === "number" && typeof entry.route === "string" && now - entry.at < RELOAD_LOOP_WINDOW_MS);
|
|
3746
3781
|
let entryKind = "app";
|
|
3782
|
+
const rawNavigationIntent = sessionStorage.getItem(NAVIGATION_INTENT_STORAGE_KEY);
|
|
3783
|
+
sessionStorage.removeItem(NAVIGATION_INTENT_STORAGE_KEY);
|
|
3784
|
+
const navigationIntentAt = Number(rawNavigationIntent);
|
|
3785
|
+
if (rawNavigationIntent !== null && Number.isFinite(navigationIntentAt) && now - navigationIntentAt >= 0 && now - navigationIntentAt <= NAVIGATION_INTENT_MAX_AGE_MS) {
|
|
3786
|
+
history2 = [];
|
|
3787
|
+
entryKind = "intentional-navigation";
|
|
3788
|
+
}
|
|
3747
3789
|
if (document.referrer !== "") {
|
|
3748
3790
|
const referrer = new URL(document.referrer, location.href);
|
|
3749
3791
|
if (referrer.origin !== location.origin) {
|
|
@@ -4081,6 +4123,11 @@ var createBeacon = (options) => {
|
|
|
4081
4123
|
pageLifecycleGeneration += 1;
|
|
4082
4124
|
pageRestoredAt = undefined;
|
|
4083
4125
|
pendingNetworkFailures.delete("transport");
|
|
4126
|
+
if (pendingNavigationIntentAt !== undefined && Date.now() - pendingNavigationIntentAt <= NAVIGATION_INTENT_MAX_AGE_MS) {
|
|
4127
|
+
try {
|
|
4128
|
+
sessionStorage.setItem(NAVIGATION_INTENT_STORAGE_KEY, String(Date.now()));
|
|
4129
|
+
} catch {}
|
|
4130
|
+
}
|
|
4084
4131
|
flush(true);
|
|
4085
4132
|
};
|
|
4086
4133
|
const onPageShow = (event) => {
|
|
@@ -4091,10 +4138,27 @@ var createBeacon = (options) => {
|
|
|
4091
4138
|
if (document.visibilityState === "hidden")
|
|
4092
4139
|
flush(true);
|
|
4093
4140
|
};
|
|
4141
|
+
const onNavigationIntent = (event) => {
|
|
4142
|
+
if (event.type === "submit") {
|
|
4143
|
+
pendingNavigationIntentAt = Date.now();
|
|
4144
|
+
return;
|
|
4145
|
+
}
|
|
4146
|
+
if (!(event instanceof MouseEvent) || event.button !== 0)
|
|
4147
|
+
return;
|
|
4148
|
+
if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey)
|
|
4149
|
+
return;
|
|
4150
|
+
const target = event.target instanceof Element ? event.target : null;
|
|
4151
|
+
const anchor = target?.closest("a[href]");
|
|
4152
|
+
if (anchor instanceof HTMLAnchorElement && anchor.target !== "_blank" && !anchor.hasAttribute("download")) {
|
|
4153
|
+
pendingNavigationIntentAt = Date.now();
|
|
4154
|
+
}
|
|
4155
|
+
};
|
|
4094
4156
|
window.addEventListener("pagehide", onPageHide);
|
|
4095
4157
|
window.addEventListener("pageshow", onPageShow);
|
|
4158
|
+
document.addEventListener("click", onNavigationIntent, true);
|
|
4159
|
+
document.addEventListener("submit", onNavigationIntent, true);
|
|
4096
4160
|
document.addEventListener("visibilitychange", onVisibilityChange);
|
|
4097
|
-
cleanups.push(() => window.removeEventListener("pagehide", onPageHide), () => window.removeEventListener("pageshow", onPageShow), () => document.removeEventListener("visibilitychange", onVisibilityChange));
|
|
4161
|
+
cleanups.push(() => window.removeEventListener("pagehide", onPageHide), () => window.removeEventListener("pageshow", onPageShow), () => document.removeEventListener("click", onNavigationIntent, true), () => document.removeEventListener("submit", onNavigationIntent, true), () => document.removeEventListener("visibilitychange", onVisibilityChange));
|
|
4098
4162
|
return {
|
|
4099
4163
|
addBreadcrumb,
|
|
4100
4164
|
captureException,
|
|
@@ -4139,5 +4203,5 @@ export {
|
|
|
4139
4203
|
BEACON_ATTRIBUTE
|
|
4140
4204
|
};
|
|
4141
4205
|
|
|
4142
|
-
//# debugId=
|
|
4206
|
+
//# debugId=F92DB6A4B074BFF064756E2164756E21
|
|
4143
4207
|
//# sourceMappingURL=index.js.map
|