@absolutejs/beacon 0.4.18 → 0.5.0

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 CHANGED
@@ -128,6 +128,21 @@ beacon.captureMessage("checkout started", "info");
128
128
  frustration (identical resubmits / repeated native-validation failures).
129
129
  Each is individually toggleable on `signals`, deduped, capped, and exempts
130
130
  `data-beacon-scan="allow"` subtrees where a DOM scan is involved.
131
+ - **Theme and loading contracts** — mark an application boundary with
132
+ `data-beacon-theme="adaptive"` to report large opaque surfaces whose
133
+ luminance polarity contradicts the active light/dark mode. Intentional
134
+ inverted brand/media surfaces use `data-beacon-theme="allow"`. Loading UI
135
+ participates through native `aria-busy`/`role="progressbar"` semantics or
136
+ `data-beacon-loading`, without coupling the SDK to framework class names.
137
+ - **Browser capability failures** — rejected clipboard writes are observed even
138
+ when application code catches them (contents are never read), visible WebGL
139
+ contexts that do not restore after `webglcontextlost` become warnings, and a
140
+ focused editable control stranded behind the mobile visual viewport is
141
+ reported after the keyboard settles.
142
+ - **Embedded-content stalls** — visible iframes explicitly named with
143
+ `data-beacon-embed` report when their initial `load` never arrives. Generic
144
+ cross-origin error pages cannot be inspected, so Beacon deliberately makes no
145
+ stronger claim than the load deadline.
131
146
  - **Actionable network signals** — expected aborts remain breadcrumbs instead of
132
147
  issues; offline, timeout, isolated-endpoint, and multi-endpoint connectivity
133
148
  failures are classified separately. HTTP 429 responses and repeated 401/403
@@ -141,6 +156,20 @@ beacon.captureMessage("checkout started", "info");
141
156
  dedicated/shared worker construction, runtime, and message-decoding failures
142
157
  become replay-linked warnings. Normal socket closes, page teardown, hidden-tab
143
158
  SSE errors, and successfully replaced service workers are exempt.
159
+ - **Attributed reliability signals** — Event Timing identifies genuinely slow
160
+ interactions (without treating an ordinary click timer as latency), Layout
161
+ Instability names shifted elements, and long animation frames include their
162
+ worst script when the browser exposes it. Successful HTTP responses can be
163
+ classified through the host-owned `instrument.classifyResponse` callback for
164
+ GraphQL-style errors without Beacon retaining response bodies.
165
+ - **Lifecycle and platform gaps** — marked empty application roots, marked dirty
166
+ forms abandoned during navigation, marked media errors/stalls, Web Storage and
167
+ IndexedDB failures, discarded documents, bfcache rejection reasons, slow
168
+ static resources, policy reports, connection changes, and opt-in User Timing
169
+ measures are observable. `observeCapability(name, promise)` captures handled
170
+ browser-API rejection while preserving normal promise behavior. Crash reports
171
+ require the server-side Reporting API receiver in `@absolutejs/errors` because
172
+ the page cannot execute after its browser process crashes.
144
173
 
145
174
  ## API
146
175
 
