@absolutejs/beacon 0.6.62 → 0.7.0-beta.1
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 +67 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +27 -11
- package/dist/index.js.map +3 -3
- package/dist/policy.d.ts +210 -0
- package/dist/policy.js +224 -0
- package/dist/policy.js.map +11 -0
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -254,6 +254,73 @@ SSR-safe: imported in a non-DOM environment, `createBeacon` returns a no-op.
|
|
|
254
254
|
Semantic grouping keys require `@absolutejs/errors` 0.7.3 or newer at the
|
|
255
255
|
ingest boundary.
|
|
256
256
|
|
|
257
|
+
## Noise policy (`@absolutejs/beacon/policy`)
|
|
258
|
+
|
|
259
|
+
An issue board is only worth opening if everything on it is real. Every
|
|
260
|
+
application that ships Beacon ends up writing the same `beforeSend` filter — and
|
|
261
|
+
most of what goes in it is not application-specific at all: a stale chunk import
|
|
262
|
+
after a deploy, a theme extension rewriting inline styles before hydration, a
|
|
263
|
+
read that failed while the tab was hidden, a 5xx the server already captured
|
|
264
|
+
with a stack. What differs is a handful of endpoints and hostnames.
|
|
265
|
+
|
|
266
|
+
```ts
|
|
267
|
+
import {
|
|
268
|
+
createNoisePolicy,
|
|
269
|
+
createResourceFailurePolicy,
|
|
270
|
+
reliabilitySignalPreset,
|
|
271
|
+
BEACON_SIGNAL,
|
|
272
|
+
} from "@absolutejs/beacon/policy";
|
|
273
|
+
|
|
274
|
+
const isNoise = createNoisePolicy({
|
|
275
|
+
// Signals these endpoints raise in normal operation: a stream that stays
|
|
276
|
+
// open for a whole shift, an upload that is megabytes by design.
|
|
277
|
+
exemptions: [
|
|
278
|
+
{
|
|
279
|
+
signals: [BEACON_SIGNAL.SLOW_RESPONSE, BEACON_SIGNAL.FETCH_FAILED],
|
|
280
|
+
endpoints: ["/sync", "/stream"],
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
signals: [BEACON_SIGNAL.SLOW_RESPONSE],
|
|
284
|
+
endpoints: ["/api/uploads"],
|
|
285
|
+
methods: ["POST"],
|
|
286
|
+
},
|
|
287
|
+
],
|
|
288
|
+
// A 5xx from here still reports even when the server captured it: a server
|
|
289
|
+
// that stopped answering cannot file its own issue.
|
|
290
|
+
probeEndpoints: ["/api/health"],
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
initBeacon({
|
|
294
|
+
// ...
|
|
295
|
+
signals: reliabilitySignalPreset({
|
|
296
|
+
behavioural,
|
|
297
|
+
recoverableSockets: ["/sync"],
|
|
298
|
+
}),
|
|
299
|
+
instrument: {
|
|
300
|
+
resourceErrors: createResourceFailurePolicy({
|
|
301
|
+
thirdPartyHosts: ["googletagmanager.com", "js.stripe.com"],
|
|
302
|
+
optionalPathPrefixes: ["/uploads/"],
|
|
303
|
+
}),
|
|
304
|
+
},
|
|
305
|
+
beforeSend: (event) => (isNoise(event) ? null : event),
|
|
306
|
+
});
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
Built in, each switchable and individually exported: hidden-tab read failures,
|
|
310
|
+
5xx the server already captured, stale releases the app prompts for itself,
|
|
311
|
+
stale chunk imports, theme-extension hydration mismatches, and third-party
|
|
312
|
+
deprecation reports. `rules` takes application-specific predicates.
|
|
313
|
+
|
|
314
|
+
`reliabilitySignalPreset` turns off the four detectors another system usually
|
|
315
|
+
already owns — browser policy reports (a `report-to` endpoint is canonical),
|
|
316
|
+
document discards, latency (a performance console), stale releases (a service
|
|
317
|
+
worker prompt) — and puts the behavioural detectors behind a consent flag.
|
|
318
|
+
Everything it does not name keeps its Beacon default.
|
|
319
|
+
|
|
320
|
+
This entry point imports nothing from the SDK at runtime: boot-time policy is
|
|
321
|
+
read by the synchronous page graph, and pulling Beacon's runtime in there makes
|
|
322
|
+
the bundler merge the whole SDK back into it, defeating lazy startup.
|
|
323
|
+
|
|
257
324
|
## License
|
|
258
325
|
|
|
259
326
|
BSL-1.1 with a named carveout against hosted error-tracking / session-replay
|
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.
|
|
28
|
+
export declare const BEACON_SDK_VERSION = "0.7.0-beta.1";
|
|
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
|
@@ -79,7 +79,7 @@ var BEACON_ATTRIBUTE = {
|
|
|
79
79
|
|
|
80
80
|
// src/index.ts
|
|
81
81
|
var BEACON_TRACE_HEADER = "x-absolute-trace-id";
|
|
82
|
-
var BEACON_SDK_VERSION = "0.
|
|
82
|
+
var BEACON_SDK_VERSION = "0.7.0-beta.1";
|
|
83
83
|
var inBrowser = () => typeof window !== "undefined";
|
|
84
84
|
var newId = () => {
|
|
85
85
|
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
@@ -486,6 +486,8 @@ var UUID_PATH_SEGMENT = /\b[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-
|
|
|
486
486
|
var LONG_IDENTIFIER_SEGMENT = /\b(?:[0-9a-f]{16,}|\d{8,})\b/giu;
|
|
487
487
|
var VOLATILE_SIGNAL_TAGS = new Set([
|
|
488
488
|
"actionId",
|
|
489
|
+
"actionTrusted",
|
|
490
|
+
"automation",
|
|
489
491
|
"attemptCount",
|
|
490
492
|
"blockingDurationMs",
|
|
491
493
|
"blockingFrameDurationMs",
|
|
@@ -496,9 +498,11 @@ var VOLATILE_SIGNAL_TAGS = new Set([
|
|
|
496
498
|
"durationMs",
|
|
497
499
|
"elapsedMs",
|
|
498
500
|
"errorCount",
|
|
501
|
+
"focusEventTrusted",
|
|
499
502
|
"inputDelayMs",
|
|
500
503
|
"interactionId",
|
|
501
504
|
"interactionAgeMs",
|
|
505
|
+
"lastFocused",
|
|
502
506
|
"loadCount",
|
|
503
507
|
"newestRelease",
|
|
504
508
|
"obscuredPx",
|
|
@@ -975,12 +979,13 @@ var createBeacon = (options) => {
|
|
|
975
979
|
let user;
|
|
976
980
|
let actionSequence = 0;
|
|
977
981
|
let activeAction;
|
|
978
|
-
const beginAction = (type, target) => {
|
|
982
|
+
const beginAction = (type, target, trusted) => {
|
|
979
983
|
actionSequence += 1;
|
|
980
984
|
activeAction = {
|
|
981
985
|
at: Date.now(),
|
|
982
986
|
id: `${sessionId}:${actionSequence}`,
|
|
983
987
|
target,
|
|
988
|
+
trusted,
|
|
984
989
|
type
|
|
985
990
|
};
|
|
986
991
|
};
|
|
@@ -1026,6 +1031,7 @@ var createBeacon = (options) => {
|
|
|
1026
1031
|
...action === undefined ? {} : {
|
|
1027
1032
|
actionId: action.id,
|
|
1028
1033
|
actionTarget: action.target,
|
|
1034
|
+
actionTrusted: String(action.trusted),
|
|
1029
1035
|
actionType: action.type
|
|
1030
1036
|
},
|
|
1031
1037
|
...event.tags
|
|
@@ -1949,7 +1955,7 @@ var createBeacon = (options) => {
|
|
|
1949
1955
|
if (!(target instanceof Element))
|
|
1950
1956
|
return;
|
|
1951
1957
|
const targetName = describeElement(target);
|
|
1952
|
-
beginAction("click", targetName);
|
|
1958
|
+
beginAction("click", targetName, event.isTrusted);
|
|
1953
1959
|
addBreadcrumb({ message: targetName, type: "click" });
|
|
1954
1960
|
if (signals === null)
|
|
1955
1961
|
return;
|
|
@@ -2005,7 +2011,7 @@ var createBeacon = (options) => {
|
|
|
2005
2011
|
if (!(event.target instanceof HTMLFormElement))
|
|
2006
2012
|
return;
|
|
2007
2013
|
const target = describeElement(event.target);
|
|
2008
|
-
beginAction("submit", target);
|
|
2014
|
+
beginAction("submit", target, event.isTrusted);
|
|
2009
2015
|
recentInteraction = {
|
|
2010
2016
|
at: Date.now(),
|
|
2011
2017
|
performanceAt: performance.now(),
|
|
@@ -2020,7 +2026,7 @@ var createBeacon = (options) => {
|
|
|
2020
2026
|
if (!(target instanceof Element))
|
|
2021
2027
|
return;
|
|
2022
2028
|
const targetName = describeElement(target);
|
|
2023
|
-
beginAction("keyboard", targetName);
|
|
2029
|
+
beginAction("keyboard", targetName, event.isTrusted);
|
|
2024
2030
|
recentInteraction = {
|
|
2025
2031
|
at: Date.now(),
|
|
2026
2032
|
performanceAt: performance.now(),
|
|
@@ -3527,19 +3533,29 @@ var createBeacon = (options) => {
|
|
|
3527
3533
|
};
|
|
3528
3534
|
const onFocusOut = (event) => {
|
|
3529
3535
|
const target = event.target;
|
|
3530
|
-
|
|
3531
|
-
if (candidate === null)
|
|
3536
|
+
if (!(target instanceof Element))
|
|
3532
3537
|
return;
|
|
3538
|
+
const dialog = target.closest(DIALOG_SELECTOR);
|
|
3539
|
+
if (dialog === null)
|
|
3540
|
+
return;
|
|
3541
|
+
const dialogDescriptor = describeElement(dialog);
|
|
3542
|
+
const focusEventTrusted = event.isTrusted === true;
|
|
3533
3543
|
setTimeout(() => {
|
|
3534
3544
|
const active = document.activeElement;
|
|
3535
3545
|
const focusDropped = active === null || active === document.body;
|
|
3536
|
-
if (!focusDropped ||
|
|
3546
|
+
if (!focusDropped || target.isConnected)
|
|
3537
3547
|
return;
|
|
3538
|
-
const descriptor = describeElement(
|
|
3548
|
+
const descriptor = describeElement(target);
|
|
3539
3549
|
if (reportedFocusLoss.has(descriptor))
|
|
3540
3550
|
return;
|
|
3541
3551
|
reportedFocusLoss.add(descriptor);
|
|
3542
|
-
emitSignal(`Focus lost — a dialog closed and dropped keyboard focus on body — ${shortUrl(location.href)}`, {
|
|
3552
|
+
emitSignal(`Focus lost — a dialog closed and dropped keyboard focus on body — ${shortUrl(location.href)}`, {
|
|
3553
|
+
dialog: dialogDescriptor,
|
|
3554
|
+
focusEventTrusted: String(focusEventTrusted),
|
|
3555
|
+
lastFocused: descriptor,
|
|
3556
|
+
signal: BEACON_SIGNAL.FOCUS_LOST,
|
|
3557
|
+
...navigator.webdriver === true ? { automation: "webdriver" } : {}
|
|
3558
|
+
});
|
|
3543
3559
|
}, 0);
|
|
3544
3560
|
};
|
|
3545
3561
|
document.addEventListener("focusin", onFocusIn, true);
|
|
@@ -4568,5 +4584,5 @@ export {
|
|
|
4568
4584
|
redactBeaconEvent
|
|
4569
4585
|
};
|
|
4570
4586
|
|
|
4571
|
-
//# debugId=
|
|
4587
|
+
//# debugId=5C89D1E136B8537164756E2164756E21
|
|
4572
4588
|
//# sourceMappingURL=index.js.map
|