@absolutejs/beacon 0.7.0-beta.23 → 0.7.0-beta.25

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 CHANGED
@@ -6,6 +6,18 @@ 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.25 — 2026-11-21
10
+
11
+ ### Fixed
12
+
13
+ - **Retain bounded content-free page lifecycle and visibility context on errors and vitals, and guard missing browser policy report types.** (`BEACON_SDK_VERSION`)
14
+
15
+ ## 0.7.0-beta.24 — 2026-11-17
16
+
17
+ ### Fixed
18
+
19
+ - **Preserve safe browser rejection diagnostics instead of empty JSON, handle throwing getters and proxies, and avoid serializing arbitrary rejection payloads or fabricating stacks.** (`BEACON_SDK_VERSION`)
20
+
9
21
  ## 0.7.0-beta.23 — 2026-10-28
10
22
 
11
23
  ### Fixed
package/README.md CHANGED
@@ -398,3 +398,15 @@ Validation: `bun test tests/outbox.test.ts` covers restart recovery, unchanged
398
398
  retry IDs, acknowledgement mismatch, overlapping flushes, capacity/age limits,
399
399
  timeouts and quota failure. Exercised by Hello World's real browser offline /
400
400
  reload / retry workflow.
401
+
402
+ ### Page lifecycle diagnostics
403
+
404
+ Errors include `extra.pageLifecycle`; vital samples include
405
+ `attribution.pageLifecycle`. These content-free snapshots record initial/current
406
+ visibility, readiness, observed hidden duration, visibility changes, back/forward
407
+ cache restores, pagehide state, and at most eight recent transitions. Times are
408
+ monotonic milliseconds since observation began. They do not reconstruct history
409
+ before Beacon initialized or prove that a high paint value meant a blank page.
410
+ No page content, user identifiers, extra request, or polling timer is added.
411
+ Hosts using strict attribution schemas must allow the optional `pageLifecycle`
412
+ object to retain this context. `close()` removes its listeners.
package/changelog.json CHANGED
@@ -2,6 +2,32 @@
2
2
  "contract": 1,
3
3
  "name": "@absolutejs/beacon",