@@ -154,6 +183,7 @@ captureException(error, { groupingKey?, level?, traceId?, spanId?, tags?, extra?
154
183
  captureMessage(message, level?, { groupingKey?, traceId?, spanId?, tags?, extra? })
155
184
  addBreadcrumb({ message, type?, data? })
156
185
  setTags(tags) · setUser(user | null)
186
+ observeCapability(name, promise) => Promise
157
187
  flush() => Promise<void> // buffered events out now
158
188
  close() => Promise<void> // remove listeners + final flush
159
189
 
@@ -163,7 +193,8 @@ BEACON_SIGNAL.SLOW_RESPONSE
163
193
  BEACON_SIGNAL.HTTP_5XX
164
194
  BEACON_TRACE_HEADER // "x-absolute-trace-id"
165
195
 
166
- // Global helpers (no-op until initBeacon): captureException, captureMessage, addBreadcrumb
196
+ // Global helpers (no-op until initBeacon): captureException, captureMessage,
197
+ // addBreadcrumb, observeCapability
167
198
  ```
168
199
 
169
200
  SSR-safe: imported in a non-DOM environment, `createBeacon` returns a no-op.
package/dist/index.d.ts CHANGED
@@ -23,45 +23,79 @@ export type BeaconLevel = "fatal" | "error" | "warning" | "info";
23
23
  export declare const BEACON_SIGNAL: {
24
24
  readonly AUTH_FAILURE_STORM: "auth_failure_storm";
25
25
  readonly BROWSER_INTERVENTION: "browser_intervention";
26
+ readonly BROWSER_POLICY_VIOLATION: "browser_policy_violation";
27
+ readonly BFCACHE_BLOCKED: "bfcache_blocked";
28
+ readonly CAPABILITY_FAILURE: "capability_failure";
29
+ readonly BLANK_APP_ROOT: "blank_app_root";
26
30
  readonly CONSOLE_ERROR: "console_error";
27
31
  readonly CSP_VIOLATION: "csp_violation";
32
+ readonly CLIPBOARD_FAILURE: "clipboard_failure";
28
33
  readonly DEAD_CLICK: "dead_click";
34
+ readonly DISRUPTIVE_LAYOUT_SHIFT: "disruptive_layout_shift";
35
+ readonly DOCUMENT_DISCARDED: "document_discarded";
36
+ readonly ERROR_CLICK: "error_click";
29
37
  readonly FETCH_FAILED: "fetch_failed";
30
38
  readonly FOCUS_LOST: "focus_lost";
31
39
  readonly FONT_FAILURE: "font_failure";
32
40
  readonly FORM_FRUSTRATION: "form_frustration";
41
+ readonly FORM_ABANDONMENT: "form_abandonment";
42
+ readonly FOCUSED_CONTROL_OFFSCREEN: "focused_control_offscreen";
33
43
  readonly HTTP_5XX: "http_5xx";
34
44
  readonly INVISIBLE_TEXT: "invisible_text";
45
+ readonly EMBEDDED_CONTENT_STALLED: "embedded_content_stalled";
35
46
  readonly LAYOUT_OVERFLOW: "layout_overflow";
36
47
  readonly MAIN_THREAD_STALL: "main_thread_stall";
48
+ readonly MEDIA_PLAYBACK_FAILED: "media_playback_failed";
49
+ readonly MEDIA_PLAYBACK_STALLED: "media_playback_stalled";
37
50
  readonly MODAL_FOCUS_ESCAPE: "modal_focus_escape";
38
51
  readonly OCCLUDED_CONTROL: "occluded_control";
39
52
  readonly RAGE_CLICK: "rage_click";
40
53
  readonly RATE_LIMITED: "rate_limited";
54
+ readonly NAVIGATION_STALLED: "navigation_stalled";
41
55
  readonly RELOAD_LOOP: "reload_loop";
42
56
  readonly REQUEST_STORM: "request_storm";
57
+ readonly SEMANTIC_RESPONSE_FAILURE: "semantic_response_failure";
43
58
  readonly SCROLL_JAIL: "scroll_jail";
44
59
  readonly SLOW_RESPONSE: "slow_response";
60
+ readonly SLOW_RESOURCE: "slow_resource";
61
+ readonly SLOW_INTERACTION: "slow_interaction";
45
62
  readonly SOCKET_ABNORMAL_CLOSE: "socket_abnormal_close";
46
63
  readonly SOCKET_FLAPPING: "socket_flapping";
47
64
  readonly SSE_FLAPPING: "sse_flapping";
48
65
  readonly STALE_RELEASE: "stale_release";
49
66
  readonly STALLED_STREAM: "stalled_stream";
50
67
  readonly STUCK_LOADING: "stuck_loading";
68
+ readonly THEME_MISMATCH: "theme_mismatch";
69
+ readonly THRASHED_CURSOR: "thrashed_cursor";
70
+ readonly STORAGE_FAILURE: "storage_failure";
71
+ readonly WEBGL_CONTEXT_LOST: "webgl_context_lost";
51
72
  readonly SERVICE_WORKER_FAILURE: "service_worker_failure";
52
73
  readonly WORKER_FAILURE: "worker_failure";
53
74
  };
54
75
  export type BeaconSignal = (typeof BEACON_SIGNAL)[keyof typeof BEACON_SIGNAL];
55
76
  /** Stable DOM attributes understood by Beacon's instrumentation. */
56
77
  export declare const BEACON_ATTRIBUTE: {
78
+ /** Names an application root whose settled empty state is a failure. */
79
+ readonly APP_ROOT: "data-beacon-app-root";
57
80
  readonly DEAD_CLICK: "data-beacon-dead-click";
58
81
  readonly NAME: "data-beacon-name";
82
+ /** Names an iframe whose initial load should be watched for a stall. */
83
+ readonly EMBED: "data-beacon-embed";
84
+ /** Marks loading UI that should participate in the stuck-loading watchdog. */
85
+ readonly LOADING: "data-beacon-loading";
86
+ /** Names a form whose dirty navigation should be reported as abandonment. */
87
+ readonly FORM: "data-beacon-form";
88
+ /** Names media whose user-visible playback should be watched. */
89
+ readonly MEDIA: "data-beacon-media";
59
90
  /** `="allow"` exempts an element AND its subtree from layout-overflow
60
91
  * detection — for deliberate bleeds (decorative shapes, marquees). */
61
92
  readonly OVERFLOW: "data-beacon-overflow";
62
93
  /** `="allow"` exempts an element AND its subtree from the visual scan
63
94
  * detectors (occluded controls, invisible text, stuck loading). */
64
95
  readonly SCAN: "data-beacon-scan";
96
+ /** `="adaptive"` opts a subtree into theme-polarity checks; `="allow"`
97
+ * exempts an intentional opposite-theme surface and its subtree. */
98
+ readonly THEME: "data-beacon-theme";
65
99
  };
66
100
  /** Response header used to correlate a browser signal with its server request. */
67
101
  export declare const BEACON_TRACE_HEADER = "x-absolute-trace-id";
@@ -139,6 +173,26 @@ export type BeaconInstrumentation = {
139
173
  xhr?: boolean;
140
174
  /** Breadcrumb SPA navigations (`pushState`/`replaceState`/`popstate`). Default true. */
141
175
  history?: boolean;
176
+ /** Record Network Information API changes as breadcrumbs. Default true. */
177
+ networkChanges?: boolean;
178
+ /** Record application-authored Performance API measures as breadcrumbs.
179
+ * Default false because measure names are host-owned. */
180
+ userTiming?: boolean;
181
+ /** Privacy-owned application classifier for successful HTTP responses that
182
+ * encode a semantic failure (for example GraphQL errors in an HTTP 200).
183
+ * Beacon never reads or stores the response body itself. */
184
+ classifyResponse?: (response: Response, request: {
185
+ method: string;
186
+ url: string;
187
+ }) => void | false | {
188
+ groupingKey: string;
189
+ message: string;
190
+ tags?: Record<string, string>;
191
+ } | Promise<void | false | {
192
+ groupingKey: string;
193
+ message: string;
194
+ tags?: Record<string, string>;
195
+ }>;
142
196
  };
143
197
  export type BeaconResourceFailure = {
144
198
  crossOrigin: boolean;
@@ -155,6 +209,12 @@ export type BeaconResourceFailure = {
155
209
  * `console.error`. Each detector is feature-gated and independently tunable.
156
210
  */
157
211
  export type BeaconSignals = {
212
+ /** Back/forward navigations the browser could not restore from bfcache. */
213
+ bfcacheBlocks?: boolean;
214
+ /** Marked application roots that settle without meaningful visible content. */
215
+ blankAppRoots?: boolean;
216
+ /** Delay before an application root is evaluated. Default 3000ms. */
217
+ blankAppRootSettleMs?: number;
158
218
  /** Repeated 401/403 responses from one endpoint inside a short window.
159
219
  * Default true. */
160
220
  authFailureStorms?: boolean;
@@ -164,12 +224,22 @@ export type BeaconSignals = {
164
224
  authFailureStormWindowMs?: number;
165
225
  /** Browser intervention reports surfaced by ReportingObserver. Default true. */
166
226
  browserInterventions?: boolean;
227
+ /** Deprecation, permissions-policy, integrity, and cross-origin policy
228
+ * reports exposed by ReportingObserver. Default true. */
229
+ browserPolicyViolations?: boolean;
167
230
  /** Enforced Content Security Policy violations. Default true. */
168
231
  cspViolations?: boolean;
232
+ /** Rejected clipboard writes, including failures handled by application
233
+ * code. Clipboard contents are never captured. Default true. */
234
+ clipboardFailures?: boolean;
169
235
  /** N rapid clicks in roughly the same spot. Default true. */
170
236
  rageClicks?: boolean;
171
237
  /** An interactive control clicked with no DOM/nav/scroll/focus/request response. Default true. */
172
238
  deadClicks?: boolean;
239
+ /** A user interaction followed shortly by an error. Default true. */
240
+ errorClicks?: boolean;
241
+ /** Correlation window between interaction and error. Default 2000ms. */
242
+ errorClickWindowMs?: number;
173
243
  /** Responses with status >= 500. Default true. */
174
244
  serverErrors?: boolean;
175
245
  /** Responses slower than `slowResponseMs`. Default true. */
@@ -187,6 +257,18 @@ export type BeaconSignals = {
187
257
  /** The same form submitted or failing native validation repeatedly within a
188
258
  * minute — the quiet sibling of a rage click. Default true. */
189
259
  formFrustration?: boolean;
260
+ /** Dirty marked forms left without a successful submission. Default true. */
261
+ formAbandonment?: boolean;
262
+ /** A focused editable control left outside the mobile visual viewport after
263
+ * the on-screen keyboard settles. Default true. */
264
+ focusedControlsOffscreen?: boolean;
265
+ /** Grace period after focus/visual-viewport movement. Default 500ms. */
266
+ focusedControlSettleMs?: number;
267
+ /** Opt-in iframes marked with `data-beacon-embed` that never fire their
268
+ * initial load event. Default true. */
269
+ embeddedContentStalls?: boolean;
270
+ /** Initial iframe load deadline. Default 15000ms. */
271
+ embeddedContentStallMs?: number;
190
272
  /** Sampled scan for text rendered nearly the same color as its opaque
191
273
  * background (theme-token bugs). Default true. */
192
274
  invisibleText?: boolean;
@@ -199,6 +281,12 @@ export type BeaconSignals = {
199
281
  * popovers, drawers) are skipped by design. Default true.
200
282
  */
201
283
  layoutOverflows?: boolean;
284
+ /** Large unexpected Layout Instability API entries with culprit elements. */
285
+ disruptiveLayoutShifts?: boolean;
286
+ /** Individual unexpected shift score that becomes an issue. Default 0.1. */
287
+ disruptiveLayoutShiftMin?: number;
288
+ /** A page reloaded after the browser discarded its previous document. */
289
+ documentDiscards?: boolean;
202
290
  /** Maximum layout-overflow issues reported per page load. Default 5. */
203
291
  layoutOverflowMaxReports?: number;
204
292
  /** Quiet period after load/resize/navigation before the settled visual
@@ -206,6 +294,14 @@ export type BeaconSignals = {
206
294
  layoutOverflowSettleMs?: number;
207
295
  /** Repeated long animation frames/tasks on a visible page. Default true. */
208
296
  mainThreadStalls?: boolean;
297
+ /** Responding interactions that exceed the latency threshold. Default true. */
298
+ slowInteractions?: boolean;
299
+ /** Interaction duration that becomes a warning. Default 1000ms. */
300
+ slowInteractionMs?: number;
301
+ /** Opt-in marked media playback failures and sustained stalls. Default true. */
302
+ mediaFailures?: boolean;
303
+ /** Time continuously waiting/stalled before reporting. Default 10000ms. */
304
+ mediaStallMs?: number;
209
305
  /** Long-frame duration that counts as a main-thread stall. Default 200ms. */
210
306
  mainThreadStallMs?: number;
211
307
  /** Stalls inside the window that trip a report. Default 3. */
@@ -226,6 +322,8 @@ export type BeaconSignals = {
226
322
  /** Several full page loads within a minute — a crash or reload loop.
227
323
  * Default true. */
228
324
  reloadLoops?: boolean;
325
+ /** SPA navigations accepted by a router but never settled. Default true. */
326
+ stalledNavigations?: boolean;
229
327
  /** The same endpoint hit `requestStormCount` times inside
230
328
  * `requestStormWindowMs` — refetch loops and retry storms. Needs the
231
329
  * fetch/XHR instrumentation. Default true. */
@@ -268,6 +366,17 @@ export type BeaconSignals = {
268
366
  /** Age at which a visible loading indicator counts as stuck.
269
367
  * Default 20000ms. */
270
368
  stuckLoadingMs?: number;
369
+ /** Opposite-polarity opaque surfaces inside subtrees explicitly marked
370
+ * `data-beacon-theme="adaptive"`. Default true. */
371
+ themeMismatches?: boolean;
372
+ /** Visible surface area required for theme-polarity checks. Default
373
+ * 10000px². */
374
+ themeMismatchMinArea?: number;
375
+ /** Visible WebGL canvases whose context remains lost after a restoration
376
+ * grace period. Default true. */
377
+ webglContextLosses?: boolean;
378
+ /** Grace period for `webglcontextrestored`. Default 2000ms. */
379
+ webglRestoreGraceMs?: number;
271
380
  /** Dedicated/shared worker construction, runtime, and message decoding
272
381
  * failures. Default true. */
273
382
  workerFailures?: boolean;
@@ -279,6 +388,16 @@ export type BeaconSignals = {
279
388
  navigationResponseMs?: number;
280
389
  /** Slow-response threshold (ms). Default 8000. */
281
390
  slowResponseMs?: number;
391
+ /** Slow successful static resources from Resource Timing. Default true. */
392
+ slowResources?: boolean;
393
+ /** Static resource duration that becomes a warning. Default 5000ms. */
394
+ slowResourceMs?: number;
395
+ /** Browser storage writes and IndexedDB operations that fail. Default true. */
396
+ storageFailures?: boolean;
397
+ /** Erratic desktop pointer movement indicating confusion/waiting. Default true. */
398
+ thrashedCursors?: boolean;
399
+ /** Cursor direction reversals inside the detection window. Default 8. */
400
+ thrashedCursorReversals?: number;
282
401
  };
283
402
  export type BeaconNetworkFailure = {
284
403
  at: number;
@@ -292,6 +411,12 @@ export type BeaconNetworkFailure = {
292
411
  };
293
412
  method: string;
294
413
  online: boolean | null;
414
+ connection?: {
415
+ downlink?: number;
416
+ effectiveType?: string;
417
+ rtt?: number;
418
+ saveData?: boolean;
419
+ };
295
420
  transport: "fetch" | "xhr";
296
421
  visibilityState: string;
297
422
  };
@@ -369,6 +494,8 @@ export type WebVital = {
369
494
  sdkVersion?: string;
370
495
  /** Optional W3C trace correlation. */
371
496
  traceId?: string;
497
+ /** Privacy-bounded field attribution supplied by web-vitals/attribution. */
498
+ attribution?: Record<string, unknown>;
372
499
  };
373
500
  /** Override Web Vital delivery without changing collection semantics. */
374
501
  export type BeaconVitalsTransport = (vital: WebVital) => void | Promise<void>;
@@ -378,6 +505,7 @@ type WebVitalMetric = {
378
505
  rating: string;
379
506
  id: string;
380
507
  navigationType: string;
508
+ attribution?: Record<string, unknown>;
381
509
  };
382
510
  type WebVitalReporter = (callback: (metric: WebVitalMetric) => void) => void;
383
511
  /** The subset of the `web-vitals` package surface beacon uses. */
@@ -425,6 +553,9 @@ export type Beacon = {
425
553
  id?: string;
426
554
  email?: string;
427
555
  } | null) => void;
556
+ /** Observe an application-owned browser capability promise without globally
557
+ * monkey-patching sensitive platform APIs. */
558
+ observeCapability: <T>(name: string, operation: Promise<T>) => Promise<T>;
428
559
  /** Flush buffered events now. */
429
560
  flush: () => Promise<void>;
430
561
  /** Remove all listeners + do a final flush. */
@@ -449,4 +580,6 @@ export declare const addBreadcrumb: (crumb: {
449
580
  type?: Breadcrumb["type"];
450
581
  data?: Record<string, unknown>;
451
582
  }) => void;
583
+ /** Observe an application-owned browser capability against the global beacon. */
584
+ export declare const observeCapability: <T>(name: string, operation: Promise<T>) => Promise<T>;
452
585
  export {};