@absolutejs/beacon 0.7.0-beta.11 → 0.7.0-beta.12
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 +6 -0
- package/changelog.json +14 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +79 -49
- package/dist/index.js.map +3 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,12 @@ This file is generated by `absolute-changelog` from the entries in
|
|
|
6
6
|
`changelog/`. Edit an entry, not this file — and add new ones under
|
|
7
7
|
`changelog/unreleased/`.
|
|
8
8
|
|
|
9
|
+
## 0.7.0-beta.12 — 2026-09-27
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- **Stop TBT observation after its measurement window and clean up on close; ignore late vital delivery.** (`createBeacon`, `BEACON_SDK_VERSION`)
|
|
14
|
+
|
|
9
15
|
## 0.7.0-beta.11 — 2026-09-27
|
|
10
16
|
|
|
11
17
|
### Fixed
|
package/changelog.json
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
"contract": 1,
|
|
3
3
|
"name": "@absolutejs/beacon",
|
|
4
4
|
"releases": [
|
|
5
|
+
{
|
|
6
|
+
"changes": [
|
|
7
|
+
{
|
|
8
|
+
"kind": "fixed",
|
|
9
|
+
"summary": "Stop TBT observation after its measurement window and clean up on close; ignore late vital delivery.",
|
|
10
|
+
"symbols": [
|
|
11
|
+
"createBeacon",
|
|
12
|
+
"BEACON_SDK_VERSION"
|
|
13
|
+
]
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"date": "2026-09-27",
|
|
17
|
+
"version": "0.7.0-beta.12"
|
|
18
|
+
},
|
|
5
19
|
{
|
|
6
20
|
"changes": [
|
|
7
21
|
{
|
package/dist/index.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export type BeaconLevel = "fatal" | "error" | "warning" | "info";
|
|
|
25
25
|
/** Response header used to correlate a browser signal with its server request. */
|
|
26
26
|
export declare const BEACON_TRACE_HEADER = "x-absolute-trace-id";
|
|
27
27
|
/** Beacon package version retained with every captured event. */
|
|
28
|
-
export declare const BEACON_SDK_VERSION = "0.7.0-beta.
|
|
28
|
+
export declare const BEACON_SDK_VERSION = "0.7.0-beta.12";
|
|
29
29
|
/** Arbitrary event tags, with Beacon's reserved `signal` tag type-checked. */
|
|
30
30
|
export type BeaconTags = Record<string, string> & {
|
|
31
31
|
signal?: BeaconSignal;
|
package/dist/index.js
CHANGED
|
@@ -199,7 +199,7 @@ var consumeEarlyLayoutShiftBuffer = () => {
|
|
|
199
199
|
|
|
200
200
|
// src/index.ts
|
|
201
201
|
var BEACON_TRACE_HEADER = "x-absolute-trace-id";
|
|
202
|
-
var BEACON_SDK_VERSION = "0.7.0-beta.
|
|
202
|
+
var BEACON_SDK_VERSION = "0.7.0-beta.12";
|
|
203
203
|
var inBrowser = () => typeof window !== "undefined";
|
|
204
204
|
var newId = () => {
|
|
205
205
|
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
@@ -765,52 +765,77 @@ var TBT_GOOD_MS = 200;
|
|
|
765
765
|
var TBT_POOR_MS = 600;
|
|
766
766
|
var observeLongTasks = (report, navigationType) => {
|
|
767
767
|
if (typeof PerformanceObserver === "undefined")
|
|
768
|
-
return;
|
|
768
|
+
return () => {};
|
|
769
769
|
const longTasks = [];
|
|
770
|
-
let
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
770
|
+
let observer;
|
|
771
|
+
let timer;
|
|
772
|
+
let stopped = false;
|
|
773
|
+
const firstPaint = () => performance.getEntriesByName("first-contentful-paint")[0]?.startTime;
|
|
774
|
+
const collect = (entries) => {
|
|
775
|
+
if (stopped)
|
|
776
|
+
return;
|
|
777
|
+
const windowStart = firstPaint() ?? 0;
|
|
778
|
+
for (const entry of entries) {
|
|
779
|
+
if (entry.startTime < windowStart || entry.startTime >= windowStart + TBT_WINDOW_MS)
|
|
780
|
+
continue;
|
|
781
|
+
longTasks.push({ duration: entry.duration, startTime: entry.startTime });
|
|
782
|
+
}
|
|
783
|
+
};
|
|
784
|
+
const onVisibilityChange = () => {
|
|
785
|
+
if (document.visibilityState === "hidden")
|
|
786
|
+
flush();
|
|
787
|
+
};
|
|
788
|
+
const stop = () => {
|
|
789
|
+
stopped = true;
|
|
790
|
+
if (timer !== undefined)
|
|
791
|
+
clearTimeout(timer);
|
|
792
|
+
observer?.disconnect();
|
|
793
|
+
window.removeEventListener("visibilitychange", onVisibilityChange);
|
|
794
|
+
window.removeEventListener("pagehide", flush);
|
|
795
|
+
longTasks.length = 0;
|
|
796
|
+
};
|
|
797
|
+
const flush = () => {
|
|
798
|
+
if (stopped)
|
|
799
|
+
return;
|
|
800
|
+
collect(observer?.takeRecords() ?? []);
|
|
801
|
+
const paint = firstPaint();
|
|
802
|
+
const windowStart = paint ?? 0;
|
|
803
|
+
const tasks = longTasks.filter(({ startTime }) => startTime >= windowStart && startTime < windowStart + TBT_WINDOW_MS);
|
|
804
|
+
stop();
|
|
805
|
+
if (tasks.length === 0)
|
|
806
|
+
return;
|
|
807
|
+
const value = Math.round(tasks.reduce((total, { duration }) => total + Math.max(0, duration - LONG_TASK_MS), 0));
|
|
808
|
+
report({
|
|
809
|
+
attribution: {
|
|
810
|
+
measurementWindow: paint === undefined ? "navigation" : "FCP",
|
|
811
|
+
measurementWindowMs: TBT_WINDOW_MS
|
|
812
|
+
},
|
|
813
|
+
id: `tbt-${navigationType}-${TBT_WINDOW_MS}-${value}`,
|
|
814
|
+
name: "TBT",
|
|
815
|
+
navigationType,
|
|
816
|
+
rating: value <= TBT_GOOD_MS ? "good" : value >= TBT_POOR_MS ? "poor" : "needs-improvement",
|
|
817
|
+
value
|
|
783
818
|
});
|
|
819
|
+
};
|
|
820
|
+
const finishWindow = () => {
|
|
821
|
+
if (stopped)
|
|
822
|
+
return;
|
|
823
|
+
const remaining = (firstPaint() ?? 0) + TBT_WINDOW_MS - performance.now();
|
|
824
|
+
if (remaining > 0)
|
|
825
|
+
timer = setTimeout(finishWindow, remaining);
|
|
826
|
+
else
|
|
827
|
+
flush();
|
|
828
|
+
};
|
|
829
|
+
try {
|
|
830
|
+
observer = new PerformanceObserver((list) => collect(list.getEntries()));
|
|
784
831
|
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 {}
|
|
832
|
+
window.addEventListener("visibilitychange", onVisibilityChange);
|
|
833
|
+
window.addEventListener("pagehide", flush);
|
|
834
|
+
timer = setTimeout(finishWindow, Math.max(0, (firstPaint() ?? 0) + TBT_WINDOW_MS - performance.now()));
|
|
835
|
+
} catch {
|
|
836
|
+
stop();
|
|
837
|
+
}
|
|
838
|
+
return stop;
|
|
814
839
|
};
|
|
815
840
|
var isVitalName = (name) => VITAL_NAMES.has(name);
|
|
816
841
|
var vitalAttribution = (value) => {
|
|
@@ -1070,11 +1095,13 @@ var createBeacon = (options) => {
|
|
|
1070
1095
|
}
|
|
1071
1096
|
return false;
|
|
1072
1097
|
};
|
|
1098
|
+
const cleanups = [];
|
|
1099
|
+
let closed = false;
|
|
1073
1100
|
const vitalsOptions = options.vitals === undefined || options.vitals === false ? null : options.vitals === true ? {} : options.vitals;
|
|
1074
1101
|
if (vitalsOptions !== null) {
|
|
1075
1102
|
const vitalsEndpoint = vitalsOptions.endpoint ?? "/ingest/vitals";
|
|
1076
1103
|
const reportVital = (metric) => {
|
|
1077
|
-
if (!isVitalName(metric.name))
|
|
1104
|
+
if (closed || !isVitalName(metric.name))
|
|
1078
1105
|
return;
|
|
1079
1106
|
const replayId = options.getReplayId?.();
|
|
1080
1107
|
const traceId = options.getTraceId?.();
|
|
@@ -1117,17 +1144,19 @@ var createBeacon = (options) => {
|
|
|
1117
1144
|
if (vitalsOptions.webVitals !== undefined) {
|
|
1118
1145
|
observeWebVitals(vitalsOptions.webVitals, reportVital);
|
|
1119
1146
|
} else {
|
|
1120
|
-
loadWebVitals().then((webVitals) =>
|
|
1147
|
+
loadWebVitals().then((webVitals) => {
|
|
1148
|
+
if (!closed)
|
|
1149
|
+
observeWebVitals(webVitals, reportVital);
|
|
1150
|
+
}).catch(() => {
|
|
1121
1151
|
console.warn("[beacon] web-vitals not installed; vitals disabled. `bun add web-vitals`.");
|
|
1122
1152
|
});
|
|
1123
1153
|
}
|
|
1124
1154
|
const navigationEntry = performance.getEntriesByType("navigation")[0];
|
|
1125
1155
|
const navigationType = typeof PerformanceNavigationTiming !== "undefined" && navigationEntry instanceof PerformanceNavigationTiming ? navigationEntry.type : "navigate";
|
|
1126
|
-
observeLongTasks(reportVital, navigationType);
|
|
1156
|
+
cleanups.push(observeLongTasks(reportVital, navigationType));
|
|
1127
1157
|
}
|
|
1128
1158
|
const buffer = [];
|
|
1129
1159
|
const breadcrumbs = [];
|
|
1130
|
-
const cleanups = [];
|
|
1131
1160
|
const pendingClickCleanups = new Set;
|
|
1132
1161
|
cleanups.push(() => {
|
|
1133
1162
|
for (const cleanup of pendingClickCleanups)
|
|
@@ -4877,6 +4906,7 @@ var createBeacon = (options) => {
|
|
|
4877
4906
|
captureException,
|
|
4878
4907
|
captureMessage,
|
|
4879
4908
|
close: async () => {
|
|
4909
|
+
closed = true;
|
|
4880
4910
|
for (const cleanup of cleanups.splice(0, cleanups.length))
|
|
4881
4911
|
cleanup();
|
|
4882
4912
|
await flush(true);
|
|
@@ -4918,5 +4948,5 @@ export {
|
|
|
4918
4948
|
redactBeaconEvent
|
|
4919
4949
|
};
|
|
4920
4950
|
|
|
4921
|
-
//# debugId=
|
|
4951
|
+
//# debugId=508A7FF4EEF1B17D64756E2164756E21
|
|
4922
4952
|
//# sourceMappingURL=index.js.map
|