4
4
  "releases": [
5
+ {
6
+ "changes": [
7
+ {
8
+ "kind": "fixed",
9
+ "summary": "Retain bounded content-free page lifecycle and visibility context on errors and vitals, and guard missing browser policy report types.",
10
+ "symbols": [
11
+ "BEACON_SDK_VERSION"
12
+ ]
13
+ }
14
+ ],
15
+ "date": "2026-11-21",
16
+ "version": "0.7.0-beta.25"
17
+ },
18
+ {
19
+ "changes": [
20
+ {
21
+ "kind": "fixed",
22
+ "summary": "Preserve safe browser rejection diagnostics instead of empty JSON, handle throwing getters and proxies, and avoid serializing arbitrary rejection payloads or fabricating stacks.",
23
+ "symbols": [
24
+ "BEACON_SDK_VERSION"
25
+ ]
26
+ }
27
+ ],
28
+ "date": "2026-11-17",
29
+ "version": "0.7.0-beta.24"
30
+ },
5
31
  {
6
32
  "changes": [
7
33
  {
package/dist/index.d.ts CHANGED
@@ -1,23 +1,3 @@
1
- /**
2
- * @absolutejs/beacon — tiny, zero-dependency browser SDK for the AbsoluteJS
3
- * observability stack.
4
- *
5
- * It is deliberately NOT Effect-native: a browser SDK loads on every page for
6
- * every user, so bytes are the dominant cost (measured: an Effect client is
7
- * ~108 KB gz; this is ~2-5 KB gz). The client has no trust boundary — it's a
8
- * dumb producer of telemetry — so the Effect/Schema rigor lives server-side in
9
- * `@absolutejs/errors/ingest`, which validates the untrusted POST body.
10
- *
11
- * Type safety is preserved end-to-end WITHOUT shipping Effect: the envelope
12
- * type below is contract-locked to the ingest endpoint's accepted shape by a
13
- * compile-time assertion in tests (`tests/contract.test.ts`). The type spans
14
- * the wire; the runtime machinery does not.
15
- *
16
- * captureException / global handlers
17
- * → enrich (breadcrumbs, tags, context, replayId)
18
- * → batch
19
- * → flush: POST envelope to /ingest via sendBeacon / fetch keepalive
20
- */
21
1
  export { BEACON_ATTRIBUTE, BEACON_SIGNAL } from "./contracts";
22
2
  export type { BeaconSignal } from "./contracts";
23
3
  import type { BeaconSignal } from "./contracts";
@@ -25,7 +5,7 @@ export type BeaconLevel = "fatal" | "error" | "warning" | "info";
25
5
  /** Response header used to correlate a browser signal with its server request. */
26
6
  export declare const BEACON_TRACE_HEADER = "x-absolute-trace-id";
27
7
  /** Beacon package version retained with every captured event. */
28
- export declare const BEACON_SDK_VERSION = "0.7.0-beta.23";
8
+ export declare const BEACON_SDK_VERSION = "0.7.0-beta.25";
29
9
  /** Arbitrary event tags, with Beacon's reserved `signal` tag type-checked. */
30
10
  export type BeaconTags = Record<string, string> & {
31
11
  signal?: BeaconSignal;
package/dist/index.js CHANGED
@@ -1,3 +1,122 @@
1
+ // src/pageLifecycle.ts
2
+ var observePageLifecycle = () => {
3
+ const started = performance.now();
4
+ const elapsed = () => Math.max(0, Math.round(performance.now() - started));
5
+ const visibility = () => document.visibilityState === "visible" ? "visible" : document.visibilityState === "hidden" ? "hidden" : "unknown";
6
+ const initialVisibility = visibility();
7
+ let state = initialVisibility;
8
+ let hiddenAt = state === "hidden" ? 0 : undefined;
9
+ let hiddenDurationMs = 0;
10
+ let visibilityChanges = 0;
11
+ let bfcacheRestores = 0;
12
+ let pageHidden = false;
13
+ const recentTransitions = [];
14
+ const record = (kind, persisted) => {
15
+ const atMs = elapsed();
16
+ const next = visibility();
17
+ if (next !== state) {
18
+ visibilityChanges = Math.min(visibilityChanges + 1, 1e6);
19
+ if (hiddenAt !== undefined)
20
+ hiddenDurationMs += Math.max(0, atMs - hiddenAt);
21
+ hiddenAt = next === "hidden" ? atMs : undefined;
22
+ state = next;
23
+ }
24
+ recentTransitions.push({
25
+ kind,
26
+ atMs,
27
+ visibility: state,
28
+ ...persisted === undefined ? {} : { persisted }
29
+ });
30
+ if (recentTransitions.length > 8)
31
+ recentTransitions.shift();
32
+ };
33
+ const onVisibility = () => record("visibilitychange");
34
+ const onHide = (event) => {
35
+ pageHidden = true;
36
+ record("pagehide", event.persisted === true);
37
+ };
38
+ const onShow = (event) => {
39
+ pageHidden = false;
40
+ if (event.persisted)
41
+ bfcacheRestores = Math.min(bfcacheRestores + 1, 1e6);
42
+ record("pageshow", event.persisted === true);
43
+ };
44
+ document.addEventListener("visibilitychange", onVisibility);
45
+ window.addEventListener("pagehide", onHide);
46
+ window.addEventListener("pageshow", onShow);
47
+ return {
48
+ snapshot: () => ({
49
+ observationAgeMs: elapsed(),
50
+ initialVisibility,
51
+ visibilityState: visibility(),
52
+ readyState: document.readyState,
53
+ observedHiddenDurationMs: hiddenDurationMs + (hiddenAt === undefined ? 0 : Math.max(0, elapsed() - hiddenAt)),
54
+ visibilityChanges,
55
+ bfcacheRestores,
56
+ pageHidden,
57
+ recentTransitions: recentTransitions.map((item) => ({ ...item }))
58
+ }),
59
+ close: () => {
60
+ document.removeEventListener("visibilitychange", onVisibility);
61
+ window.removeEventListener("pagehide", onHide);
62
+ window.removeEventListener("pageshow", onShow);
63
+ }
64
+ };
65
+ };
66
+
67
+ // src/rejection.ts
68
+ var read = (value, key) => {
69
+ try {
70
+ return value !== null && (typeof value === "object" || typeof value === "function") ? Reflect.get(value, key) : undefined;
71
+ } catch {
72
+ return;
73
+ }
74
+ };
75
+ var isArray = (value) => {
76
+ try {
77
+ return Array.isArray(value);
78
+ } catch {
79
+ return false;
80
+ }
81
+ };
82
+ var text = (value) => typeof value === "string" && value.length > 0 ? value.slice(0, 2048) : undefined;
83
+ var describeRejection = (reason) => {
84
+ const extra = {
85
+ rejectionType: reason === null ? "null" : isArray(reason) ? "array" : typeof reason
86
+ };
87
+ const name = text(read(reason, "name"));
88
+ const message = text(read(reason, "message"));
89
+ const originalStack = read(reason, "stack");
90
+ const stack = typeof originalStack === "string" ? originalStack : undefined;
91
+ const className = text(read(read(reason, "constructor"), "name"));
92
+ if (className)
93
+ extra.rejectionClass = className;
94
+ for (const key of ["code", "type", "status", "statusText", "url"]) {
95
+ const value = read(reason, key);
96
+ if (typeof value === "number" && Number.isFinite(value))
97
+ extra[key] = value;
98
+ else if (text(value))
99
+ extra[key] = text(value);
100
+ }
101
+ const target = read(reason, "target");
102
+ const tag = text(read(target, "tagName"));
103
+ if (tag)
104
+ extra.resourceTag = tag;
105
+ if (tag && ["SCRIPT", "LINK", "IMG", "SOURCE", "VIDEO", "AUDIO"].includes(tag.toUpperCase())) {
106
+ const url = text(read(target, "currentSrc")) ?? text(read(target, "src")) ?? text(read(target, "href"));
107
+ if (url)
108
+ extra.resourceUrl = url;
109
+ }
110
+ const description = message ?? (typeof reason === "string" ? reason : reason === null || typeof reason !== "object" && typeof reason !== "function" ? String(reason) : `Unhandled promise rejection (${name ?? className ?? "object"}${extra.type ? `: ${extra.type}` : ""}${extra.status !== undefined ? `; status ${extra.status}` : ""})`);
111
+ const error = new Error(description);
112
+ error.name = name ?? "UnhandledRejection";
113
+ error.stack = stack;
114
+ const cause = read(reason, "cause");
115
+ if (stack !== undefined && cause !== undefined)
116
+ error.cause = cause;
117
+ return { error, extra };
118
+ };
119
+
1
120
  // src/contracts.ts
2
121
  var BEACON_SIGNAL = {
3
122
  AUTH_FAILURE_STORM: "auth_failure_storm",
@@ -192,7 +311,7 @@ var consumeEarlyLayoutShiftBuffer = () => {
192
311
 
193
312
  // src/index.ts
194
313
  var BEACON_TRACE_HEADER = "x-absolute-trace-id";
195
- var BEACON_SDK_VERSION = "0.7.0-beta.23";
314
+ var BEACON_SDK_VERSION = "0.7.0-beta.25";
196
315
  var inBrowser = () => typeof window !== "undefined";
197
316
  var newId = () => {
198
317
  if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
@@ -1099,7 +1218,8 @@ var createBeacon = (options) => {
1099
1218
  }
1100
1219
  return false;
1101
1220
  };
1102
- const cleanups = [];
1221
+ const lifecycle = observePageLifecycle();
1222
+ const cleanups = [lifecycle.close];
1103
1223
  let closed = false;
1104
1224
  const vitalsOptions = options.vitals === undefined || options.vitals === false ? null : options.vitals === true ? {} : options.vitals;
1105
1225
  if (vitalsOptions !== null) {
@@ -1126,7 +1246,10 @@ var createBeacon = (options) => {
1126
1246
  ...vitalsOptions.sdkVersion === undefined ? {} : { sdkVersion: vitalsOptions.sdkVersion },
1127
1247
  ...traceId === undefined ? {} : { traceId },
1128
1248
  value: metric.value,
1129
- ...vitalAttribution(metric.attribution) === undefined ? {} : { attribution: vitalAttribution(metric.attribution) }
1249
+ attribution: {
1250
+ ...vitalAttribution(metric.attribution),
1251
+ pageLifecycle: lifecycle.snapshot()
1252
+ }
1130
1253
  };
1131
1254
  vitalsOptions.onVital?.(vital);
1132
1255
  if (vitalsOptions.transport !== undefined) {
@@ -1235,6 +1358,7 @@ var createBeacon = (options) => {
1235
1358
  const extra = {
1236
1359
  ...event.extra,
1237
1360
  pageStartedAt,
1361
+ pageLifecycle: lifecycle.snapshot(),
1238
1362
  sdkVersion: BEACON_SDK_VERSION,
1239
1363
  sessionId
1240
1364
  };
@@ -1778,6 +1902,8 @@ var createBeacon = (options) => {
1778
1902
  const reported = new Set;
1779
1903
  const observer = new ReportingObserver((reports) => {
1780
1904
  for (const report of reports) {
1905
+ if (typeof report.type !== "string" || report.type === "")
1906
+ continue;
1781
1907
  const body = report.body;
1782
1908
  const id = typeof body.id === "string" && body.id !== "" ? body.id.slice(0, SIGNAL_TEXT_MAX) : report.type;
1783
1909
  const key = `${report.type}|${id}|${shortUrl(report.url || location.href)}`;
@@ -2026,22 +2152,17 @@ var createBeacon = (options) => {
2026
2152
  if (instrument.unhandledRejections !== false) {
2027
2153
  const onRejection = (event) => {
2028
2154
  const reason = event.reason;
2029
- if (reason instanceof Error) {
2155
+ let nativeError = false;
2156
+ try {
2157
+ nativeError = reason instanceof Error;
2158
+ } catch {}
2159
+ if (nativeError) {
2030
2160
  captureException(reason, { level: "error" });
2031
2161
  reportCapturedErrorClick(reason);
2032
2162
  return;
2033
2163
  }
2034
- if (typeof reason === "object" && reason !== null && typeof reason.stack === "string") {
2035
- captureException(reason, { level: "error" });
2036
- return;
2037
- }
2038
- const message = typeof reason === "string" ? reason : safeStringify(reason);
2039
- captureException(errorWithoutStack("UnhandledRejection", message), {
2040
- extra: {
2041
- rejectionType: reason === null ? "null" : Array.isArray(reason) ? "array" : typeof reason
2042
- },
2043
- level: "error"
2044
- });
2164
+ const { error, extra } = describeRejection(reason);
2165
+ captureException(error, { extra, level: "error" });
2045
2166
  reportErrorClick?.("UnhandledRejection");
2046
2167
  };
2047
2168
  window.addEventListener("unhandledrejection", onRejection);
@@ -5072,5 +5193,5 @@ export {
5072
5193
  redactBeaconEvent
5073
5194
  };
5074
5195
 
5075
- //# debugId=B14B49B1244463DE64756E2164756E21
5196
+ //# debugId=E26A5543E609C9A364756E2164756E21
5076
5197
  //# sourceMappingURL=index.js.map