@absolutejs/beacon 0.6.44 → 0.6.46
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 +5 -1
- package/dist/index.d.ts +20 -12
- package/dist/index.js +46 -17
- package/dist/index.js.map +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -186,7 +186,10 @@ beacon.captureMessage("checkout started", "info");
|
|
|
186
186
|
exposes it; missing browser attribution is labeled explicitly. Layout
|
|
187
187
|
Instability names shifted elements. Successful HTTP responses can be
|
|
188
188
|
classified through the host-owned `instrument.classifyResponse` callback for
|
|
189
|
-
GraphQL-style errors
|
|
189
|
+
GraphQL-style errors. Selected HTTP 4xx/5xx responses can be promoted through
|
|
190
|
+
the opt-in `instrument.classifyErrorResponse` callback when application context
|
|
191
|
+
proves they are internal contract failures. Beacon never retains response
|
|
192
|
+
bodies.
|
|
190
193
|
- **Lifecycle and platform gaps** — marked empty application roots, marked dirty
|
|
191
194
|
forms abandoned during navigation, marked media errors/stalls, Web Storage and
|
|
192
195
|
IndexedDB failures, discarded documents, bfcache rejection reasons, slow
|
|
@@ -216,6 +219,7 @@ close() => Promise<void> // remove listeners + final flush
|
|
|
216
219
|
BEACON_SIGNAL.FETCH_FAILED
|
|
217
220
|
BEACON_SIGNAL.SLOW_RESPONSE
|
|
218
221
|
BEACON_SIGNAL.HTTP_5XX
|
|
222
|
+
BEACON_SIGNAL.HTTP_RESPONSE_FAILURE
|
|
219
223
|
BEACON_TRACE_HEADER // "x-absolute-trace-id"
|
|
220
224
|
|
|
221
225
|
// Global helpers (no-op until initBeacon): captureException, captureMessage,
|
package/dist/index.d.ts
CHANGED
|
@@ -42,6 +42,7 @@ export declare const BEACON_SIGNAL: {
|
|
|
42
42
|
readonly FORM_ABANDONMENT: "form_abandonment";
|
|
43
43
|
readonly FOCUSED_CONTROL_OFFSCREEN: "focused_control_offscreen";
|
|
44
44
|
readonly HTTP_5XX: "http_5xx";
|
|
45
|
+
readonly HTTP_RESPONSE_FAILURE: "http_response_failure";
|
|
45
46
|
readonly INVISIBLE_TEXT: "invisible_text";
|
|
46
47
|
readonly EMBEDDED_CONTENT_STALLED: "embedded_content_stalled";
|
|
47
48
|
readonly LAYOUT_OVERFLOW: "layout_overflow";
|
|
@@ -155,6 +156,16 @@ export type BeaconTransport = (request: {
|
|
|
155
156
|
/** True on unload-time flushes — prefer `navigator.sendBeacon`. */
|
|
156
157
|
useBeacon: boolean;
|
|
157
158
|
}) => void | Promise<void>;
|
|
159
|
+
export type BeaconResponseClassification = {
|
|
160
|
+
groupingKey: string;
|
|
161
|
+
level?: BeaconLevel;
|
|
162
|
+
message: string;
|
|
163
|
+
tags?: Record<string, string>;
|
|
164
|
+
};
|
|
165
|
+
export type BeaconResponseClassifier = (response: Response, request: {
|
|
166
|
+
method: string;
|
|
167
|
+
url: string;
|
|
168
|
+
}) => void | false | BeaconResponseClassification | Promise<void | false | BeaconResponseClassification>;
|
|
158
169
|
export type BeaconInstrumentation = {
|
|
159
170
|
/** `window.onerror` / `error` events. Default true. */
|
|
160
171
|
globalErrors?: boolean;
|
|
@@ -184,18 +195,12 @@ export type BeaconInstrumentation = {
|
|
|
184
195
|
/** Privacy-owned application classifier for successful HTTP responses that
|
|
185
196
|
* encode a semantic failure (for example GraphQL errors in an HTTP 200).
|
|
186
197
|
* Beacon never reads or stores the response body itself. */
|
|
187
|
-
classifyResponse?:
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
tags?: Record<string, string>;
|
|
194
|
-
} | Promise<void | false | {
|
|
195
|
-
groupingKey: string;
|
|
196
|
-
message: string;
|
|
197
|
-
tags?: Record<string, string>;
|
|
198
|
-
}>;
|
|
198
|
+
classifyResponse?: BeaconResponseClassifier;
|
|
199
|
+
/** Opt-in classifier for HTTP responses with status >= 400. Use this when
|
|
200
|
+
* application context can distinguish an internal contract failure carried
|
|
201
|
+
* as 4xx from an expected user/input rejection. Ordinary 4xx responses stay
|
|
202
|
+
* silent by default, and Beacon never reads or stores the body itself. */
|
|
203
|
+
classifyErrorResponse?: BeaconResponseClassifier;
|
|
199
204
|
};
|
|
200
205
|
export type BeaconResourceFailure = {
|
|
201
206
|
crossOrigin: boolean;
|
|
@@ -267,6 +272,9 @@ export type BeaconSignals = {
|
|
|
267
272
|
/** `FontFace` loads that end in `status: "error"` — icon fonts falling back
|
|
268
273
|
* to raw ligature text, custom faces silently missing. Default true. */
|
|
269
274
|
fontFailures?: boolean;
|
|
275
|
+
/** Time a visible failed face must remain unavailable before it is reported.
|
|
276
|
+
* The face is retried at both ends of the window. Default 5000ms. */
|
|
277
|
+
fontFailureConfirmMs?: number;
|
|
270
278
|
/** The same form submitted or failing native validation repeatedly within a
|
|
271
279
|
* minute — the quiet sibling of a rage click. Default true. */
|
|
272
280
|
formFrustration?: boolean;
|
package/dist/index.js
CHANGED
|
@@ -29,6 +29,7 @@ var BEACON_SIGNAL = {
|
|
|
29
29
|
FORM_ABANDONMENT: "form_abandonment",
|
|
30
30
|
FOCUSED_CONTROL_OFFSCREEN: "focused_control_offscreen",
|
|
31
31
|
HTTP_5XX: "http_5xx",
|
|
32
|
+
HTTP_RESPONSE_FAILURE: "http_response_failure",
|
|
32
33
|
INVISIBLE_TEXT: "invisible_text",
|
|
33
34
|
EMBEDDED_CONTENT_STALLED: "embedded_content_stalled",
|
|
34
35
|
LAYOUT_OVERFLOW: "layout_overflow",
|
|
@@ -754,6 +755,7 @@ var createBeacon = (options) => {
|
|
|
754
755
|
const EMBEDDED_CONTENT_STALL_DEFAULT_MS = 15000;
|
|
755
756
|
const WEBGL_RESTORE_GRACE_DEFAULT_MS = 2000;
|
|
756
757
|
const FOCUSED_CONTROL_SETTLE_DEFAULT_MS = 500;
|
|
758
|
+
const FONT_FAILURE_CONFIRM_DEFAULT_MS = 5000;
|
|
757
759
|
const KEYBOARD_VIEWPORT_HEIGHT_RATIO_MAX = 0.8;
|
|
758
760
|
const SCROLL_JAIL_EVENT_COUNT = 8;
|
|
759
761
|
const SCROLL_JAIL_WINDOW_MS = 2000;
|
|
@@ -3918,6 +3920,7 @@ var createBeacon = (options) => {
|
|
|
3918
3920
|
if (signals !== null && signals.fontFailures !== false && typeof document !== "undefined" && "fonts" in document && (typeof navigator === "undefined" || navigator.webdriver !== true)) {
|
|
3919
3921
|
const reportedFonts = new Set;
|
|
3920
3922
|
const checkingFonts = new Set;
|
|
3923
|
+
const confirmationMs = Math.max(0, signals.fontFailureConfirmMs ?? FONT_FAILURE_CONFIRM_DEFAULT_MS);
|
|
3921
3924
|
const normalizedFamily = (family) => family.trim().replace(/^(['"])(.*)\1$/u, "$2").toLowerCase();
|
|
3922
3925
|
const isRendered = (element) => {
|
|
3923
3926
|
for (let current = element;current !== null; current = current.parentElement) {
|
|
@@ -3960,16 +3963,38 @@ var createBeacon = (options) => {
|
|
|
3960
3963
|
if (element === null)
|
|
3961
3964
|
return;
|
|
3962
3965
|
checkingFonts.add(key);
|
|
3963
|
-
const
|
|
3964
|
-
|
|
3966
|
+
const fontAvailable = async (consumer) => {
|
|
3967
|
+
const sample = consumer.textContent?.trim().slice(0, 64) || "BESbswy";
|
|
3968
|
+
const font = `${face.style} ${face.weight} ${face.stretch} 16px ${JSON.stringify(face.family)}`;
|
|
3969
|
+
try {
|
|
3970
|
+
await document.fonts.load(font, sample);
|
|
3971
|
+
return document.fonts.check(font, sample);
|
|
3972
|
+
} catch {
|
|
3973
|
+
return false;
|
|
3974
|
+
}
|
|
3975
|
+
};
|
|
3965
3976
|
try {
|
|
3966
|
-
await
|
|
3967
|
-
|
|
3977
|
+
if (await fontAvailable(element))
|
|
3978
|
+
return;
|
|
3979
|
+
if (confirmationMs > 0) {
|
|
3980
|
+
await new Promise((resolve) => {
|
|
3981
|
+
const timer2 = window.setTimeout(resolve, confirmationMs);
|
|
3982
|
+
cleanups.push(() => window.clearTimeout(timer2));
|
|
3983
|
+
});
|
|
3984
|
+
if (document.visibilityState === "hidden")
|
|
3985
|
+
return;
|
|
3986
|
+
const confirmedElement = affectedElement(face.family);
|
|
3987
|
+
if (confirmedElement === null)
|
|
3988
|
+
return;
|
|
3989
|
+
if (await fontAvailable(confirmedElement))
|
|
3990
|
+
return;
|
|
3991
|
+
reportFontFailure(face, confirmedElement, key);
|
|
3968
3992
|
return;
|
|
3969
|
-
|
|
3993
|
+
}
|
|
3994
|
+
reportFontFailure(face, element, key);
|
|
3995
|
+
} finally {
|
|
3970
3996
|
checkingFonts.delete(key);
|
|
3971
3997
|
}
|
|
3972
|
-
reportFontFailure(face, element, key);
|
|
3973
3998
|
};
|
|
3974
3999
|
const sweepFonts = () => {
|
|
3975
4000
|
document.fonts.forEach((face) => {
|
|
@@ -4015,22 +4040,26 @@ var createBeacon = (options) => {
|
|
|
4015
4040
|
recordRequestForStorm = null;
|
|
4016
4041
|
});
|
|
4017
4042
|
}
|
|
4018
|
-
const
|
|
4019
|
-
const
|
|
4020
|
-
|
|
4043
|
+
const classifyInstrumentedResponse = (response, request) => {
|
|
4044
|
+
const errorResponse = response.status >= 400;
|
|
4045
|
+
const classifier = errorResponse ? instrument.classifyErrorResponse : response.ok ? instrument.classifyResponse : undefined;
|
|
4046
|
+
if (classifier === undefined)
|
|
4021
4047
|
return;
|
|
4048
|
+
const traceId = responseTraceId(response.headers.get(BEACON_TRACE_HEADER));
|
|
4022
4049
|
Promise.resolve(classifier(response.clone(), request)).then((result) => {
|
|
4023
4050
|
if (result === undefined || result === false)
|
|
4024
4051
|
return;
|
|
4025
|
-
captureException(errorWithoutStack("SemanticResponseFailure", result.message), {
|
|
4052
|
+
captureException(errorWithoutStack(errorResponse ? "HttpResponseFailure" : "SemanticResponseFailure", result.message), {
|
|
4026
4053
|
groupingKey: result.groupingKey,
|
|
4027
|
-
level: "warning",
|
|
4054
|
+
level: result.level ?? "warning",
|
|
4028
4055
|
tags: {
|
|
4029
4056
|
endpoint: shortUrl(request.url),
|
|
4030
4057
|
method: request.method.toUpperCase(),
|
|
4031
|
-
signal: BEACON_SIGNAL.SEMANTIC_RESPONSE_FAILURE,
|
|
4058
|
+
signal: errorResponse ? BEACON_SIGNAL.HTTP_RESPONSE_FAILURE : BEACON_SIGNAL.SEMANTIC_RESPONSE_FAILURE,
|
|
4059
|
+
status: String(response.status),
|
|
4032
4060
|
...result.tags ?? {}
|
|
4033
|
-
}
|
|
4061
|
+
},
|
|
4062
|
+
...traceId === undefined ? {} : { traceId }
|
|
4034
4063
|
});
|
|
4035
4064
|
}).catch(() => {});
|
|
4036
4065
|
};
|
|
@@ -4053,7 +4082,7 @@ var createBeacon = (options) => {
|
|
|
4053
4082
|
type: "fetch"
|
|
4054
4083
|
});
|
|
4055
4084
|
reportResponseSignal(url, method, response.status, Date.now() - start, responseTraceId(response.headers.get(BEACON_TRACE_HEADER)));
|
|
4056
|
-
|
|
4085
|
+
classifyInstrumentedResponse(response, { method, url });
|
|
4057
4086
|
return response;
|
|
4058
4087
|
} catch (error) {
|
|
4059
4088
|
const resolved = toError(error);
|
|
@@ -4108,7 +4137,7 @@ var createBeacon = (options) => {
|
|
|
4108
4137
|
});
|
|
4109
4138
|
if (!failed) {
|
|
4110
4139
|
reportResponseSignal(request.url, request.method, this.status, Date.now() - start, responseTraceId(this.getResponseHeader(BEACON_TRACE_HEADER)));
|
|
4111
|
-
if (instrument.classifyResponse !== undefined && this.status >= 200 && this.status < 300 && (this.responseType === "" || this.responseType === "text")) {
|
|
4140
|
+
if ((instrument.classifyResponse !== undefined && this.status >= 200 && this.status < 300 || instrument.classifyErrorResponse !== undefined && this.status >= 400) && (this.responseType === "" || this.responseType === "text")) {
|
|
4112
4141
|
const headers = new Headers;
|
|
4113
4142
|
for (const line of this.getAllResponseHeaders().split(/\r?\n/u)) {
|
|
4114
4143
|
const separator = line.indexOf(":");
|
|
@@ -4116,7 +4145,7 @@ var createBeacon = (options) => {
|
|
|
4116
4145
|
continue;
|
|
4117
4146
|
headers.append(line.slice(0, separator).trim(), line.slice(separator + 1).trim());
|
|
4118
4147
|
}
|
|
4119
|
-
|
|
4148
|
+
classifyInstrumentedResponse(new Response(this.responseText, {
|
|
4120
4149
|
headers,
|
|
4121
4150
|
status: this.status,
|
|
4122
4151
|
statusText: this.statusText
|
|
@@ -4271,5 +4300,5 @@ export {
|
|
|
4271
4300
|
BEACON_ATTRIBUTE
|
|
4272
4301
|
};
|
|
4273
4302
|
|
|
4274
|
-
//# debugId=
|
|
4303
|
+
//# debugId=F6CB1E584C36B1B164756E2164756E21
|
|
4275
4304
|
//# sourceMappingURL=index.js.map
|