@absolutejs/beacon 0.7.0-beta.11 → 0.7.0-beta.13
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/CHANGELOG.md +12 -0
- package/changelog.json +28 -0
- package/dist/contracts.js +1 -9
- package/dist/contracts.js.map +2 -2
- package/dist/early.js +1 -9
- package/dist/early.js.map +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +191 -166
- package/dist/index.js.map +3 -3
- package/dist/manifest.js +1 -9
- package/dist/manifest.js.map +2 -2
- package/dist/policy.js +1 -9
- package/dist/policy.js.map +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
-
}) : x)(function(x) {
|
|
4
|
-
if (typeof require !== "undefined")
|
|
5
|
-
return require.apply(this, arguments);
|
|
6
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
-
});
|
|
8
|
-
|
|
9
1
|
// src/contracts.ts
|
|
10
2
|
var BEACON_SIGNAL = {
|
|
11
3
|
AUTH_FAILURE_STORM: "auth_failure_storm",
|
|
@@ -199,7 +191,7 @@ var consumeEarlyLayoutShiftBuffer = () => {
|
|
|
199
191
|
|
|
200
192
|
// src/index.ts
|
|
201
193
|
var BEACON_TRACE_HEADER = "x-absolute-trace-id";
|
|
202
|
-
var BEACON_SDK_VERSION = "0.7.0-beta.
|
|
194
|
+
var BEACON_SDK_VERSION = "0.7.0-beta.13";
|
|
203
195
|
var inBrowser = () => typeof window !== "undefined";
|
|
204
196
|
var newId = () => {
|
|
205
197
|
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
@@ -765,52 +757,77 @@ var TBT_GOOD_MS = 200;
|
|
|
765
757
|
var TBT_POOR_MS = 600;
|
|
766
758
|
var observeLongTasks = (report, navigationType) => {
|
|
767
759
|
if (typeof PerformanceObserver === "undefined")
|
|
768
|
-
return;
|
|
760
|
+
return () => {};
|
|
769
761
|
const longTasks = [];
|
|
770
|
-
let
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
762
|
+
let observer;
|
|
763
|
+
let timer;
|
|
764
|
+
let stopped = false;
|
|
765
|
+
const firstPaint = () => performance.getEntriesByName("first-contentful-paint")[0]?.startTime;
|
|
766
|
+
const collect = (entries) => {
|
|
767
|
+
if (stopped)
|
|
768
|
+
return;
|
|
769
|
+
const windowStart = firstPaint() ?? 0;
|
|
770
|
+
for (const entry of entries) {
|
|
771
|
+
if (entry.startTime < windowStart || entry.startTime >= windowStart + TBT_WINDOW_MS)
|
|
772
|
+
continue;
|
|
773
|
+
longTasks.push({ duration: entry.duration, startTime: entry.startTime });
|
|
774
|
+
}
|
|
775
|
+
};
|
|
776
|
+
const onVisibilityChange = () => {
|
|
777
|
+
if (document.visibilityState === "hidden")
|
|
778
|
+
flush();
|
|
779
|
+
};
|
|
780
|
+
const stop = () => {
|
|
781
|
+
stopped = true;
|
|
782
|
+
if (timer !== undefined)
|
|
783
|
+
clearTimeout(timer);
|
|
784
|
+
observer?.disconnect();
|
|
785
|
+
window.removeEventListener("visibilitychange", onVisibilityChange);
|
|
786
|
+
window.removeEventListener("pagehide", flush);
|
|
787
|
+
longTasks.length = 0;
|
|
788
|
+
};
|
|
789
|
+
const flush = () => {
|
|
790
|
+
if (stopped)
|
|
791
|
+
return;
|
|
792
|
+
collect(observer?.takeRecords() ?? []);
|
|
793
|
+
const paint = firstPaint();
|
|
794
|
+
const windowStart = paint ?? 0;
|
|
795
|
+
const tasks = longTasks.filter(({ startTime }) => startTime >= windowStart && startTime < windowStart + TBT_WINDOW_MS);
|
|
796
|
+
stop();
|
|
797
|
+
if (tasks.length === 0)
|
|
798
|
+
return;
|
|
799
|
+
const value = Math.round(tasks.reduce((total, { duration }) => total + Math.max(0, duration - LONG_TASK_MS), 0));
|
|
800
|
+
report({
|
|
801
|
+
attribution: {
|
|
802
|
+
measurementWindow: paint === undefined ? "navigation" : "FCP",
|
|
803
|
+
measurementWindowMs: TBT_WINDOW_MS
|
|
804
|
+
},
|
|
805
|
+
id: `tbt-${navigationType}-${TBT_WINDOW_MS}-${value}`,
|
|
806
|
+
name: "TBT",
|
|
807
|
+
navigationType,
|
|
808
|
+
rating: value <= TBT_GOOD_MS ? "good" : value >= TBT_POOR_MS ? "poor" : "needs-improvement",
|
|
809
|
+
value
|
|
783
810
|
});
|
|
811
|
+
};
|
|
812
|
+
const finishWindow = () => {
|
|
813
|
+
if (stopped)
|
|
814
|
+
return;
|
|
815
|
+
const remaining = (firstPaint() ?? 0) + TBT_WINDOW_MS - performance.now();
|
|
816
|
+
if (remaining > 0)
|
|
817
|
+
timer = setTimeout(finishWindow, remaining);
|
|
818
|
+
else
|
|
819
|
+
flush();
|
|
820
|
+
};
|
|
821
|
+
try {
|
|
822
|
+
observer = new PerformanceObserver((list) => collect(list.getEntries()));
|
|
784
823
|
observer.observe({ buffered: true, type: "longtask" });
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
if (tasksInWindow.length === 0)
|
|
793
|
-
return;
|
|
794
|
-
reported = true;
|
|
795
|
-
const value = Math.round(tasksInWindow.reduce((total, { duration }) => total + Math.max(0, duration - LONG_TASK_MS), 0));
|
|
796
|
-
report({
|
|
797
|
-
attribution: {
|
|
798
|
-
measurementWindow: firstContentfulPaint === undefined ? "navigation" : "FCP",
|
|
799
|
-
measurementWindowMs: TBT_WINDOW_MS
|
|
800
|
-
},
|
|
801
|
-
id: `tbt-${navigationType}-${TBT_WINDOW_MS}-${value}`,
|
|
802
|
-
name: "TBT",
|
|
803
|
-
navigationType,
|
|
804
|
-
rating: value <= TBT_GOOD_MS ? "good" : value >= TBT_POOR_MS ? "poor" : "needs-improvement",
|
|
805
|
-
value
|
|
806
|
-
});
|
|
807
|
-
};
|
|
808
|
-
addEventListener("visibilitychange", () => {
|
|
809
|
-
if (document.visibilityState === "hidden")
|
|
810
|
-
flush();
|
|
811
|
-
});
|
|
812
|
-
addEventListener("pagehide", flush);
|
|
813
|
-
} catch {}
|
|
824
|
+
window.addEventListener("visibilitychange", onVisibilityChange);
|
|
825
|
+
window.addEventListener("pagehide", flush);
|
|
826
|
+
timer = setTimeout(finishWindow, Math.max(0, (firstPaint() ?? 0) + TBT_WINDOW_MS - performance.now()));
|
|
827
|
+
} catch {
|
|
828
|
+
stop();
|
|
829
|
+
}
|
|
830
|
+
return stop;
|
|
814
831
|
};
|
|
815
832
|
var isVitalName = (name) => VITAL_NAMES.has(name);
|
|
816
833
|
var vitalAttribution = (value) => {
|
|
@@ -1008,12 +1025,12 @@ var createBeacon = (options) => {
|
|
|
1008
1025
|
let recentInteraction;
|
|
1009
1026
|
let recentNavigation;
|
|
1010
1027
|
let reportErrorClick = null;
|
|
1011
|
-
const reportCapturedErrorClick = (error,
|
|
1028
|
+
const reportCapturedErrorClick = (error, tags) => {
|
|
1012
1029
|
if (filterKnownNoise && isKnownBeaconNoise({
|
|
1013
1030
|
message: error.message,
|
|
1014
1031
|
name: error.name,
|
|
1015
1032
|
stack: error.stack,
|
|
1016
|
-
tags
|
|
1033
|
+
tags
|
|
1017
1034
|
}))
|
|
1018
1035
|
return;
|
|
1019
1036
|
reportErrorClick?.(error.name);
|
|
@@ -1070,11 +1087,13 @@ var createBeacon = (options) => {
|
|
|
1070
1087
|
}
|
|
1071
1088
|
return false;
|
|
1072
1089
|
};
|
|
1090
|
+
const cleanups = [];
|
|
1091
|
+
let closed = false;
|
|
1073
1092
|
const vitalsOptions = options.vitals === undefined || options.vitals === false ? null : options.vitals === true ? {} : options.vitals;
|
|
1074
1093
|
if (vitalsOptions !== null) {
|
|
1075
1094
|
const vitalsEndpoint = vitalsOptions.endpoint ?? "/ingest/vitals";
|
|
1076
1095
|
const reportVital = (metric) => {
|
|
1077
|
-
if (!isVitalName(metric.name))
|
|
1096
|
+
if (closed || !isVitalName(metric.name))
|
|
1078
1097
|
return;
|
|
1079
1098
|
const replayId = options.getReplayId?.();
|
|
1080
1099
|
const traceId = options.getTraceId?.();
|
|
@@ -1117,17 +1136,19 @@ var createBeacon = (options) => {
|
|
|
1117
1136
|
if (vitalsOptions.webVitals !== undefined) {
|
|
1118
1137
|
observeWebVitals(vitalsOptions.webVitals, reportVital);
|
|
1119
1138
|
} else {
|
|
1120
|
-
loadWebVitals().then((webVitals) =>
|
|
1139
|
+
loadWebVitals().then((webVitals) => {
|
|
1140
|
+
if (!closed)
|
|
1141
|
+
observeWebVitals(webVitals, reportVital);
|
|
1142
|
+
}).catch(() => {
|
|
1121
1143
|
console.warn("[beacon] web-vitals not installed; vitals disabled. `bun add web-vitals`.");
|
|
1122
1144
|
});
|
|
1123
1145
|
}
|
|
1124
1146
|
const navigationEntry = performance.getEntriesByType("navigation")[0];
|
|
1125
1147
|
const navigationType = typeof PerformanceNavigationTiming !== "undefined" && navigationEntry instanceof PerformanceNavigationTiming ? navigationEntry.type : "navigate";
|
|
1126
|
-
observeLongTasks(reportVital, navigationType);
|
|
1148
|
+
cleanups.push(observeLongTasks(reportVital, navigationType));
|
|
1127
1149
|
}
|
|
1128
1150
|
const buffer = [];
|
|
1129
1151
|
const breadcrumbs = [];
|
|
1130
|
-
const cleanups = [];
|
|
1131
1152
|
const pendingClickCleanups = new Set;
|
|
1132
1153
|
cleanups.push(() => {
|
|
1133
1154
|
for (const cleanup of pendingClickCleanups)
|
|
@@ -1352,15 +1373,15 @@ var createBeacon = (options) => {
|
|
|
1352
1373
|
}
|
|
1353
1374
|
};
|
|
1354
1375
|
const interval = window.setInterval(checkWhenVisible, Math.max(1000, probe.intervalMs ?? 60000));
|
|
1355
|
-
const
|
|
1376
|
+
const onVisibilityChange = () => checkWhenVisible();
|
|
1356
1377
|
window.addEventListener("focus", checkWhenVisible);
|
|
1357
1378
|
window.addEventListener("online", checkWhenVisible);
|
|
1358
|
-
document.addEventListener("visibilitychange",
|
|
1379
|
+
document.addEventListener("visibilitychange", onVisibilityChange);
|
|
1359
1380
|
cleanups.push(() => {
|
|
1360
1381
|
window.clearInterval(interval);
|
|
1361
1382
|
window.removeEventListener("focus", checkWhenVisible);
|
|
1362
1383
|
window.removeEventListener("online", checkWhenVisible);
|
|
1363
|
-
document.removeEventListener("visibilitychange",
|
|
1384
|
+
document.removeEventListener("visibilitychange", onVisibilityChange);
|
|
1364
1385
|
});
|
|
1365
1386
|
checkServingRelease();
|
|
1366
1387
|
}
|
|
@@ -1408,13 +1429,13 @@ var createBeacon = (options) => {
|
|
|
1408
1429
|
const authFailureStormWindowMs = signals?.authFailureStormWindowMs ?? AUTH_FAILURE_STORM_DEFAULT_WINDOW_MS;
|
|
1409
1430
|
const authFailuresByEndpoint = new Map;
|
|
1410
1431
|
const reportedAuthFailureStorms = new Set;
|
|
1411
|
-
const recordAuthFailure = (
|
|
1432
|
+
const recordAuthFailure = (endpoint, method, status) => {
|
|
1412
1433
|
if (signals === null || signals.authFailureStorms === false)
|
|
1413
1434
|
return false;
|
|
1414
|
-
const label = `${method} ${
|
|
1415
|
-
const
|
|
1416
|
-
const failures = (authFailuresByEndpoint.get(label) ?? []).filter(({ at }) =>
|
|
1417
|
-
failures.push({ at:
|
|
1435
|
+
const label = `${method} ${endpoint}`;
|
|
1436
|
+
const now = Date.now();
|
|
1437
|
+
const failures = (authFailuresByEndpoint.get(label) ?? []).filter(({ at }) => now - at < authFailureStormWindowMs);
|
|
1438
|
+
failures.push({ at: now, status });
|
|
1418
1439
|
authFailuresByEndpoint.set(label, failures);
|
|
1419
1440
|
if (failures.length < authFailureStormCount || reportedAuthFailureStorms.has(label)) {
|
|
1420
1441
|
return false;
|
|
@@ -1422,7 +1443,7 @@ var createBeacon = (options) => {
|
|
|
1422
1443
|
reportedAuthFailureStorms.add(label);
|
|
1423
1444
|
const statuses = [...new Set(failures.map((failure) => failure.status))];
|
|
1424
1445
|
emitSignal(`Authorization failure storm — ${label} repeatedly rejected requests — ${shortUrl(location.href)}`, {
|
|
1425
|
-
endpoint
|
|
1446
|
+
endpoint,
|
|
1426
1447
|
failureCount: String(failures.length),
|
|
1427
1448
|
method,
|
|
1428
1449
|
signal: BEACON_SIGNAL.AUTH_FAILURE_STORM,
|
|
@@ -1516,14 +1537,14 @@ var createBeacon = (options) => {
|
|
|
1516
1537
|
const newestFailureAt = Math.max(...failures.map(({ at }) => at));
|
|
1517
1538
|
const reportDelayMs = Math.max(0, Date.now() - newestFailureAt);
|
|
1518
1539
|
const endpoints = [
|
|
1519
|
-
...new Set(failures.map(({ endpoint
|
|
1540
|
+
...new Set(failures.map(({ endpoint }) => endpoint))
|
|
1520
1541
|
].sort();
|
|
1521
1542
|
const methods = [...new Set(failures.map(({ method }) => method))].sort();
|
|
1522
1543
|
const onlineStates = [
|
|
1523
1544
|
...new Set(failures.map(({ online }) => String(online)))
|
|
1524
1545
|
].sort();
|
|
1525
1546
|
const transports = [
|
|
1526
|
-
...new Set(failures.map(({ transport
|
|
1547
|
+
...new Set(failures.map(({ transport }) => transport))
|
|
1527
1548
|
].sort();
|
|
1528
1549
|
const visibilityStates = [
|
|
1529
1550
|
...new Set(failures.map(({ visibilityState }) => visibilityState))
|
|
@@ -1624,7 +1645,7 @@ var createBeacon = (options) => {
|
|
|
1624
1645
|
let mutated = false;
|
|
1625
1646
|
let extended = false;
|
|
1626
1647
|
let finished = false;
|
|
1627
|
-
let
|
|
1648
|
+
let timer;
|
|
1628
1649
|
const observeRouterAcceptance = (handledEvent) => {
|
|
1629
1650
|
if (handledEvent !== event)
|
|
1630
1651
|
return;
|
|
@@ -1637,8 +1658,8 @@ var createBeacon = (options) => {
|
|
|
1637
1658
|
finished = true;
|
|
1638
1659
|
observer.disconnect();
|
|
1639
1660
|
control.removeEventListener("click", observeRouterAcceptance);
|
|
1640
|
-
if (
|
|
1641
|
-
window.clearTimeout(
|
|
1661
|
+
if (timer !== undefined)
|
|
1662
|
+
window.clearTimeout(timer);
|
|
1642
1663
|
pendingClickCleanups.delete(cancel);
|
|
1643
1664
|
report(didRespond, navigationStalled);
|
|
1644
1665
|
};
|
|
@@ -1648,8 +1669,8 @@ var createBeacon = (options) => {
|
|
|
1648
1669
|
finished = true;
|
|
1649
1670
|
observer.disconnect();
|
|
1650
1671
|
control.removeEventListener("click", observeRouterAcceptance);
|
|
1651
|
-
if (
|
|
1652
|
-
window.clearTimeout(
|
|
1672
|
+
if (timer !== undefined)
|
|
1673
|
+
window.clearTimeout(timer);
|
|
1653
1674
|
};
|
|
1654
1675
|
const observer = new MutationObserver(() => {
|
|
1655
1676
|
mutated = true;
|
|
@@ -1662,7 +1683,7 @@ var createBeacon = (options) => {
|
|
|
1662
1683
|
});
|
|
1663
1684
|
pendingClickCleanups.add(cancel);
|
|
1664
1685
|
control.addEventListener("click", observeRouterAcceptance, { once: true });
|
|
1665
|
-
|
|
1686
|
+
timer = window.setTimeout(() => {
|
|
1666
1687
|
if (responded()) {
|
|
1667
1688
|
finish(true);
|
|
1668
1689
|
return;
|
|
@@ -1672,7 +1693,7 @@ var createBeacon = (options) => {
|
|
|
1672
1693
|
return;
|
|
1673
1694
|
}
|
|
1674
1695
|
extended = true;
|
|
1675
|
-
|
|
1696
|
+
timer = window.setTimeout(() => {
|
|
1676
1697
|
const didRespond = responded();
|
|
1677
1698
|
finish(didRespond, !didRespond);
|
|
1678
1699
|
}, navigationResponseMs - DEAD_CLICK_WINDOW_MS);
|
|
@@ -2503,12 +2524,12 @@ var createBeacon = (options) => {
|
|
|
2503
2524
|
if (first.element.parentElement === second.element.parentElement && (first.positioned || second.positioned)) {
|
|
2504
2525
|
continue;
|
|
2505
2526
|
}
|
|
2506
|
-
const
|
|
2527
|
+
const axis = overlapY <= overlapX ? "vertical" : "horizontal";
|
|
2507
2528
|
reportScanIssue(first.element, BEACON_SIGNAL.CONTROL_COLLISION, `Control collision — ${describeElement(first.element)} overlaps ${describeElement(second.element)}`, {
|
|
2508
2529
|
collidesWith: describeElement(second.element),
|
|
2509
|
-
collisionAxis:
|
|
2530
|
+
collisionAxis: axis,
|
|
2510
2531
|
collisionKind: "overlap",
|
|
2511
|
-
overlapPx: String(Math.round(
|
|
2532
|
+
overlapPx: String(Math.round(axis === "vertical" ? overlapY : overlapX))
|
|
2512
2533
|
}, scanLayoutContext(first.element, second.element));
|
|
2513
2534
|
continue;
|
|
2514
2535
|
}
|
|
@@ -2853,9 +2874,9 @@ var createBeacon = (options) => {
|
|
|
2853
2874
|
const checkStuckLoading = () => {
|
|
2854
2875
|
if (document.visibilityState === "hidden")
|
|
2855
2876
|
return;
|
|
2856
|
-
const
|
|
2857
|
-
const missedPollWindow = lastLoadingCheckAt !== undefined &&
|
|
2858
|
-
lastLoadingCheckAt =
|
|
2877
|
+
const now = Date.now();
|
|
2878
|
+
const missedPollWindow = lastLoadingCheckAt !== undefined && now - lastLoadingCheckAt > STUCK_LOADING_POLL_MS * 3;
|
|
2879
|
+
lastLoadingCheckAt = now;
|
|
2859
2880
|
const indicators = Array.from(document.querySelectorAll(loadingIndicatorSelector));
|
|
2860
2881
|
const activeIndicators = new Set(indicators);
|
|
2861
2882
|
for (const tracked of trackedLoadingIndicators) {
|
|
@@ -2873,22 +2894,22 @@ var createBeacon = (options) => {
|
|
|
2873
2894
|
continue;
|
|
2874
2895
|
}
|
|
2875
2896
|
if (missedPollWindow && loadingFirstSeen.has(indicator)) {
|
|
2876
|
-
loadingFirstSeen.set(indicator,
|
|
2897
|
+
loadingFirstSeen.set(indicator, now);
|
|
2877
2898
|
}
|
|
2878
2899
|
const firstSeen = loadingFirstSeen.get(indicator);
|
|
2879
2900
|
if (firstSeen === undefined) {
|
|
2880
|
-
loadingFirstSeen.set(indicator,
|
|
2901
|
+
loadingFirstSeen.set(indicator, now);
|
|
2881
2902
|
trackedLoadingIndicators.add(indicator);
|
|
2882
2903
|
continue;
|
|
2883
2904
|
}
|
|
2884
2905
|
const deadlineMs = loadingDeadlineMs(indicator);
|
|
2885
|
-
if (
|
|
2906
|
+
if (now - firstSeen < deadlineMs || reportedStuckLoading.has(indicator)) {
|
|
2886
2907
|
continue;
|
|
2887
2908
|
}
|
|
2888
2909
|
reportedStuckLoading.add(indicator);
|
|
2889
2910
|
reportScanIssue(indicator, BEACON_SIGNAL.STUCK_LOADING, `Stuck loading — ${describeElement(indicator)} never resolved`, {
|
|
2890
2911
|
deadlineMs: String(deadlineMs),
|
|
2891
|
-
visibleMs: String(
|
|
2912
|
+
visibleMs: String(now - firstSeen)
|
|
2892
2913
|
});
|
|
2893
2914
|
}
|
|
2894
2915
|
};
|
|
@@ -3286,7 +3307,7 @@ var createBeacon = (options) => {
|
|
|
3286
3307
|
if (name === null)
|
|
3287
3308
|
return;
|
|
3288
3309
|
const onLoad = () => stopWatching(frame);
|
|
3289
|
-
const
|
|
3310
|
+
const timer = setTimeout(() => {
|
|
3290
3311
|
stopWatching(frame);
|
|
3291
3312
|
if (pageLifecycleEnding || document.visibilityState === "hidden" || !frame.isConnected) {
|
|
3292
3313
|
return;
|
|
@@ -3303,7 +3324,7 @@ var createBeacon = (options) => {
|
|
|
3303
3324
|
target: describeElement(frame)
|
|
3304
3325
|
});
|
|
3305
3326
|
}, stallMs);
|
|
3306
|
-
watched.set(frame, { onLoad, timer
|
|
3327
|
+
watched.set(frame, { onLoad, timer });
|
|
3307
3328
|
frame.addEventListener("load", onLoad, { once: true });
|
|
3308
3329
|
};
|
|
3309
3330
|
const discoverFrames = (root) => {
|
|
@@ -3502,9 +3523,9 @@ var createBeacon = (options) => {
|
|
|
3502
3523
|
const pending = new Map;
|
|
3503
3524
|
const reported = new WeakSet;
|
|
3504
3525
|
const clearPending = (canvas) => {
|
|
3505
|
-
const
|
|
3506
|
-
if (
|
|
3507
|
-
clearTimeout(
|
|
3526
|
+
const timer = pending.get(canvas);
|
|
3527
|
+
if (timer !== undefined)
|
|
3528
|
+
clearTimeout(timer);
|
|
3508
3529
|
pending.delete(canvas);
|
|
3509
3530
|
};
|
|
3510
3531
|
const onLost = (event) => {
|
|
@@ -3512,7 +3533,7 @@ var createBeacon = (options) => {
|
|
|
3512
3533
|
return;
|
|
3513
3534
|
const canvas = event.target;
|
|
3514
3535
|
clearPending(canvas);
|
|
3515
|
-
const
|
|
3536
|
+
const timer = setTimeout(() => {
|
|
3516
3537
|
pending.delete(canvas);
|
|
3517
3538
|
if (reported.has(canvas) || pageLifecycleEnding || document.visibilityState === "hidden" || !canvas.isConnected) {
|
|
3518
3539
|
return;
|
|
@@ -3529,7 +3550,7 @@ var createBeacon = (options) => {
|
|
|
3529
3550
|
target: describeElement(canvas)
|
|
3530
3551
|
});
|
|
3531
3552
|
}, graceMs);
|
|
3532
|
-
pending.set(canvas,
|
|
3553
|
+
pending.set(canvas, timer);
|
|
3533
3554
|
};
|
|
3534
3555
|
const onRestored = (event) => {
|
|
3535
3556
|
if (event.target instanceof HTMLCanvasElement)
|
|
@@ -3540,8 +3561,8 @@ var createBeacon = (options) => {
|
|
|
3540
3561
|
cleanups.push(() => {
|
|
3541
3562
|
document.removeEventListener("webglcontextlost", onLost, true);
|
|
3542
3563
|
document.removeEventListener("webglcontextrestored", onRestored, true);
|
|
3543
|
-
for (const
|
|
3544
|
-
clearTimeout(
|
|
3564
|
+
for (const timer of pending.values())
|
|
3565
|
+
clearTimeout(timer);
|
|
3545
3566
|
pending.clear();
|
|
3546
3567
|
});
|
|
3547
3568
|
}
|
|
@@ -3550,9 +3571,9 @@ var createBeacon = (options) => {
|
|
|
3550
3571
|
const visualViewport = window.visualViewport;
|
|
3551
3572
|
const settleMs = signals.focusedControlSettleMs ?? FOCUSED_CONTROL_SETTLE_DEFAULT_MS;
|
|
3552
3573
|
const reported = new Set;
|
|
3553
|
-
let
|
|
3574
|
+
let timer;
|
|
3554
3575
|
const checkFocusedControl = () => {
|
|
3555
|
-
|
|
3576
|
+
timer = undefined;
|
|
3556
3577
|
if (pageLifecycleEnding || document.visibilityState === "hidden" || visualViewport.height >= window.innerHeight * KEYBOARD_VIEWPORT_HEIGHT_RATIO_MAX) {
|
|
3557
3578
|
return;
|
|
3558
3579
|
}
|
|
@@ -3582,9 +3603,9 @@ var createBeacon = (options) => {
|
|
|
3582
3603
|
});
|
|
3583
3604
|
};
|
|
3584
3605
|
const scheduleCheck = () => {
|
|
3585
|
-
if (
|
|
3586
|
-
clearTimeout(
|
|
3587
|
-
|
|
3606
|
+
if (timer !== undefined)
|
|
3607
|
+
clearTimeout(timer);
|
|
3608
|
+
timer = setTimeout(checkFocusedControl, settleMs);
|
|
3588
3609
|
};
|
|
3589
3610
|
document.addEventListener("focusin", scheduleCheck, true);
|
|
3590
3611
|
visualViewport.addEventListener("resize", scheduleCheck);
|
|
@@ -3593,8 +3614,8 @@ var createBeacon = (options) => {
|
|
|
3593
3614
|
document.removeEventListener("focusin", scheduleCheck, true);
|
|
3594
3615
|
visualViewport.removeEventListener("resize", scheduleCheck);
|
|
3595
3616
|
visualViewport.removeEventListener("scroll", scheduleCheck);
|
|
3596
|
-
if (
|
|
3597
|
-
clearTimeout(
|
|
3617
|
+
if (timer !== undefined)
|
|
3618
|
+
clearTimeout(timer);
|
|
3598
3619
|
});
|
|
3599
3620
|
}
|
|
3600
3621
|
if (signals.scrollJail !== false) {
|
|
@@ -3651,16 +3672,16 @@ var createBeacon = (options) => {
|
|
|
3651
3672
|
jailBurst = [];
|
|
3652
3673
|
return;
|
|
3653
3674
|
}
|
|
3654
|
-
const
|
|
3675
|
+
const now = Date.now();
|
|
3655
3676
|
if (jailScroller !== scroller) {
|
|
3656
3677
|
jailScroller = scroller;
|
|
3657
3678
|
jailBurst = [];
|
|
3658
3679
|
}
|
|
3659
|
-
jailBurst = jailBurst.filter((entry) =>
|
|
3680
|
+
jailBurst = jailBurst.filter((entry) => now - entry.at < SCROLL_JAIL_WINDOW_MS && !entry.event.defaultPrevented);
|
|
3660
3681
|
if (jailBurst.length === 0) {
|
|
3661
3682
|
jailStartingScrollGeneration = scrollActivityGeneration;
|
|
3662
3683
|
}
|
|
3663
|
-
jailBurst.push({ at:
|
|
3684
|
+
jailBurst.push({ at: now, position: scroller.scrollTop, event });
|
|
3664
3685
|
if (jailBurst.length < SCROLL_JAIL_EVENT_COUNT)
|
|
3665
3686
|
return;
|
|
3666
3687
|
const first = jailBurst[0];
|
|
@@ -3695,7 +3716,7 @@ var createBeacon = (options) => {
|
|
|
3695
3716
|
scroller: descriptor,
|
|
3696
3717
|
direction: scrollingDown ? "down" : "up",
|
|
3697
3718
|
wheelCount: confirmedBurst.length,
|
|
3698
|
-
burstDurationMs:
|
|
3719
|
+
burstDurationMs: now - (confirmedBurst[0]?.at ?? now),
|
|
3699
3720
|
scrollTop: scroller.scrollTop,
|
|
3700
3721
|
scrollHeight: scroller.scrollHeight,
|
|
3701
3722
|
clientHeight: scroller.clientHeight,
|
|
@@ -3744,9 +3765,9 @@ var createBeacon = (options) => {
|
|
|
3744
3765
|
previous = { x: event.clientX, y: event.clientY };
|
|
3745
3766
|
if (Math.hypot(dx, dy) < 8)
|
|
3746
3767
|
return;
|
|
3747
|
-
const
|
|
3748
|
-
points = points.filter((point) =>
|
|
3749
|
-
points.push({ at:
|
|
3768
|
+
const now = Date.now();
|
|
3769
|
+
points = points.filter((point) => now - point.at < THRASHED_CURSOR_WINDOW_MS);
|
|
3770
|
+
points.push({ at: now, dx, dy });
|
|
3750
3771
|
let reversals = 0;
|
|
3751
3772
|
for (let index = 1;index < points.length; index += 1) {
|
|
3752
3773
|
const prior = points[index - 1];
|
|
@@ -3810,8 +3831,8 @@ var createBeacon = (options) => {
|
|
|
3810
3831
|
};
|
|
3811
3832
|
const openModals = () => Array.from(document.querySelectorAll(MODAL_SELECTOR)).filter(isRenderedModal);
|
|
3812
3833
|
const checkInitialModalFocus = (modal) => {
|
|
3813
|
-
const
|
|
3814
|
-
modalTimers.delete(
|
|
3834
|
+
const timer = setTimeout(() => {
|
|
3835
|
+
modalTimers.delete(timer);
|
|
3815
3836
|
if (!isRenderedModal(modal))
|
|
3816
3837
|
return;
|
|
3817
3838
|
const active = document.activeElement instanceof Element ? document.activeElement : null;
|
|
@@ -3819,7 +3840,7 @@ var createBeacon = (options) => {
|
|
|
3819
3840
|
return;
|
|
3820
3841
|
reportModalEscape(modal, active, "initial-focus-missing");
|
|
3821
3842
|
}, MODAL_FOCUS_SETTLE_MS);
|
|
3822
|
-
modalTimers.add(
|
|
3843
|
+
modalTimers.add(timer);
|
|
3823
3844
|
};
|
|
3824
3845
|
const updateModalVisibility = (modal) => {
|
|
3825
3846
|
knownModals.add(modal);
|
|
@@ -3842,8 +3863,8 @@ var createBeacon = (options) => {
|
|
|
3842
3863
|
const modals = openModals();
|
|
3843
3864
|
if (modals.length > 0 && !modals.some((modal) => modal.contains(target))) {
|
|
3844
3865
|
const modal = modals[modals.length - 1];
|
|
3845
|
-
const
|
|
3846
|
-
modalTimers.delete(
|
|
3866
|
+
const timer = setTimeout(() => {
|
|
3867
|
+
modalTimers.delete(timer);
|
|
3847
3868
|
if (!isRenderedModal(modal))
|
|
3848
3869
|
return;
|
|
3849
3870
|
const active = document.activeElement instanceof Element ? document.activeElement : null;
|
|
@@ -3851,7 +3872,7 @@ var createBeacon = (options) => {
|
|
|
3851
3872
|
return;
|
|
3852
3873
|
reportModalEscape(modal, active, "escaped");
|
|
3853
3874
|
}, 0);
|
|
3854
|
-
modalTimers.add(
|
|
3875
|
+
modalTimers.add(timer);
|
|
3855
3876
|
}
|
|
3856
3877
|
}
|
|
3857
3878
|
};
|
|
@@ -3928,8 +3949,8 @@ var createBeacon = (options) => {
|
|
|
3928
3949
|
document.removeEventListener("focusin", onFocusIn, true);
|
|
3929
3950
|
document.removeEventListener("focusout", onFocusOut, true);
|
|
3930
3951
|
modalObserver?.disconnect();
|
|
3931
|
-
for (const
|
|
3932
|
-
clearTimeout(
|
|
3952
|
+
for (const timer of modalTimers)
|
|
3953
|
+
clearTimeout(timer);
|
|
3933
3954
|
modalTimers.clear();
|
|
3934
3955
|
knownModals.clear();
|
|
3935
3956
|
});
|
|
@@ -3974,14 +3995,14 @@ var createBeacon = (options) => {
|
|
|
3974
3995
|
if (data === null)
|
|
3975
3996
|
return;
|
|
3976
3997
|
const activity = activityFor(form);
|
|
3977
|
-
const
|
|
3998
|
+
const now = Date.now();
|
|
3978
3999
|
if (data !== activity.lastData) {
|
|
3979
4000
|
activity.lastData = data;
|
|
3980
|
-
activity.identicalSubmits = [
|
|
4001
|
+
activity.identicalSubmits = [now];
|
|
3981
4002
|
return;
|
|
3982
4003
|
}
|
|
3983
|
-
activity.identicalSubmits = activity.identicalSubmits.filter((at) =>
|
|
3984
|
-
activity.identicalSubmits.push(
|
|
4004
|
+
activity.identicalSubmits = activity.identicalSubmits.filter((at) => now - at < FORM_FRUSTRATION_WINDOW_MS);
|
|
4005
|
+
activity.identicalSubmits.push(now);
|
|
3985
4006
|
if (activity.identicalSubmits.length >= FORM_FRUSTRATION_THRESHOLD) {
|
|
3986
4007
|
reportForm(form, "was submitted with identical values repeatedly");
|
|
3987
4008
|
}
|
|
@@ -3992,14 +4013,14 @@ var createBeacon = (options) => {
|
|
|
3992
4013
|
if (form === null)
|
|
3993
4014
|
return;
|
|
3994
4015
|
const activity = activityFor(form);
|
|
3995
|
-
const
|
|
3996
|
-
if (
|
|
3997
|
-
activity.lastInvalidAt =
|
|
4016
|
+
const now = Date.now();
|
|
4017
|
+
if (now - activity.lastInvalidAt < FORM_INVALID_BURST_GAP_MS) {
|
|
4018
|
+
activity.lastInvalidAt = now;
|
|
3998
4019
|
return;
|
|
3999
4020
|
}
|
|
4000
|
-
activity.lastInvalidAt =
|
|
4001
|
-
activity.invalidBursts = activity.invalidBursts.filter((at) =>
|
|
4002
|
-
activity.invalidBursts.push(
|
|
4021
|
+
activity.lastInvalidAt = now;
|
|
4022
|
+
activity.invalidBursts = activity.invalidBursts.filter((at) => now - at < FORM_FRUSTRATION_WINDOW_MS);
|
|
4023
|
+
activity.invalidBursts.push(now);
|
|
4003
4024
|
if (activity.invalidBursts.length >= FORM_FRUSTRATION_THRESHOLD) {
|
|
4004
4025
|
reportForm(form, "keeps failing native validation");
|
|
4005
4026
|
}
|
|
@@ -4098,9 +4119,9 @@ var createBeacon = (options) => {
|
|
|
4098
4119
|
if (signals.sseFlapping === false || pageLifecycleEnding || document.visibilityState === "hidden") {
|
|
4099
4120
|
return;
|
|
4100
4121
|
}
|
|
4101
|
-
const
|
|
4102
|
-
const errors = (errorsByEndpoint.get(endpointLabel) ?? []).filter((at) =>
|
|
4103
|
-
errors.push(
|
|
4122
|
+
const now = Date.now();
|
|
4123
|
+
const errors = (errorsByEndpoint.get(endpointLabel) ?? []).filter((at) => now - at < sseFlapWindowMs);
|
|
4124
|
+
errors.push(now);
|
|
4104
4125
|
errorsByEndpoint.set(endpointLabel, errors);
|
|
4105
4126
|
if (errors.length < sseFlapCount || reportedFlappingStreams.has(endpointLabel)) {
|
|
4106
4127
|
return;
|
|
@@ -4121,13 +4142,13 @@ var createBeacon = (options) => {
|
|
|
4121
4142
|
};
|
|
4122
4143
|
const originalAddEventListener = source.addEventListener.bind(source);
|
|
4123
4144
|
const armedTypes = new Set(["error", "message", "open"]);
|
|
4124
|
-
source.addEventListener = (type, listener,
|
|
4145
|
+
source.addEventListener = (type, listener, options) => {
|
|
4125
4146
|
if (!armedTypes.has(type)) {
|
|
4126
4147
|
armedTypes.add(type);
|
|
4127
4148
|
originalAddEventListener(type, arm);
|
|
4128
4149
|
}
|
|
4129
4150
|
if (listener !== null) {
|
|
4130
|
-
originalAddEventListener(type, listener,
|
|
4151
|
+
originalAddEventListener(type, listener, options);
|
|
4131
4152
|
}
|
|
4132
4153
|
};
|
|
4133
4154
|
originalAddEventListener("open", arm);
|
|
@@ -4193,10 +4214,10 @@ var createBeacon = (options) => {
|
|
|
4193
4214
|
}
|
|
4194
4215
|
if (signals.socketFlapping === false)
|
|
4195
4216
|
return;
|
|
4196
|
-
const
|
|
4197
|
-
const closes = (closesByUrl.get(label) ?? []).filter((close) =>
|
|
4217
|
+
const now = Date.now();
|
|
4218
|
+
const closes = (closesByUrl.get(label) ?? []).filter((close) => now - close.at < SOCKET_FLAP_WINDOW_MS);
|
|
4198
4219
|
closes.push({
|
|
4199
|
-
at:
|
|
4220
|
+
at: now,
|
|
4200
4221
|
code: typeof CloseEvent !== "undefined" && event instanceof CloseEvent ? event.code : null,
|
|
4201
4222
|
wasClean: typeof CloseEvent !== "undefined" && event instanceof CloseEvent ? event.wasClean : null
|
|
4202
4223
|
});
|
|
@@ -4212,7 +4233,7 @@ var createBeacon = (options) => {
|
|
|
4212
4233
|
windowMs: String(SOCKET_FLAP_WINDOW_MS)
|
|
4213
4234
|
}, undefined, {
|
|
4214
4235
|
closeSamples: closes.map((close) => ({
|
|
4215
|
-
ageMs:
|
|
4236
|
+
ageMs: now - close.at,
|
|
4216
4237
|
code: close.code,
|
|
4217
4238
|
wasClean: close.wasClean
|
|
4218
4239
|
}))
|
|
@@ -4236,14 +4257,14 @@ var createBeacon = (options) => {
|
|
|
4236
4257
|
cleanup();
|
|
4237
4258
|
}
|
|
4238
4259
|
});
|
|
4239
|
-
const reportWorkerFailure = (workerType, endpointLabel,
|
|
4240
|
-
const key = `${workerType}|${endpointLabel}|${
|
|
4260
|
+
const reportWorkerFailure = (workerType, endpointLabel, failureKind, error) => {
|
|
4261
|
+
const key = `${workerType}|${endpointLabel}|${failureKind}`;
|
|
4241
4262
|
if (reportedWorkerFailures.has(key))
|
|
4242
4263
|
return;
|
|
4243
4264
|
reportedWorkerFailures.add(key);
|
|
4244
4265
|
emitSignal(`Worker failure — ${workerType} worker ${endpointLabel} failed — ${shortUrl(location.href)}`, {
|
|
4245
4266
|
endpoint: endpointLabel,
|
|
4246
|
-
failureKind
|
|
4267
|
+
failureKind,
|
|
4247
4268
|
signal: BEACON_SIGNAL.WORKER_FAILURE,
|
|
4248
4269
|
workerType
|
|
4249
4270
|
}, undefined, error === undefined ? undefined : {
|
|
@@ -4330,14 +4351,14 @@ var createBeacon = (options) => {
|
|
|
4330
4351
|
"TimeoutError",
|
|
4331
4352
|
"TypeError"
|
|
4332
4353
|
]);
|
|
4333
|
-
const reportServiceWorkerFailure = (endpointLabel,
|
|
4334
|
-
const key = `${endpointLabel}|${
|
|
4354
|
+
const reportServiceWorkerFailure = (endpointLabel, failureKind, error) => {
|
|
4355
|
+
const key = `${endpointLabel}|${failureKind}`;
|
|
4335
4356
|
if (reportedServiceWorkerFailures.has(key))
|
|
4336
4357
|
return;
|
|
4337
4358
|
reportedServiceWorkerFailures.add(key);
|
|
4338
|
-
emitSignal(`Service worker failure — ${endpointLabel} failed during ${
|
|
4359
|
+
emitSignal(`Service worker failure — ${endpointLabel} failed during ${failureKind} — ${shortUrl(location.href)}`, {
|
|
4339
4360
|
endpoint: endpointLabel,
|
|
4340
|
-
failureKind
|
|
4361
|
+
failureKind,
|
|
4341
4362
|
signal: BEACON_SIGNAL.SERVICE_WORKER_FAILURE
|
|
4342
4363
|
}, undefined, error === undefined ? undefined : {
|
|
4343
4364
|
serviceWorkerError: {
|
|
@@ -4347,12 +4368,15 @@ var createBeacon = (options) => {
|
|
|
4347
4368
|
}
|
|
4348
4369
|
});
|
|
4349
4370
|
};
|
|
4350
|
-
const watchInstallingWorker = (worker) => {
|
|
4351
|
-
let
|
|
4371
|
+
const watchInstallingWorker = (worker, registration) => {
|
|
4372
|
+
let settled = worker.state === "installed" || worker.state === "activated";
|
|
4352
4373
|
const onStateChange = () => {
|
|
4353
|
-
if (worker.state === "activated")
|
|
4354
|
-
|
|
4355
|
-
if (worker.state !== "redundant" ||
|
|
4374
|
+
if (worker.state === "installed" || worker.state === "activated")
|
|
4375
|
+
settled = true;
|
|
4376
|
+
if (worker.state !== "redundant" || settled)
|
|
4377
|
+
return;
|
|
4378
|
+
const successor = registration?.installing ?? registration?.waiting;
|
|
4379
|
+
if (successor !== null && successor !== undefined && successor !== worker)
|
|
4356
4380
|
return;
|
|
4357
4381
|
reportServiceWorkerFailure(shortUrl(worker.scriptURL), "installation");
|
|
4358
4382
|
};
|
|
@@ -4361,11 +4385,11 @@ var createBeacon = (options) => {
|
|
|
4361
4385
|
};
|
|
4362
4386
|
const watchRegistration = (registration) => {
|
|
4363
4387
|
if (registration.installing !== null) {
|
|
4364
|
-
watchInstallingWorker(registration.installing);
|
|
4388
|
+
watchInstallingWorker(registration.installing, registration);
|
|
4365
4389
|
}
|
|
4366
4390
|
const onUpdateFound = () => {
|
|
4367
4391
|
if (registration.installing !== null) {
|
|
4368
|
-
watchInstallingWorker(registration.installing);
|
|
4392
|
+
watchInstallingWorker(registration.installing, registration);
|
|
4369
4393
|
}
|
|
4370
4394
|
};
|
|
4371
4395
|
registration.addEventListener("updatefound", onUpdateFound);
|
|
@@ -4443,23 +4467,23 @@ var createBeacon = (options) => {
|
|
|
4443
4467
|
try {
|
|
4444
4468
|
const navigation = performance.getEntriesByType("navigation")[0];
|
|
4445
4469
|
if (navigation?.type !== "back_forward") {
|
|
4446
|
-
const
|
|
4470
|
+
const now = Date.now();
|
|
4447
4471
|
const route = shortUrl(location.href);
|
|
4448
4472
|
const raw = sessionStorage.getItem(RELOAD_LOOP_STORAGE_KEY);
|
|
4449
4473
|
const parsed = raw === null ? [] : JSON.parse(raw);
|
|
4450
|
-
let history2 = (Array.isArray(parsed) ? parsed : []).filter((entry) => entry !== null && typeof entry === "object" && typeof entry.at === "number" && typeof entry.route === "string" &&
|
|
4474
|
+
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);
|
|
4451
4475
|
let entryKind = "app";
|
|
4452
4476
|
const rawNavigationIntent = sessionStorage.getItem(NAVIGATION_INTENT_STORAGE_KEY);
|
|
4453
4477
|
sessionStorage.removeItem(NAVIGATION_INTENT_STORAGE_KEY);
|
|
4454
4478
|
const navigationIntentAt = Number(rawNavigationIntent);
|
|
4455
|
-
if (rawNavigationIntent !== null && Number.isFinite(navigationIntentAt) &&
|
|
4479
|
+
if (rawNavigationIntent !== null && Number.isFinite(navigationIntentAt) && now - navigationIntentAt >= 0 && now - navigationIntentAt <= NAVIGATION_INTENT_MAX_AGE_MS) {
|
|
4456
4480
|
history2 = [];
|
|
4457
4481
|
entryKind = "intentional-navigation";
|
|
4458
4482
|
}
|
|
4459
4483
|
const rawServiceWorkerUpdateIntent = sessionStorage.getItem(SERVICE_WORKER_UPDATE_INTENT_STORAGE_KEY);
|
|
4460
4484
|
sessionStorage.removeItem(SERVICE_WORKER_UPDATE_INTENT_STORAGE_KEY);
|
|
4461
4485
|
const serviceWorkerUpdateIntentAt = Number(rawServiceWorkerUpdateIntent);
|
|
4462
|
-
if (rawServiceWorkerUpdateIntent !== null && Number.isFinite(serviceWorkerUpdateIntentAt) &&
|
|
4486
|
+
if (rawServiceWorkerUpdateIntent !== null && Number.isFinite(serviceWorkerUpdateIntentAt) && now - serviceWorkerUpdateIntentAt >= 0 && now - serviceWorkerUpdateIntentAt <= NAVIGATION_INTENT_MAX_AGE_MS) {
|
|
4463
4487
|
history2 = [];
|
|
4464
4488
|
entryKind = "service-worker-update";
|
|
4465
4489
|
}
|
|
@@ -4470,7 +4494,7 @@ var createBeacon = (options) => {
|
|
|
4470
4494
|
entryKind = "external";
|
|
4471
4495
|
}
|
|
4472
4496
|
}
|
|
4473
|
-
history2.push({ at:
|
|
4497
|
+
history2.push({ at: now, route });
|
|
4474
4498
|
sessionStorage.setItem(RELOAD_LOOP_STORAGE_KEY, JSON.stringify(history2));
|
|
4475
4499
|
let loadCount = 0;
|
|
4476
4500
|
for (let index = history2.length - 1;index >= 0; index -= 1) {
|
|
@@ -4479,7 +4503,7 @@ var createBeacon = (options) => {
|
|
|
4479
4503
|
loadCount += 1;
|
|
4480
4504
|
}
|
|
4481
4505
|
if (loadCount === RELOAD_LOOP_COUNT) {
|
|
4482
|
-
const firstLoad = history2.at(-loadCount)?.at ??
|
|
4506
|
+
const firstLoad = history2.at(-loadCount)?.at ?? now;
|
|
4483
4507
|
emitSignal(`Reload loop — repeated page loads within a minute — ${shortUrl(location.href)}`, {
|
|
4484
4508
|
currentRelease: options.release ?? "unknown",
|
|
4485
4509
|
entryKind,
|
|
@@ -4488,7 +4512,7 @@ var createBeacon = (options) => {
|
|
|
4488
4512
|
serviceWorkerControlled: String(navigator.serviceWorker?.controller !== null && navigator.serviceWorker?.controller !== undefined),
|
|
4489
4513
|
serviceWorkerScript: navigator.serviceWorker?.controller?.scriptURL ?? "none",
|
|
4490
4514
|
signal: BEACON_SIGNAL.RELOAD_LOOP,
|
|
4491
|
-
windowMs: String(
|
|
4515
|
+
windowMs: String(now - firstLoad)
|
|
4492
4516
|
});
|
|
4493
4517
|
flush(true);
|
|
4494
4518
|
}
|
|
@@ -4498,7 +4522,7 @@ var createBeacon = (options) => {
|
|
|
4498
4522
|
if (signals !== null && signals.staleReleases !== false && typeof localStorage !== "undefined" && typeof options.release === "string" && options.release !== "") {
|
|
4499
4523
|
try {
|
|
4500
4524
|
const currentRelease = options.release;
|
|
4501
|
-
const
|
|
4525
|
+
const now = Date.now();
|
|
4502
4526
|
const raw = localStorage.getItem(STALE_RELEASE_STORAGE_KEY);
|
|
4503
4527
|
const parsed = raw === null ? {} : JSON.parse(raw);
|
|
4504
4528
|
const firstSeenByRelease = {};
|
|
@@ -4508,10 +4532,10 @@ var createBeacon = (options) => {
|
|
|
4508
4532
|
firstSeenByRelease[release] = at;
|
|
4509
4533
|
}
|
|
4510
4534
|
}
|
|
4511
|
-
const currentFirstSeen = firstSeenByRelease[currentRelease] ??
|
|
4535
|
+
const currentFirstSeen = firstSeenByRelease[currentRelease] ?? now;
|
|
4512
4536
|
firstSeenByRelease[currentRelease] = currentFirstSeen;
|
|
4513
4537
|
const newest = Object.entries(firstSeenByRelease).filter(([release, at]) => release !== currentRelease && at > currentFirstSeen).sort((left, right) => right[1] - left[1])[0];
|
|
4514
|
-
if (newest !== undefined &&
|
|
4538
|
+
if (newest !== undefined && now - newest[1] > STALE_RELEASE_GRACE_MS) {
|
|
4515
4539
|
emitSignal(`Stale release — this page is running a build older than one this browser already saw — ${shortUrl(location.href)}`, {
|
|
4516
4540
|
currentRelease,
|
|
4517
4541
|
newestRelease: newest[0],
|
|
@@ -4588,8 +4612,8 @@ var createBeacon = (options) => {
|
|
|
4588
4612
|
return;
|
|
4589
4613
|
if (confirmationMs > 0) {
|
|
4590
4614
|
await new Promise((resolve) => {
|
|
4591
|
-
const
|
|
4592
|
-
cleanups.push(() => window.clearTimeout(
|
|
4615
|
+
const timer = window.setTimeout(resolve, confirmationMs);
|
|
4616
|
+
cleanups.push(() => window.clearTimeout(timer));
|
|
4593
4617
|
});
|
|
4594
4618
|
if (document.visibilityState === "hidden")
|
|
4595
4619
|
return;
|
|
@@ -4631,9 +4655,9 @@ var createBeacon = (options) => {
|
|
|
4631
4655
|
const reportedStorms = new Set;
|
|
4632
4656
|
recordRequestForStorm = (url, method) => {
|
|
4633
4657
|
const label = `${method.toUpperCase()} ${shortUrl(url)}`;
|
|
4634
|
-
const
|
|
4635
|
-
const hits = (hitsByEndpoint.get(label) ?? []).filter((at) =>
|
|
4636
|
-
hits.push(
|
|
4658
|
+
const now = Date.now();
|
|
4659
|
+
const hits = (hitsByEndpoint.get(label) ?? []).filter((at) => now - at < stormWindowMs);
|
|
4660
|
+
hits.push(now);
|
|
4637
4661
|
hitsByEndpoint.set(label, hits);
|
|
4638
4662
|
if (hits.length < stormCount || reportedStorms.has(label))
|
|
4639
4663
|
return;
|
|
@@ -4877,6 +4901,7 @@ var createBeacon = (options) => {
|
|
|
4877
4901
|
captureException,
|
|
4878
4902
|
captureMessage,
|
|
4879
4903
|
close: async () => {
|
|
4904
|
+
closed = true;
|
|
4880
4905
|
for (const cleanup of cleanups.splice(0, cleanups.length))
|
|
4881
4906
|
cleanup();
|
|
4882
4907
|
await flush(true);
|
|
@@ -4918,5 +4943,5 @@ export {
|
|
|
4918
4943
|
redactBeaconEvent
|
|
4919
4944
|
};
|
|
4920
4945
|
|
|
4921
|
-
//# debugId=
|
|
4946
|
+
//# debugId=8F6B8B9D4A41867164756E2164756E21
|
|
4922
4947
|
//# sourceMappingURL=index.js.map
|