@absolutejs/beacon 0.6.35 → 0.6.37
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/dist/index.d.ts +5 -0
- package/dist/index.js +65 -10
- package/dist/index.js.map +3 -3
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -351,6 +351,11 @@ export type BeaconSignals = {
|
|
|
351
351
|
/** Abnormal WebSocket closes (`wasClean: false` or non-normal codes).
|
|
352
352
|
* Default true. */
|
|
353
353
|
socketAbnormalCloses?: boolean;
|
|
354
|
+
/** Endpoints whose client explicitly owns reconnect/resume. An isolated
|
|
355
|
+
* abnormal close is suppressed for matching URLs, while every close still
|
|
356
|
+
* counts toward socket-flapping detection. String patterns are URL/path
|
|
357
|
+
* prefixes; RegExp patterns match the full URL. */
|
|
358
|
+
recoverableSockets?: Array<RegExp | string>;
|
|
354
359
|
/** WebSocket connect/close cycles to one URL tripping a flap report.
|
|
355
360
|
* Default true. */
|
|
356
361
|
socketFlapping?: boolean;
|
package/dist/index.js
CHANGED
|
@@ -3508,10 +3508,12 @@ var createBeacon = (options) => {
|
|
|
3508
3508
|
const closesByUrl = new Map;
|
|
3509
3509
|
const reportedSockets = new Set;
|
|
3510
3510
|
const reportedAbnormalCloses = new Set;
|
|
3511
|
+
const recoverableSocket = (url) => (signals.recoverableSockets ?? []).some((pattern) => typeof pattern === "string" ? url.startsWith(pattern) || shortUrl(url).startsWith(pattern) : pattern.test(url));
|
|
3511
3512
|
const wrappedWebSocket = new Proxy(OriginalWebSocket, {
|
|
3512
3513
|
construct(target, args) {
|
|
3513
3514
|
const socket = Reflect.construct(target, args);
|
|
3514
|
-
const
|
|
3515
|
+
const socketUrl = String(args[0]);
|
|
3516
|
+
const label = shortUrl(socketUrl);
|
|
3515
3517
|
const socketLifecycleGeneration = pageLifecycleGeneration;
|
|
3516
3518
|
let applicationClose = false;
|
|
3517
3519
|
const originalClose = socket.close.bind(socket);
|
|
@@ -3523,7 +3525,7 @@ var createBeacon = (options) => {
|
|
|
3523
3525
|
const restoredLifecycleClose = pageRestoredAt !== undefined && socketLifecycleGeneration < pageLifecycleGeneration && Date.now() - pageRestoredAt <= RESTORED_SOCKET_CLOSE_GRACE_MS;
|
|
3524
3526
|
if (pageLifecycleEnding || applicationClose || restoredLifecycleClose)
|
|
3525
3527
|
return;
|
|
3526
|
-
if (signals.socketAbnormalCloses !== false && typeof CloseEvent !== "undefined" && event instanceof CloseEvent && !event.wasClean) {
|
|
3528
|
+
if (signals.socketAbnormalCloses !== false && typeof CloseEvent !== "undefined" && event instanceof CloseEvent && !event.wasClean && !recoverableSocket(socketUrl)) {
|
|
3527
3529
|
const abnormalKey = `${label}|${event.code}`;
|
|
3528
3530
|
if (!reportedAbnormalCloses.has(abnormalKey)) {
|
|
3529
3531
|
reportedAbnormalCloses.add(abnormalKey);
|
|
@@ -3798,14 +3800,66 @@ var createBeacon = (options) => {
|
|
|
3798
3800
|
localStorage.setItem(STALE_RELEASE_STORAGE_KEY, JSON.stringify(trimmed));
|
|
3799
3801
|
} catch {}
|
|
3800
3802
|
}
|
|
3801
|
-
if (signals !== null && signals.fontFailures !== false && typeof document !== "undefined" && "fonts" in document) {
|
|
3803
|
+
if (signals !== null && signals.fontFailures !== false && typeof document !== "undefined" && "fonts" in document && (typeof navigator === "undefined" || navigator.webdriver !== true)) {
|
|
3802
3804
|
const reportedFonts = new Set;
|
|
3805
|
+
const checkingFonts = new Set;
|
|
3806
|
+
const normalizedFamily = (family) => family.trim().replace(/^(['"])(.*)\1$/u, "$2").toLowerCase();
|
|
3807
|
+
const isRendered = (element) => {
|
|
3808
|
+
for (let current = element;current !== null; current = current.parentElement) {
|
|
3809
|
+
const style = window.getComputedStyle(current);
|
|
3810
|
+
if (style.display === "none" || style.visibility === "hidden" || style.visibility === "collapse" || Number.parseFloat(style.opacity || "1") <= 0.01) {
|
|
3811
|
+
return false;
|
|
3812
|
+
}
|
|
3813
|
+
}
|
|
3814
|
+
const rect = element.getBoundingClientRect();
|
|
3815
|
+
return rect.width > 0 && rect.height > 0;
|
|
3816
|
+
};
|
|
3817
|
+
const affectedElement = (family) => {
|
|
3818
|
+
const expected = normalizedFamily(family);
|
|
3819
|
+
for (const element of document.querySelectorAll("body *")) {
|
|
3820
|
+
if (!isRendered(element))
|
|
3821
|
+
continue;
|
|
3822
|
+
const style = window.getComputedStyle(element);
|
|
3823
|
+
const families = style.fontFamily.split(",").map(normalizedFamily);
|
|
3824
|
+
if (families.includes(expected))
|
|
3825
|
+
return element;
|
|
3826
|
+
}
|
|
3827
|
+
return null;
|
|
3828
|
+
};
|
|
3829
|
+
const reportFontFailure = (face, element, key) => {
|
|
3830
|
+
reportedFonts.add(key);
|
|
3831
|
+
emitSignal(`Font failure — ${face.family} failed to load — ${shortUrl(location.href)}`, {
|
|
3832
|
+
fontFamily: face.family,
|
|
3833
|
+
fontStretch: face.stretch,
|
|
3834
|
+
fontStyle: face.style,
|
|
3835
|
+
fontWeight: face.weight,
|
|
3836
|
+
signal: BEACON_SIGNAL.FONT_FAILURE,
|
|
3837
|
+
target: describeElement(element)
|
|
3838
|
+
});
|
|
3839
|
+
};
|
|
3840
|
+
const verifyFontFailure = async (face) => {
|
|
3841
|
+
const key = [face.family, face.style, face.weight, face.stretch].join("|");
|
|
3842
|
+
if (reportedFonts.has(key) || checkingFonts.has(key))
|
|
3843
|
+
return;
|
|
3844
|
+
const element = affectedElement(face.family);
|
|
3845
|
+
if (element === null)
|
|
3846
|
+
return;
|
|
3847
|
+
checkingFonts.add(key);
|
|
3848
|
+
const sample = element.textContent?.trim().slice(0, 64) || "BESbswy";
|
|
3849
|
+
const font = `${face.style} ${face.weight} ${face.stretch} 16px ${JSON.stringify(face.family)}`;
|
|
3850
|
+
try {
|
|
3851
|
+
await document.fonts.load(font, sample);
|
|
3852
|
+
if (document.fonts.check(font, sample))
|
|
3853
|
+
return;
|
|
3854
|
+
} catch {} finally {
|
|
3855
|
+
checkingFonts.delete(key);
|
|
3856
|
+
}
|
|
3857
|
+
reportFontFailure(face, element, key);
|
|
3858
|
+
};
|
|
3803
3859
|
const sweepFonts = () => {
|
|
3804
3860
|
document.fonts.forEach((face) => {
|
|
3805
|
-
if (face.status
|
|
3806
|
-
|
|
3807
|
-
reportedFonts.add(face.family);
|
|
3808
|
-
emitSignal(`Font failure — ${face.family} failed to load — ${shortUrl(location.href)}`, { fontFamily: face.family, signal: BEACON_SIGNAL.FONT_FAILURE });
|
|
3861
|
+
if (face.status === "error")
|
|
3862
|
+
verifyFontFailure(face);
|
|
3809
3863
|
});
|
|
3810
3864
|
};
|
|
3811
3865
|
const fontsReady = document.fonts.ready;
|
|
@@ -3815,8 +3869,9 @@ var createBeacon = (options) => {
|
|
|
3815
3869
|
});
|
|
3816
3870
|
}
|
|
3817
3871
|
if (typeof document.fonts.addEventListener === "function") {
|
|
3818
|
-
|
|
3819
|
-
|
|
3872
|
+
const handleLoadingError = () => sweepFonts();
|
|
3873
|
+
document.fonts.addEventListener("loadingerror", handleLoadingError);
|
|
3874
|
+
cleanups.push(() => document.fonts.removeEventListener("loadingerror", handleLoadingError));
|
|
3820
3875
|
}
|
|
3821
3876
|
}
|
|
3822
3877
|
if (signals !== null && signals.requestStorms !== false) {
|
|
@@ -4079,5 +4134,5 @@ export {
|
|
|
4079
4134
|
BEACON_ATTRIBUTE
|
|
4080
4135
|
};
|
|
4081
4136
|
|
|
4082
|
-
//# debugId=
|
|
4137
|
+
//# debugId=E29B0984FFB5596E64756E2164756E21
|
|
4083
4138
|
//# sourceMappingURL=index.js.map
|