@absolutejs/beacon 0.4.19 → 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 +17 -1
- package/dist/index.d.ts +97 -0
- package/dist/index.js +676 -14
- package/dist/index.js.map +3 -3
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -10,28 +10,42 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
10
10
|
var BEACON_SIGNAL = {
|
|
11
11
|
AUTH_FAILURE_STORM: "auth_failure_storm",
|
|
12
12
|
BROWSER_INTERVENTION: "browser_intervention",
|
|
13
|
+
BROWSER_POLICY_VIOLATION: "browser_policy_violation",
|
|
14
|
+
BFCACHE_BLOCKED: "bfcache_blocked",
|
|
15
|
+
CAPABILITY_FAILURE: "capability_failure",
|
|
16
|
+
BLANK_APP_ROOT: "blank_app_root",
|
|
13
17
|
CONSOLE_ERROR: "console_error",
|
|
14
18
|
CSP_VIOLATION: "csp_violation",
|
|
15
19
|
CLIPBOARD_FAILURE: "clipboard_failure",
|
|
16
20
|
DEAD_CLICK: "dead_click",
|
|
21
|
+
DISRUPTIVE_LAYOUT_SHIFT: "disruptive_layout_shift",
|
|
22
|
+
DOCUMENT_DISCARDED: "document_discarded",
|
|
23
|
+
ERROR_CLICK: "error_click",
|
|
17
24
|
FETCH_FAILED: "fetch_failed",
|
|
18
25
|
FOCUS_LOST: "focus_lost",
|
|
19
26
|
FONT_FAILURE: "font_failure",
|
|
20
27
|
FORM_FRUSTRATION: "form_frustration",
|
|
28
|
+
FORM_ABANDONMENT: "form_abandonment",
|
|
21
29
|
FOCUSED_CONTROL_OFFSCREEN: "focused_control_offscreen",
|
|
22
30
|
HTTP_5XX: "http_5xx",
|
|
23
31
|
INVISIBLE_TEXT: "invisible_text",
|
|
24
32
|
EMBEDDED_CONTENT_STALLED: "embedded_content_stalled",
|
|
25
33
|
LAYOUT_OVERFLOW: "layout_overflow",
|
|
26
34
|
MAIN_THREAD_STALL: "main_thread_stall",
|
|
35
|
+
MEDIA_PLAYBACK_FAILED: "media_playback_failed",
|
|
36
|
+
MEDIA_PLAYBACK_STALLED: "media_playback_stalled",
|
|
27
37
|
MODAL_FOCUS_ESCAPE: "modal_focus_escape",
|
|
28
38
|
OCCLUDED_CONTROL: "occluded_control",
|
|
29
39
|
RAGE_CLICK: "rage_click",
|
|
30
40
|
RATE_LIMITED: "rate_limited",
|
|
41
|
+
NAVIGATION_STALLED: "navigation_stalled",
|
|
31
42
|
RELOAD_LOOP: "reload_loop",
|
|
32
43
|
REQUEST_STORM: "request_storm",
|
|
44
|
+
SEMANTIC_RESPONSE_FAILURE: "semantic_response_failure",
|
|
33
45
|
SCROLL_JAIL: "scroll_jail",
|
|
34
46
|
SLOW_RESPONSE: "slow_response",
|
|
47
|
+
SLOW_RESOURCE: "slow_resource",
|
|
48
|
+
SLOW_INTERACTION: "slow_interaction",
|
|
35
49
|
SOCKET_ABNORMAL_CLOSE: "socket_abnormal_close",
|
|
36
50
|
SOCKET_FLAPPING: "socket_flapping",
|
|
37
51
|
SSE_FLAPPING: "sse_flapping",
|
|
@@ -39,15 +53,20 @@ var BEACON_SIGNAL = {
|
|
|
39
53
|
STALLED_STREAM: "stalled_stream",
|
|
40
54
|
STUCK_LOADING: "stuck_loading",
|
|
41
55
|
THEME_MISMATCH: "theme_mismatch",
|
|
56
|
+
THRASHED_CURSOR: "thrashed_cursor",
|
|
57
|
+
STORAGE_FAILURE: "storage_failure",
|
|
42
58
|
WEBGL_CONTEXT_LOST: "webgl_context_lost",
|
|
43
59
|
SERVICE_WORKER_FAILURE: "service_worker_failure",
|
|
44
60
|
WORKER_FAILURE: "worker_failure"
|
|
45
61
|
};
|
|
46
62
|
var BEACON_ATTRIBUTE = {
|
|
63
|
+
APP_ROOT: "data-beacon-app-root",
|
|
47
64
|
DEAD_CLICK: "data-beacon-dead-click",
|
|
48
65
|
NAME: "data-beacon-name",
|
|
49
66
|
EMBED: "data-beacon-embed",
|
|
50
67
|
LOADING: "data-beacon-loading",
|
|
68
|
+
FORM: "data-beacon-form",
|
|
69
|
+
MEDIA: "data-beacon-media",
|
|
51
70
|
OVERFLOW: "data-beacon-overflow",
|
|
52
71
|
SCAN: "data-beacon-scan",
|
|
53
72
|
THEME: "data-beacon-theme"
|
|
@@ -490,8 +509,37 @@ var observeLongTasks = (report, navigationType) => {
|
|
|
490
509
|
} catch {}
|
|
491
510
|
};
|
|
492
511
|
var isVitalName = (name) => VITAL_NAMES.has(name);
|
|
512
|
+
var vitalAttribution = (value) => {
|
|
513
|
+
if (value === undefined)
|
|
514
|
+
return;
|
|
515
|
+
const allowed = [
|
|
516
|
+
"element",
|
|
517
|
+
"elementRenderDelay",
|
|
518
|
+
"inputDelay",
|
|
519
|
+
"interactionTarget",
|
|
520
|
+
"interactionType",
|
|
521
|
+
"largestShiftTarget",
|
|
522
|
+
"largestShiftValue",
|
|
523
|
+
"loadState",
|
|
524
|
+
"presentationDelay",
|
|
525
|
+
"processingDuration",
|
|
526
|
+
"resourceLoadDelay",
|
|
527
|
+
"resourceLoadDuration",
|
|
528
|
+
"timeToFirstByte",
|
|
529
|
+
"url"
|
|
530
|
+
];
|
|
531
|
+
const result = {};
|
|
532
|
+
for (const key of allowed) {
|
|
533
|
+
const item = value[key];
|
|
534
|
+
if (typeof item === "string")
|
|
535
|
+
result[key] = item.slice(0, 300);
|
|
536
|
+
else if (typeof item === "number" || typeof item === "boolean")
|
|
537
|
+
result[key] = item;
|
|
538
|
+
}
|
|
539
|
+
return Object.keys(result).length === 0 ? undefined : result;
|
|
540
|
+
};
|
|
493
541
|
var loadWebVitals = async () => {
|
|
494
|
-
const mod = await import("web-vitals");
|
|
542
|
+
const mod = await import("web-vitals/attribution");
|
|
495
543
|
return mod;
|
|
496
544
|
};
|
|
497
545
|
var observeWebVitals = (webVitals, report) => {
|
|
@@ -507,6 +555,7 @@ var noopBeacon = {
|
|
|
507
555
|
captureMessage: () => {},
|
|
508
556
|
close: async () => {},
|
|
509
557
|
flush: async () => {},
|
|
558
|
+
observeCapability: async (_name, operation) => operation,
|
|
510
559
|
setTags: () => {},
|
|
511
560
|
setUser: () => {}
|
|
512
561
|
};
|
|
@@ -548,6 +597,14 @@ var createBeacon = (options) => {
|
|
|
548
597
|
const RAGE_WINDOW_MS = 1000;
|
|
549
598
|
const RAGE_RADIUS_PX = 40;
|
|
550
599
|
const DEAD_CLICK_WINDOW_MS = 1500;
|
|
600
|
+
const ERROR_CLICK_WINDOW_DEFAULT_MS = 2000;
|
|
601
|
+
const SLOW_INTERACTION_DEFAULT_MS = 1000;
|
|
602
|
+
const BLANK_APP_ROOT_SETTLE_DEFAULT_MS = 3000;
|
|
603
|
+
const DISRUPTIVE_LAYOUT_SHIFT_DEFAULT_MIN = 0.1;
|
|
604
|
+
const SLOW_RESOURCE_DEFAULT_MS = 5000;
|
|
605
|
+
const MEDIA_STALL_DEFAULT_MS = 1e4;
|
|
606
|
+
const THRASHED_CURSOR_DEFAULT_REVERSALS = 8;
|
|
607
|
+
const THRASHED_CURSOR_WINDOW_MS = 2000;
|
|
551
608
|
const NAVIGATION_RESPONSE_DEFAULT_MS = 8000;
|
|
552
609
|
const LAYOUT_OVERFLOW_SETTLE_DEFAULT_MS = 600;
|
|
553
610
|
const LAYOUT_OVERFLOW_MAX_REPORTS_DEFAULT = 5;
|
|
@@ -604,6 +661,9 @@ var createBeacon = (options) => {
|
|
|
604
661
|
let externalNavigationCount = 0;
|
|
605
662
|
let inSignalConsole = false;
|
|
606
663
|
let pageLifecycleEnding = false;
|
|
664
|
+
let recentInteraction;
|
|
665
|
+
let reportErrorClick = null;
|
|
666
|
+
let reportFormAbandonmentOnNavigation = null;
|
|
607
667
|
let overflowScanOnNavigation = null;
|
|
608
668
|
let recordRequestForStorm = null;
|
|
609
669
|
const OVERLAY_VIEWPORT_COVERAGE_MIN = 0.9;
|
|
@@ -655,7 +715,8 @@ var createBeacon = (options) => {
|
|
|
655
715
|
schemaVersion: vitalsOptions.schemaVersion ?? 1,
|
|
656
716
|
...vitalsOptions.sdkVersion === undefined ? {} : { sdkVersion: vitalsOptions.sdkVersion },
|
|
657
717
|
...traceId === undefined ? {} : { traceId },
|
|
658
|
-
value: metric.value
|
|
718
|
+
value: metric.value,
|
|
719
|
+
...vitalAttribution(metric.attribution) === undefined ? {} : { attribution: vitalAttribution(metric.attribution) }
|
|
659
720
|
};
|
|
660
721
|
vitalsOptions.onVital?.(vital);
|
|
661
722
|
if (vitalsOptions.transport !== undefined) {
|
|
@@ -697,6 +758,17 @@ var createBeacon = (options) => {
|
|
|
697
758
|
let flushPendingNetworkFailures = () => {};
|
|
698
759
|
let tags = {};
|
|
699
760
|
let user;
|
|
761
|
+
let actionSequence = 0;
|
|
762
|
+
let activeAction;
|
|
763
|
+
const beginAction = (type, target) => {
|
|
764
|
+
actionSequence += 1;
|
|
765
|
+
activeAction = {
|
|
766
|
+
at: Date.now(),
|
|
767
|
+
id: `${sessionId}:${actionSequence}`,
|
|
768
|
+
target,
|
|
769
|
+
type
|
|
770
|
+
};
|
|
771
|
+
};
|
|
700
772
|
const flush = async (useBeacon = false) => {
|
|
701
773
|
flushPendingNetworkFailures();
|
|
702
774
|
if (buffer.length === 0)
|
|
@@ -733,7 +805,16 @@ var createBeacon = (options) => {
|
|
|
733
805
|
const replayId = options.getReplayId?.();
|
|
734
806
|
if (replayId !== undefined)
|
|
735
807
|
enriched.replayId = replayId;
|
|
736
|
-
const
|
|
808
|
+
const action = activeAction !== undefined && Date.now() - activeAction.at <= 1e4 ? activeAction : undefined;
|
|
809
|
+
const mergedTags = {
|
|
810
|
+
...tags,
|
|
811
|
+
...action === undefined ? {} : {
|
|
812
|
+
actionId: action.id,
|
|
813
|
+
actionTarget: action.target,
|
|
814
|
+
actionType: action.type
|
|
815
|
+
},
|
|
816
|
+
...event.tags
|
|
817
|
+
};
|
|
737
818
|
if (Object.keys(mergedTags).length > 0)
|
|
738
819
|
enriched.tags = mergedTags;
|
|
739
820
|
const extra = { sessionId, ...event.extra };
|
|
@@ -821,6 +902,41 @@ var createBeacon = (options) => {
|
|
|
821
902
|
...extra !== undefined ? { extra } : {}
|
|
822
903
|
});
|
|
823
904
|
};
|
|
905
|
+
if (signals !== null && signals.errorClicks !== false) {
|
|
906
|
+
const windowMs = signals.errorClickWindowMs ?? ERROR_CLICK_WINDOW_DEFAULT_MS;
|
|
907
|
+
reportErrorClick = (errorName) => {
|
|
908
|
+
const interaction = recentInteraction;
|
|
909
|
+
if (interaction === undefined || Date.now() - interaction.at > windowMs)
|
|
910
|
+
return;
|
|
911
|
+
recentInteraction = undefined;
|
|
912
|
+
emitSignal(`Error click — ${interaction.target} — ${shortUrl(location.href)}`, {
|
|
913
|
+
errorName,
|
|
914
|
+
interactionType: interaction.type,
|
|
915
|
+
signal: BEACON_SIGNAL.ERROR_CLICK,
|
|
916
|
+
target: interaction.target
|
|
917
|
+
});
|
|
918
|
+
};
|
|
919
|
+
cleanups.push(() => {
|
|
920
|
+
reportErrorClick = null;
|
|
921
|
+
});
|
|
922
|
+
}
|
|
923
|
+
const observeCapability = async (name, operation) => {
|
|
924
|
+
try {
|
|
925
|
+
return await operation;
|
|
926
|
+
} catch (error) {
|
|
927
|
+
const resolved = toError(error);
|
|
928
|
+
captureException(errorWithoutStack("CapabilityFailure", `Browser capability failed — ${name}`), {
|
|
929
|
+
groupingKey: `browser-capability:${name}`,
|
|
930
|
+
level: "warning",
|
|
931
|
+
tags: {
|
|
932
|
+
capability: name.slice(0, SIGNAL_TEXT_MAX),
|
|
933
|
+
errorName: resolved.name,
|
|
934
|
+
signal: BEACON_SIGNAL.CAPABILITY_FAILURE
|
|
935
|
+
}
|
|
936
|
+
});
|
|
937
|
+
throw error;
|
|
938
|
+
}
|
|
939
|
+
};
|
|
824
940
|
const responseTraceId = (value) => {
|
|
825
941
|
const traceId = value?.trim().toLowerCase();
|
|
826
942
|
return traceId !== undefined && /^[0-9a-f]{32}$/.test(traceId) ? traceId : undefined;
|
|
@@ -893,7 +1009,16 @@ var createBeacon = (options) => {
|
|
|
893
1009
|
let networkFailureTimer;
|
|
894
1010
|
const networkState = () => {
|
|
895
1011
|
const online = typeof navigator.onLine === "boolean" ? navigator.onLine : null;
|
|
1012
|
+
const connection = navigator.connection;
|
|
896
1013
|
return {
|
|
1014
|
+
...connection === undefined ? {} : {
|
|
1015
|
+
connection: {
|
|
1016
|
+
...typeof connection.downlink === "number" ? { downlink: connection.downlink } : {},
|
|
1017
|
+
...typeof connection.effectiveType === "string" ? { effectiveType: connection.effectiveType } : {},
|
|
1018
|
+
...typeof connection.rtt === "number" ? { rtt: connection.rtt } : {},
|
|
1019
|
+
...typeof connection.saveData === "boolean" ? { saveData: connection.saveData } : {}
|
|
1020
|
+
}
|
|
1021
|
+
},
|
|
897
1022
|
online,
|
|
898
1023
|
visibilityState: typeof document.visibilityState === "string" ? document.visibilityState : "unknown"
|
|
899
1024
|
};
|
|
@@ -988,6 +1113,7 @@ var createBeacon = (options) => {
|
|
|
988
1113
|
},
|
|
989
1114
|
method: method.toUpperCase(),
|
|
990
1115
|
online: state.online,
|
|
1116
|
+
...state.connection === undefined ? {} : { connection: state.connection },
|
|
991
1117
|
transport: transportKind,
|
|
992
1118
|
visibilityState: state.visibilityState
|
|
993
1119
|
};
|
|
@@ -1018,7 +1144,7 @@ var createBeacon = (options) => {
|
|
|
1018
1144
|
routerAcceptedNavigation = control instanceof HTMLAnchorElement && handledEvent.defaultPrevented;
|
|
1019
1145
|
};
|
|
1020
1146
|
const responded = () => mutated || formStateChanged(formBefore) || location.href !== urlBefore || window.scrollY !== scrollBefore || document.activeElement !== activeBefore || networkRequestCount !== networkRequestsBefore || externalNavigationCount !== externalNavigationsBefore;
|
|
1021
|
-
const finish = (didRespond) => {
|
|
1147
|
+
const finish = (didRespond, navigationStalled = false) => {
|
|
1022
1148
|
if (finished)
|
|
1023
1149
|
return;
|
|
1024
1150
|
finished = true;
|
|
@@ -1027,7 +1153,7 @@ var createBeacon = (options) => {
|
|
|
1027
1153
|
if (timer2 !== undefined)
|
|
1028
1154
|
window.clearTimeout(timer2);
|
|
1029
1155
|
pendingClickCleanups.delete(cancel);
|
|
1030
|
-
report(didRespond);
|
|
1156
|
+
report(didRespond, navigationStalled);
|
|
1031
1157
|
};
|
|
1032
1158
|
const cancel = () => {
|
|
1033
1159
|
if (finished)
|
|
@@ -1040,8 +1166,7 @@ var createBeacon = (options) => {
|
|
|
1040
1166
|
};
|
|
1041
1167
|
const observer = new MutationObserver(() => {
|
|
1042
1168
|
mutated = true;
|
|
1043
|
-
|
|
1044
|
-
finish(true);
|
|
1169
|
+
finish(true);
|
|
1045
1170
|
});
|
|
1046
1171
|
observer.observe(document.body, {
|
|
1047
1172
|
attributes: true,
|
|
@@ -1060,7 +1185,10 @@ var createBeacon = (options) => {
|
|
|
1060
1185
|
return;
|
|
1061
1186
|
}
|
|
1062
1187
|
extended = true;
|
|
1063
|
-
timer2 = window.setTimeout(() =>
|
|
1188
|
+
timer2 = window.setTimeout(() => {
|
|
1189
|
+
const didRespond = responded();
|
|
1190
|
+
finish(didRespond, !didRespond);
|
|
1191
|
+
}, navigationResponseMs - DEAD_CLICK_WINDOW_MS);
|
|
1064
1192
|
}, DEAD_CLICK_WINDOW_MS);
|
|
1065
1193
|
};
|
|
1066
1194
|
const clickSignalMessage = (message, control) => `${message} — ${shortUrl(location.href)} — ${describeElement(control)}`;
|
|
@@ -1119,6 +1247,37 @@ var createBeacon = (options) => {
|
|
|
1119
1247
|
cleanups.push(() => observer.disconnect());
|
|
1120
1248
|
} catch {}
|
|
1121
1249
|
}
|
|
1250
|
+
if (signals !== null && signals.browserPolicyViolations !== false && typeof ReportingObserver !== "undefined") {
|
|
1251
|
+
try {
|
|
1252
|
+
const reportTypes = [
|
|
1253
|
+
"deprecation",
|
|
1254
|
+
"permissions-policy-violation",
|
|
1255
|
+
"integrity-violation",
|
|
1256
|
+
"coep"
|
|
1257
|
+
];
|
|
1258
|
+
const reported = new Set;
|
|
1259
|
+
const observer = new ReportingObserver((reports) => {
|
|
1260
|
+
for (const report of reports) {
|
|
1261
|
+
const body = report.body;
|
|
1262
|
+
const id = typeof body.id === "string" && body.id !== "" ? body.id.slice(0, SIGNAL_TEXT_MAX) : report.type;
|
|
1263
|
+
const key = `${report.type}|${id}|${shortUrl(report.url || location.href)}`;
|
|
1264
|
+
if (reported.has(key))
|
|
1265
|
+
continue;
|
|
1266
|
+
reported.add(key);
|
|
1267
|
+
emitSignal(`Browser policy violation — ${report.type} ${id} — ${shortUrl(location.href)}`, {
|
|
1268
|
+
policyId: id,
|
|
1269
|
+
reportType: report.type,
|
|
1270
|
+
reportUrl: report.url || location.href,
|
|
1271
|
+
signal: BEACON_SIGNAL.BROWSER_POLICY_VIOLATION,
|
|
1272
|
+
...typeof body.sourceFile === "string" ? { sourceFile: body.sourceFile } : {},
|
|
1273
|
+
...typeof body.lineNumber === "number" ? { sourceLine: String(body.lineNumber) } : {}
|
|
1274
|
+
});
|
|
1275
|
+
}
|
|
1276
|
+
}, { buffered: true, types: reportTypes });
|
|
1277
|
+
observer.observe();
|
|
1278
|
+
cleanups.push(() => observer.disconnect());
|
|
1279
|
+
} catch {}
|
|
1280
|
+
}
|
|
1122
1281
|
if (signals !== null && signals.mainThreadStalls !== false && typeof PerformanceObserver !== "undefined") {
|
|
1123
1282
|
const stallMs = signals.mainThreadStallMs ?? MAIN_THREAD_STALL_DEFAULT_MS;
|
|
1124
1283
|
const stallCount = signals.mainThreadStallCount ?? MAIN_THREAD_STALL_DEFAULT_COUNT;
|
|
@@ -1138,10 +1297,18 @@ var createBeacon = (options) => {
|
|
|
1138
1297
|
if (stallTimes.length < stallCount)
|
|
1139
1298
|
continue;
|
|
1140
1299
|
reported = true;
|
|
1300
|
+
const animationFrame = entry;
|
|
1301
|
+
const script = [...animationFrame.scripts ?? []].sort((left, right) => (right.duration ?? 0) - (left.duration ?? 0))[0];
|
|
1141
1302
|
emitSignal(`Main-thread stall — repeated long frames blocked the page — ${shortUrl(location.href)}`, {
|
|
1303
|
+
...animationFrame.blockingDuration === undefined ? {} : {
|
|
1304
|
+
blockingDurationMs: String(Math.round(animationFrame.blockingDuration))
|
|
1305
|
+
},
|
|
1142
1306
|
durationMs: String(Math.round(entry.duration)),
|
|
1143
1307
|
entryType: entry.entryType,
|
|
1144
1308
|
signal: BEACON_SIGNAL.MAIN_THREAD_STALL,
|
|
1309
|
+
...script?.functionName === undefined ? {} : { scriptFunction: script.functionName },
|
|
1310
|
+
...script?.invoker === undefined ? {} : { scriptInvoker: script.invoker },
|
|
1311
|
+
...script?.sourceURL === undefined ? {} : { scriptSource: shortUrl(script.sourceURL) },
|
|
1145
1312
|
stallCount: String(stallTimes.length),
|
|
1146
1313
|
windowMs: String(stallWindowMs)
|
|
1147
1314
|
});
|
|
@@ -1166,6 +1333,69 @@ var createBeacon = (options) => {
|
|
|
1166
1333
|
cleanups.push(() => observer.disconnect());
|
|
1167
1334
|
} catch {}
|
|
1168
1335
|
}
|
|
1336
|
+
if (signals !== null && typeof document !== "undefined") {
|
|
1337
|
+
const discardedDocument = document;
|
|
1338
|
+
if (signals.documentDiscards !== false && discardedDocument.wasDiscarded === true) {
|
|
1339
|
+
emitSignal(`Document discarded — the browser reloaded a discarded tab — ${shortUrl(location.href)}`, { signal: BEACON_SIGNAL.DOCUMENT_DISCARDED });
|
|
1340
|
+
}
|
|
1341
|
+
if (signals.bfcacheBlocks !== false && typeof performance !== "undefined") {
|
|
1342
|
+
const navigation = performance.getEntriesByType("navigation")[0];
|
|
1343
|
+
if (navigation?.type === "back_forward" && navigation.notRestoredReasons != null) {
|
|
1344
|
+
const reasons = new Set;
|
|
1345
|
+
const visit = (node) => {
|
|
1346
|
+
if (node === null || typeof node !== "object")
|
|
1347
|
+
return;
|
|
1348
|
+
const detail = node;
|
|
1349
|
+
for (const reason of detail.reasons ?? []) {
|
|
1350
|
+
if (typeof reason.reason === "string")
|
|
1351
|
+
reasons.add(reason.reason);
|
|
1352
|
+
}
|
|
1353
|
+
for (const child of detail.children ?? [])
|
|
1354
|
+
visit(child);
|
|
1355
|
+
};
|
|
1356
|
+
visit(navigation.notRestoredReasons);
|
|
1357
|
+
const reasonList = [...reasons].slice(0, 10);
|
|
1358
|
+
emitSignal(`Back-forward cache blocked — ${reasonList.join(", ") || "unknown reason"} — ${shortUrl(location.href)}`, {
|
|
1359
|
+
reasons: reasonList.join(",") || "unknown",
|
|
1360
|
+
signal: BEACON_SIGNAL.BFCACHE_BLOCKED
|
|
1361
|
+
});
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
if (instrument.networkChanges !== false && typeof navigator !== "undefined") {
|
|
1366
|
+
const connection = navigator.connection;
|
|
1367
|
+
if (connection !== undefined) {
|
|
1368
|
+
const onConnectionChange = () => {
|
|
1369
|
+
addBreadcrumb({
|
|
1370
|
+
data: {
|
|
1371
|
+
...typeof connection.downlink === "number" ? { downlink: connection.downlink } : {},
|
|
1372
|
+
...typeof connection.effectiveType === "string" ? { effectiveType: connection.effectiveType } : {},
|
|
1373
|
+
...typeof connection.rtt === "number" ? { rtt: connection.rtt } : {},
|
|
1374
|
+
...typeof connection.saveData === "boolean" ? { saveData: connection.saveData } : {}
|
|
1375
|
+
},
|
|
1376
|
+
message: "Network quality changed",
|
|
1377
|
+
type: "custom"
|
|
1378
|
+
});
|
|
1379
|
+
};
|
|
1380
|
+
connection.addEventListener("change", onConnectionChange);
|
|
1381
|
+
cleanups.push(() => connection.removeEventListener("change", onConnectionChange));
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
if (instrument.userTiming === true && typeof PerformanceObserver !== "undefined") {
|
|
1385
|
+
try {
|
|
1386
|
+
const observer = new PerformanceObserver((list) => {
|
|
1387
|
+
for (const entry of list.getEntries()) {
|
|
1388
|
+
addBreadcrumb({
|
|
1389
|
+
data: { durationMs: Math.round(entry.duration) },
|
|
1390
|
+
message: `Performance measure ${entry.name.slice(0, SIGNAL_TEXT_MAX)}`,
|
|
1391
|
+
type: "custom"
|
|
1392
|
+
});
|
|
1393
|
+
}
|
|
1394
|
+
});
|
|
1395
|
+
observer.observe({ buffered: true, type: "measure" });
|
|
1396
|
+
cleanups.push(() => observer.disconnect());
|
|
1397
|
+
} catch {}
|
|
1398
|
+
}
|
|
1169
1399
|
if (instrument.globalErrors !== false) {
|
|
1170
1400
|
const onError = (event) => {
|
|
1171
1401
|
if (event instanceof ErrorEvent) {
|
|
@@ -1175,6 +1405,7 @@ var createBeacon = (options) => {
|
|
|
1175
1405
|
level: "error",
|
|
1176
1406
|
tags: errorEventTags(event)
|
|
1177
1407
|
});
|
|
1408
|
+
reportErrorClick?.(error.name);
|
|
1178
1409
|
return;
|
|
1179
1410
|
}
|
|
1180
1411
|
const target = event.target;
|
|
@@ -1213,6 +1444,7 @@ var createBeacon = (options) => {
|
|
|
1213
1444
|
const reason = event.reason;
|
|
1214
1445
|
if (reason instanceof Error) {
|
|
1215
1446
|
captureException(reason, { level: "error" });
|
|
1447
|
+
reportErrorClick?.(reason.name);
|
|
1216
1448
|
return;
|
|
1217
1449
|
}
|
|
1218
1450
|
if (typeof reason === "object" && reason !== null && typeof reason.stack === "string") {
|
|
@@ -1226,6 +1458,7 @@ var createBeacon = (options) => {
|
|
|
1226
1458
|
},
|
|
1227
1459
|
level: "error"
|
|
1228
1460
|
});
|
|
1461
|
+
reportErrorClick?.("UnhandledRejection");
|
|
1229
1462
|
};
|
|
1230
1463
|
window.addEventListener("unhandledrejection", onRejection);
|
|
1231
1464
|
cleanups.push(() => window.removeEventListener("unhandledrejection", onRejection));
|
|
@@ -1243,6 +1476,8 @@ var createBeacon = (options) => {
|
|
|
1243
1476
|
const text = args.map(String).join(" ").trim().slice(0, SIGNAL_TEXT_MAX);
|
|
1244
1477
|
if (text !== "")
|
|
1245
1478
|
emitSignal(text, { signal: BEACON_SIGNAL.CONSOLE_ERROR }, undefined, undefined, wrappedConsole, 2);
|
|
1479
|
+
if (text !== "")
|
|
1480
|
+
reportErrorClick?.("ConsoleError");
|
|
1246
1481
|
inSignalConsole = false;
|
|
1247
1482
|
}
|
|
1248
1483
|
original.apply(console, args);
|
|
@@ -1300,9 +1535,16 @@ var createBeacon = (options) => {
|
|
|
1300
1535
|
const target = event.target;
|
|
1301
1536
|
if (!(target instanceof Element))
|
|
1302
1537
|
return;
|
|
1303
|
-
|
|
1538
|
+
const targetName = describeElement(target);
|
|
1539
|
+
beginAction("click", targetName);
|
|
1540
|
+
addBreadcrumb({ message: targetName, type: "click" });
|
|
1304
1541
|
if (signals === null)
|
|
1305
1542
|
return;
|
|
1543
|
+
recentInteraction = {
|
|
1544
|
+
at: Date.now(),
|
|
1545
|
+
target: targetName,
|
|
1546
|
+
type: "click"
|
|
1547
|
+
};
|
|
1306
1548
|
const control = deadClickCandidate(target, event);
|
|
1307
1549
|
if (control === null)
|
|
1308
1550
|
return;
|
|
@@ -1313,11 +1555,18 @@ var createBeacon = (options) => {
|
|
|
1313
1555
|
const clickedAt = Date.now();
|
|
1314
1556
|
const x = event instanceof MouseEvent ? event.clientX : 0;
|
|
1315
1557
|
const y = event instanceof MouseEvent ? event.clientY : 0;
|
|
1316
|
-
observeClickResponse(control, event, (responded) => {
|
|
1558
|
+
observeClickResponse(control, event, (responded, navigationStalled) => {
|
|
1317
1559
|
if (responded) {
|
|
1318
1560
|
unresponsiveClicks = unresponsiveClicks.filter((click) => click.control !== control);
|
|
1319
1561
|
return;
|
|
1320
1562
|
}
|
|
1563
|
+
if (navigationStalled && signals.stalledNavigations !== false) {
|
|
1564
|
+
emitSignal(clickSignalMessage("Navigation stalled — accepted route never settled", control), {
|
|
1565
|
+
signal: BEACON_SIGNAL.NAVIGATION_STALLED,
|
|
1566
|
+
target: describeElement(control)
|
|
1567
|
+
});
|
|
1568
|
+
return;
|
|
1569
|
+
}
|
|
1321
1570
|
if (detectDead) {
|
|
1322
1571
|
emitSignal(clickSignalMessage("Dead click — control didn't respond", control), {
|
|
1323
1572
|
signal: BEACON_SIGNAL.DEAD_CLICK,
|
|
@@ -1338,7 +1587,38 @@ var createBeacon = (options) => {
|
|
|
1338
1587
|
});
|
|
1339
1588
|
};
|
|
1340
1589
|
document.addEventListener("click", onClick, true);
|
|
1341
|
-
|
|
1590
|
+
const onInteractionSubmit = (event) => {
|
|
1591
|
+
if (!(event.target instanceof HTMLFormElement))
|
|
1592
|
+
return;
|
|
1593
|
+
const target = describeElement(event.target);
|
|
1594
|
+
beginAction("submit", target);
|
|
1595
|
+
recentInteraction = {
|
|
1596
|
+
at: Date.now(),
|
|
1597
|
+
target,
|
|
1598
|
+
type: "submit"
|
|
1599
|
+
};
|
|
1600
|
+
};
|
|
1601
|
+
const onInteractionKey = (event) => {
|
|
1602
|
+
if (event.key !== "Enter" && event.key !== " ")
|
|
1603
|
+
return;
|
|
1604
|
+
const target = event.target;
|
|
1605
|
+
if (!(target instanceof Element))
|
|
1606
|
+
return;
|
|
1607
|
+
const targetName = describeElement(target);
|
|
1608
|
+
beginAction("keyboard", targetName);
|
|
1609
|
+
recentInteraction = {
|
|
1610
|
+
at: Date.now(),
|
|
1611
|
+
target: targetName,
|
|
1612
|
+
type: "keyboard"
|
|
1613
|
+
};
|
|
1614
|
+
};
|
|
1615
|
+
document.addEventListener("submit", onInteractionSubmit, true);
|
|
1616
|
+
document.addEventListener("keydown", onInteractionKey, true);
|
|
1617
|
+
cleanups.push(() => {
|
|
1618
|
+
document.removeEventListener("click", onClick, true);
|
|
1619
|
+
document.removeEventListener("submit", onInteractionSubmit, true);
|
|
1620
|
+
document.removeEventListener("keydown", onInteractionKey, true);
|
|
1621
|
+
});
|
|
1342
1622
|
}
|
|
1343
1623
|
if (signals !== null && typeof document !== "undefined" && typeof window.getComputedStyle === "function") {
|
|
1344
1624
|
const detectOverflow = signals.layoutOverflows !== false;
|
|
@@ -1346,6 +1626,7 @@ var createBeacon = (options) => {
|
|
|
1346
1626
|
const detectInvisibleText = signals.invisibleText !== false;
|
|
1347
1627
|
const detectStuckLoading = signals.stuckLoading !== false;
|
|
1348
1628
|
const detectThemeMismatch = signals.themeMismatches !== false;
|
|
1629
|
+
const detectBlankAppRoot = signals.blankAppRoots !== false;
|
|
1349
1630
|
const overflowSettleMs = signals.layoutOverflowSettleMs ?? LAYOUT_OVERFLOW_SETTLE_DEFAULT_MS;
|
|
1350
1631
|
const overflowMaxReports = signals.layoutOverflowMaxReports ?? LAYOUT_OVERFLOW_MAX_REPORTS_DEFAULT;
|
|
1351
1632
|
const stuckLoadingMs = signals.stuckLoadingMs ?? STUCK_LOADING_DEFAULT_MS;
|
|
@@ -1735,6 +2016,25 @@ var createBeacon = (options) => {
|
|
|
1735
2016
|
reportScanIssue(indicator, BEACON_SIGNAL.STUCK_LOADING, `Stuck loading — ${describeElement(indicator)} never resolved`, { visibleMs: String(now - firstSeen) });
|
|
1736
2017
|
}
|
|
1737
2018
|
};
|
|
2019
|
+
const checkBlankAppRoots = () => {
|
|
2020
|
+
if (document.visibilityState === "hidden")
|
|
2021
|
+
return;
|
|
2022
|
+
const roots = document.querySelectorAll(`[${BEACON_ATTRIBUTE.APP_ROOT}]`);
|
|
2023
|
+
for (const root of Array.from(roots)) {
|
|
2024
|
+
if (isScanExempt(root))
|
|
2025
|
+
continue;
|
|
2026
|
+
const rect = root.getBoundingClientRect();
|
|
2027
|
+
if (rect.width === 0 || rect.height === 0)
|
|
2028
|
+
continue;
|
|
2029
|
+
const text = (root.textContent ?? "").trim();
|
|
2030
|
+
const meaningful = text !== "" || root.querySelector("button, input, select, textarea, img, svg, canvas, video, iframe, [role=alert]") !== null;
|
|
2031
|
+
const loading = root.querySelector(`[aria-busy="true"], [role="progressbar"], [${BEACON_ATTRIBUTE.LOADING}]`) !== null;
|
|
2032
|
+
if (meaningful || loading)
|
|
2033
|
+
continue;
|
|
2034
|
+
const name = root.getAttribute(BEACON_ATTRIBUTE.APP_ROOT)?.trim() || describeElement(root);
|
|
2035
|
+
reportScanIssue(root, BEACON_SIGNAL.BLANK_APP_ROOT, `Blank application root — ${name} rendered no meaningful content`, {});
|
|
2036
|
+
}
|
|
2037
|
+
};
|
|
1738
2038
|
const runSettledScan = () => {
|
|
1739
2039
|
if (detectOverflow)
|
|
1740
2040
|
scanForOverflow();
|
|
@@ -1781,6 +2081,97 @@ var createBeacon = (options) => {
|
|
|
1781
2081
|
stuckTimer.unref?.();
|
|
1782
2082
|
cleanups.push(() => clearInterval(stuckTimer));
|
|
1783
2083
|
}
|
|
2084
|
+
if (detectBlankAppRoot) {
|
|
2085
|
+
const blankTimer = setTimeout(checkBlankAppRoots, signals.blankAppRootSettleMs ?? BLANK_APP_ROOT_SETTLE_DEFAULT_MS);
|
|
2086
|
+
cleanups.push(() => clearTimeout(blankTimer));
|
|
2087
|
+
}
|
|
2088
|
+
}
|
|
2089
|
+
if (signals !== null && signals.disruptiveLayoutShifts !== false && typeof PerformanceObserver !== "undefined") {
|
|
2090
|
+
const minimum = signals.disruptiveLayoutShiftMin ?? DISRUPTIVE_LAYOUT_SHIFT_DEFAULT_MIN;
|
|
2091
|
+
const reported = new Set;
|
|
2092
|
+
try {
|
|
2093
|
+
const observer = new PerformanceObserver((list) => {
|
|
2094
|
+
for (const raw of list.getEntries()) {
|
|
2095
|
+
const entry = raw;
|
|
2096
|
+
if (entry.hadRecentInput === true || (entry.value ?? 0) < minimum)
|
|
2097
|
+
continue;
|
|
2098
|
+
const targets = (entry.sources ?? []).map(({ node }) => node instanceof Element ? describeElement(node) : undefined).filter((target) => target !== undefined).slice(0, 5);
|
|
2099
|
+
const key = targets.join(",") || "unknown";
|
|
2100
|
+
if (reported.has(key))
|
|
2101
|
+
continue;
|
|
2102
|
+
reported.add(key);
|
|
2103
|
+
emitSignal(`Disruptive layout shift — ${key} — ${shortUrl(location.href)}`, {
|
|
2104
|
+
shiftValue: String(entry.value ?? 0),
|
|
2105
|
+
signal: BEACON_SIGNAL.DISRUPTIVE_LAYOUT_SHIFT,
|
|
2106
|
+
target: key
|
|
2107
|
+
});
|
|
2108
|
+
}
|
|
2109
|
+
});
|
|
2110
|
+
observer.observe({ buffered: true, type: "layout-shift" });
|
|
2111
|
+
cleanups.push(() => observer.disconnect());
|
|
2112
|
+
} catch {}
|
|
2113
|
+
}
|
|
2114
|
+
if (signals !== null && signals.slowInteractions !== false && typeof PerformanceObserver !== "undefined") {
|
|
2115
|
+
const minimum = signals.slowInteractionMs ?? SLOW_INTERACTION_DEFAULT_MS;
|
|
2116
|
+
const reported = new Set;
|
|
2117
|
+
try {
|
|
2118
|
+
const observer = new PerformanceObserver((list) => {
|
|
2119
|
+
for (const raw of list.getEntries()) {
|
|
2120
|
+
const entry = raw;
|
|
2121
|
+
if (entry.duration < minimum)
|
|
2122
|
+
continue;
|
|
2123
|
+
const target = entry.target instanceof Element ? describeElement(entry.target) : "unknown";
|
|
2124
|
+
const key = entry.interactionId ?? `${entry.name}|${target}`;
|
|
2125
|
+
if (reported.has(key))
|
|
2126
|
+
continue;
|
|
2127
|
+
reported.add(key);
|
|
2128
|
+
emitSignal(`Slow interaction — ${entry.name} blocked for ${Math.round(entry.duration)}ms — ${shortUrl(location.href)}`, {
|
|
2129
|
+
durationMs: String(Math.round(entry.duration)),
|
|
2130
|
+
eventType: entry.name,
|
|
2131
|
+
...entry.interactionId === undefined ? {} : { interactionId: String(entry.interactionId) },
|
|
2132
|
+
signal: BEACON_SIGNAL.SLOW_INTERACTION,
|
|
2133
|
+
target
|
|
2134
|
+
});
|
|
2135
|
+
}
|
|
2136
|
+
});
|
|
2137
|
+
observer.observe({
|
|
2138
|
+
buffered: true,
|
|
2139
|
+
durationThreshold: Math.max(16, Math.min(1040, minimum)),
|
|
2140
|
+
type: "event"
|
|
2141
|
+
});
|
|
2142
|
+
cleanups.push(() => observer.disconnect());
|
|
2143
|
+
} catch {}
|
|
2144
|
+
}
|
|
2145
|
+
if (signals !== null && signals.slowResources !== false && typeof PerformanceObserver !== "undefined") {
|
|
2146
|
+
const minimum = signals.slowResourceMs ?? SLOW_RESOURCE_DEFAULT_MS;
|
|
2147
|
+
const reported = new Set;
|
|
2148
|
+
try {
|
|
2149
|
+
const observer = new PerformanceObserver((list) => {
|
|
2150
|
+
for (const raw of list.getEntries()) {
|
|
2151
|
+
const entry = raw;
|
|
2152
|
+
if (entry.duration < minimum)
|
|
2153
|
+
continue;
|
|
2154
|
+
if (!/^(css|font|img|link|script)$/u.test(entry.initiatorType))
|
|
2155
|
+
continue;
|
|
2156
|
+
const resource = shortUrl(entry.name);
|
|
2157
|
+
const key = `${entry.initiatorType}|${resource}`;
|
|
2158
|
+
if (reported.has(key))
|
|
2159
|
+
continue;
|
|
2160
|
+
reported.add(key);
|
|
2161
|
+
emitSignal(`Slow resource — ${entry.initiatorType} ${resource}`, {
|
|
2162
|
+
cacheHit: String(entry.transferSize === 0),
|
|
2163
|
+
durationMs: String(Math.round(entry.duration)),
|
|
2164
|
+
initiatorType: entry.initiatorType,
|
|
2165
|
+
protocol: entry.nextHopProtocol || "unknown",
|
|
2166
|
+
signal: BEACON_SIGNAL.SLOW_RESOURCE,
|
|
2167
|
+
target: resource,
|
|
2168
|
+
transferSize: String(entry.transferSize)
|
|
2169
|
+
});
|
|
2170
|
+
}
|
|
2171
|
+
});
|
|
2172
|
+
observer.observe({ buffered: true, type: "resource" });
|
|
2173
|
+
cleanups.push(() => observer.disconnect());
|
|
2174
|
+
} catch {}
|
|
1784
2175
|
}
|
|
1785
2176
|
if (signals !== null && signals.embeddedContentStalls !== false && typeof document !== "undefined") {
|
|
1786
2177
|
const stallMs = signals.embeddedContentStallMs ?? EMBEDDED_CONTENT_STALL_DEFAULT_MS;
|
|
@@ -1863,6 +2254,153 @@ var createBeacon = (options) => {
|
|
|
1863
2254
|
stopWatching(frame);
|
|
1864
2255
|
});
|
|
1865
2256
|
}
|
|
2257
|
+
if (signals !== null && signals.mediaFailures !== false && typeof document !== "undefined") {
|
|
2258
|
+
const stallMs = signals.mediaStallMs ?? MEDIA_STALL_DEFAULT_MS;
|
|
2259
|
+
const watched = new Map;
|
|
2260
|
+
const watch = (media) => {
|
|
2261
|
+
if (watched.has(media) || !media.hasAttribute(BEACON_ATTRIBUTE.MEDIA))
|
|
2262
|
+
return;
|
|
2263
|
+
const name = media.getAttribute(BEACON_ATTRIBUTE.MEDIA)?.trim() || describeElement(media);
|
|
2264
|
+
let started = false;
|
|
2265
|
+
let stallTimer;
|
|
2266
|
+
const clearStall = () => {
|
|
2267
|
+
if (stallTimer !== undefined)
|
|
2268
|
+
clearTimeout(stallTimer);
|
|
2269
|
+
stallTimer = undefined;
|
|
2270
|
+
};
|
|
2271
|
+
const onPlay = () => {
|
|
2272
|
+
started = true;
|
|
2273
|
+
clearStall();
|
|
2274
|
+
};
|
|
2275
|
+
const onWaiting = () => {
|
|
2276
|
+
if (!started || media.ended || media.paused)
|
|
2277
|
+
return;
|
|
2278
|
+
clearStall();
|
|
2279
|
+
stallTimer = setTimeout(() => {
|
|
2280
|
+
if (!media.isConnected || media.ended || media.paused)
|
|
2281
|
+
return;
|
|
2282
|
+
emitSignal(`Media playback stalled — ${name} — ${shortUrl(location.href)}`, {
|
|
2283
|
+
currentTime: String(Math.round(media.currentTime)),
|
|
2284
|
+
networkState: String(media.networkState),
|
|
2285
|
+
readyState: String(media.readyState),
|
|
2286
|
+
signal: BEACON_SIGNAL.MEDIA_PLAYBACK_STALLED,
|
|
2287
|
+
target: name
|
|
2288
|
+
});
|
|
2289
|
+
}, stallMs);
|
|
2290
|
+
};
|
|
2291
|
+
const onError = () => {
|
|
2292
|
+
const error = media.error;
|
|
2293
|
+
emitSignal(`Media playback failed — ${name} — ${shortUrl(location.href)}`, {
|
|
2294
|
+
errorCode: String(error?.code ?? 0),
|
|
2295
|
+
networkState: String(media.networkState),
|
|
2296
|
+
signal: BEACON_SIGNAL.MEDIA_PLAYBACK_FAILED,
|
|
2297
|
+
target: name
|
|
2298
|
+
});
|
|
2299
|
+
};
|
|
2300
|
+
media.addEventListener("playing", onPlay);
|
|
2301
|
+
media.addEventListener("waiting", onWaiting);
|
|
2302
|
+
media.addEventListener("stalled", onWaiting);
|
|
2303
|
+
media.addEventListener("waitingforkey", onWaiting);
|
|
2304
|
+
media.addEventListener("error", onError);
|
|
2305
|
+
media.addEventListener("pause", clearStall);
|
|
2306
|
+
media.addEventListener("ended", clearStall);
|
|
2307
|
+
const cleanup = () => {
|
|
2308
|
+
clearStall();
|
|
2309
|
+
media.removeEventListener("playing", onPlay);
|
|
2310
|
+
media.removeEventListener("waiting", onWaiting);
|
|
2311
|
+
media.removeEventListener("stalled", onWaiting);
|
|
2312
|
+
media.removeEventListener("waitingforkey", onWaiting);
|
|
2313
|
+
media.removeEventListener("error", onError);
|
|
2314
|
+
media.removeEventListener("pause", clearStall);
|
|
2315
|
+
media.removeEventListener("ended", clearStall);
|
|
2316
|
+
};
|
|
2317
|
+
watched.set(media, { cleanup, stallTimer });
|
|
2318
|
+
};
|
|
2319
|
+
const scan = (root) => {
|
|
2320
|
+
if (root instanceof HTMLMediaElement)
|
|
2321
|
+
watch(root);
|
|
2322
|
+
for (const media of Array.from(root.querySelectorAll?.(`audio[${BEACON_ATTRIBUTE.MEDIA}], video[${BEACON_ATTRIBUTE.MEDIA}]`) ?? [])) {
|
|
2323
|
+
if (media instanceof HTMLMediaElement)
|
|
2324
|
+
watch(media);
|
|
2325
|
+
}
|
|
2326
|
+
};
|
|
2327
|
+
scan(document);
|
|
2328
|
+
const observer = new MutationObserver((records) => {
|
|
2329
|
+
for (const record of records) {
|
|
2330
|
+
for (const node of Array.from(record.addedNodes)) {
|
|
2331
|
+
if (node instanceof Element)
|
|
2332
|
+
scan(node);
|
|
2333
|
+
}
|
|
2334
|
+
}
|
|
2335
|
+
});
|
|
2336
|
+
observer.observe(document.documentElement, {
|
|
2337
|
+
childList: true,
|
|
2338
|
+
subtree: true
|
|
2339
|
+
});
|
|
2340
|
+
cleanups.push(() => {
|
|
2341
|
+
observer.disconnect();
|
|
2342
|
+
for (const { cleanup } of watched.values())
|
|
2343
|
+
cleanup();
|
|
2344
|
+
watched.clear();
|
|
2345
|
+
});
|
|
2346
|
+
}
|
|
2347
|
+
if (signals !== null && signals.storageFailures !== false && typeof Storage !== "undefined") {
|
|
2348
|
+
const originalSetItem = Storage.prototype.setItem;
|
|
2349
|
+
const wrappedSetItem = function(key, value) {
|
|
2350
|
+
try {
|
|
2351
|
+
originalSetItem.call(this, key, value);
|
|
2352
|
+
} catch (error) {
|
|
2353
|
+
const resolved = toError(error);
|
|
2354
|
+
emitSignal(`Browser storage failure — ${resolved.name} — ${shortUrl(location.href)}`, {
|
|
2355
|
+
errorName: resolved.name,
|
|
2356
|
+
signal: BEACON_SIGNAL.STORAGE_FAILURE,
|
|
2357
|
+
storage: this === localStorage ? "localStorage" : "sessionStorage"
|
|
2358
|
+
});
|
|
2359
|
+
throw error;
|
|
2360
|
+
}
|
|
2361
|
+
};
|
|
2362
|
+
try {
|
|
2363
|
+
Storage.prototype.setItem = wrappedSetItem;
|
|
2364
|
+
cleanups.push(() => {
|
|
2365
|
+
Storage.prototype.setItem = originalSetItem;
|
|
2366
|
+
});
|
|
2367
|
+
} catch {}
|
|
2368
|
+
}
|
|
2369
|
+
if (signals !== null && signals.storageFailures !== false && typeof indexedDB !== "undefined") {
|
|
2370
|
+
const factory = indexedDB;
|
|
2371
|
+
const originalOpen = factory.open.bind(factory);
|
|
2372
|
+
const originalDeleteDatabase = factory.deleteDatabase.bind(factory);
|
|
2373
|
+
const reported = new WeakSet;
|
|
2374
|
+
const watch = (request, operation, database) => {
|
|
2375
|
+
request.addEventListener("error", () => {
|
|
2376
|
+
if (reported.has(request))
|
|
2377
|
+
return;
|
|
2378
|
+
reported.add(request);
|
|
2379
|
+
const error = request.error;
|
|
2380
|
+
emitSignal(`IndexedDB ${operation} failure — ${error?.name ?? "UnknownError"} — ${shortUrl(location.href)}`, {
|
|
2381
|
+
database: database.slice(0, SIGNAL_TEXT_MAX),
|
|
2382
|
+
errorName: error?.name ?? "UnknownError",
|
|
2383
|
+
operation,
|
|
2384
|
+
signal: BEACON_SIGNAL.STORAGE_FAILURE,
|
|
2385
|
+
storage: "indexedDB"
|
|
2386
|
+
});
|
|
2387
|
+
}, { once: true });
|
|
2388
|
+
return request;
|
|
2389
|
+
};
|
|
2390
|
+
const wrappedOpen = (name, version) => watch(version === undefined ? originalOpen(name) : originalOpen(name, version), "open", name);
|
|
2391
|
+
const wrappedDeleteDatabase = (name) => watch(originalDeleteDatabase(name), "delete", name);
|
|
2392
|
+
try {
|
|
2393
|
+
factory.open = wrappedOpen;
|
|
2394
|
+
factory.deleteDatabase = wrappedDeleteDatabase;
|
|
2395
|
+
cleanups.push(() => {
|
|
2396
|
+
if (factory.open === wrappedOpen)
|
|
2397
|
+
factory.open = originalOpen;
|
|
2398
|
+
if (factory.deleteDatabase === wrappedDeleteDatabase) {
|
|
2399
|
+
factory.deleteDatabase = originalDeleteDatabase;
|
|
2400
|
+
}
|
|
2401
|
+
});
|
|
2402
|
+
} catch {}
|
|
2403
|
+
}
|
|
1866
2404
|
if (signals !== null && signals.webglContextLosses !== false && typeof document !== "undefined") {
|
|
1867
2405
|
const graceMs = signals.webglRestoreGraceMs ?? WEBGL_RESTORE_GRACE_DEFAULT_MS;
|
|
1868
2406
|
const pending = new Map;
|
|
@@ -2022,6 +2560,48 @@ var createBeacon = (options) => {
|
|
|
2022
2560
|
document.addEventListener("wheel", onWheel, { passive: true });
|
|
2023
2561
|
cleanups.push(() => document.removeEventListener("wheel", onWheel));
|
|
2024
2562
|
}
|
|
2563
|
+
if (signals.thrashedCursors !== false) {
|
|
2564
|
+
const reversalThreshold = signals.thrashedCursorReversals ?? THRASHED_CURSOR_DEFAULT_REVERSALS;
|
|
2565
|
+
let points = [];
|
|
2566
|
+
let previous;
|
|
2567
|
+
let reported = false;
|
|
2568
|
+
const onPointerMove = (event) => {
|
|
2569
|
+
if (reported || event.pointerType === "touch")
|
|
2570
|
+
return;
|
|
2571
|
+
if (previous === undefined) {
|
|
2572
|
+
previous = { x: event.clientX, y: event.clientY };
|
|
2573
|
+
return;
|
|
2574
|
+
}
|
|
2575
|
+
const dx = event.clientX - previous.x;
|
|
2576
|
+
const dy = event.clientY - previous.y;
|
|
2577
|
+
previous = { x: event.clientX, y: event.clientY };
|
|
2578
|
+
if (Math.hypot(dx, dy) < 8)
|
|
2579
|
+
return;
|
|
2580
|
+
const now = Date.now();
|
|
2581
|
+
points = points.filter((point) => now - point.at < THRASHED_CURSOR_WINDOW_MS);
|
|
2582
|
+
points.push({ at: now, dx, dy });
|
|
2583
|
+
let reversals = 0;
|
|
2584
|
+
for (let index = 1;index < points.length; index += 1) {
|
|
2585
|
+
const prior = points[index - 1];
|
|
2586
|
+
const current = points[index];
|
|
2587
|
+
if (prior.dx * current.dx < 0 || prior.dy * current.dy < 0)
|
|
2588
|
+
reversals += 1;
|
|
2589
|
+
}
|
|
2590
|
+
if (reversals < reversalThreshold)
|
|
2591
|
+
return;
|
|
2592
|
+
reported = true;
|
|
2593
|
+
const target = event.target instanceof Element ? describeElement(event.target) : "document";
|
|
2594
|
+
emitSignal(`Thrashed cursor — repeated direction changes — ${shortUrl(location.href)}`, {
|
|
2595
|
+
reversals: String(reversals),
|
|
2596
|
+
signal: BEACON_SIGNAL.THRASHED_CURSOR,
|
|
2597
|
+
target
|
|
2598
|
+
});
|
|
2599
|
+
};
|
|
2600
|
+
document.addEventListener("pointermove", onPointerMove, {
|
|
2601
|
+
passive: true
|
|
2602
|
+
});
|
|
2603
|
+
cleanups.push(() => document.removeEventListener("pointermove", onPointerMove));
|
|
2604
|
+
}
|
|
2025
2605
|
if (signals.focusLoss !== false || signals.modalFocusEscape !== false) {
|
|
2026
2606
|
const DIALOG_SELECTOR = '[role="dialog"], [aria-modal="true"], dialog';
|
|
2027
2607
|
const MODAL_SELECTOR = '[aria-modal="true"], dialog[open]';
|
|
@@ -2196,6 +2776,46 @@ var createBeacon = (options) => {
|
|
|
2196
2776
|
document.removeEventListener("invalid", onInvalid, true);
|
|
2197
2777
|
});
|
|
2198
2778
|
}
|
|
2779
|
+
if (signals.formAbandonment !== false) {
|
|
2780
|
+
const dirtyForms = new Set;
|
|
2781
|
+
const submittedForms = new WeakSet;
|
|
2782
|
+
const onInput = (event) => {
|
|
2783
|
+
const target = event.target;
|
|
2784
|
+
const form = target instanceof HTMLInputElement || target instanceof HTMLSelectElement || target instanceof HTMLTextAreaElement ? target.form : null;
|
|
2785
|
+
if (form?.hasAttribute(BEACON_ATTRIBUTE.FORM) === true) {
|
|
2786
|
+
dirtyForms.add(form);
|
|
2787
|
+
}
|
|
2788
|
+
};
|
|
2789
|
+
const onSubmit = (event) => {
|
|
2790
|
+
if (!(event.target instanceof HTMLFormElement))
|
|
2791
|
+
return;
|
|
2792
|
+
submittedForms.add(event.target);
|
|
2793
|
+
dirtyForms.delete(event.target);
|
|
2794
|
+
};
|
|
2795
|
+
const report = () => {
|
|
2796
|
+
for (const form of dirtyForms) {
|
|
2797
|
+
if (!form.isConnected || submittedForms.has(form))
|
|
2798
|
+
continue;
|
|
2799
|
+
const name = form.getAttribute(BEACON_ATTRIBUTE.FORM)?.trim() || describeElement(form);
|
|
2800
|
+
emitSignal(`Form abandonment — ${name} left dirty — ${shortUrl(location.href)}`, {
|
|
2801
|
+
fieldCount: String(form.elements.length),
|
|
2802
|
+
signal: BEACON_SIGNAL.FORM_ABANDONMENT,
|
|
2803
|
+
target: name
|
|
2804
|
+
});
|
|
2805
|
+
dirtyForms.delete(form);
|
|
2806
|
+
}
|
|
2807
|
+
};
|
|
2808
|
+
reportFormAbandonmentOnNavigation = report;
|
|
2809
|
+
document.addEventListener("input", onInput, true);
|
|
2810
|
+
document.addEventListener("submit", onSubmit, true);
|
|
2811
|
+
window.addEventListener("pagehide", report);
|
|
2812
|
+
cleanups.push(() => {
|
|
2813
|
+
reportFormAbandonmentOnNavigation = null;
|
|
2814
|
+
document.removeEventListener("input", onInput, true);
|
|
2815
|
+
document.removeEventListener("submit", onSubmit, true);
|
|
2816
|
+
window.removeEventListener("pagehide", report);
|
|
2817
|
+
});
|
|
2818
|
+
}
|
|
2199
2819
|
}
|
|
2200
2820
|
if (signals !== null && (signals.stalledStreams !== false || signals.sseFlapping !== false) && typeof window.EventSource === "function") {
|
|
2201
2821
|
const stalledStreamMs = signals.stalledStreamMs ?? STALLED_STREAM_DEFAULT_MS;
|
|
@@ -2593,6 +3213,25 @@ var createBeacon = (options) => {
|
|
|
2593
3213
|
recordRequestForStorm = null;
|
|
2594
3214
|
});
|
|
2595
3215
|
}
|
|
3216
|
+
const classifySemanticResponse = (response, request) => {
|
|
3217
|
+
const classifier = instrument.classifyResponse;
|
|
3218
|
+
if (classifier === undefined || !response.ok)
|
|
3219
|
+
return;
|
|
3220
|
+
Promise.resolve(classifier(response.clone(), request)).then((result) => {
|
|
3221
|
+
if (result === undefined || result === false)
|
|
3222
|
+
return;
|
|
3223
|
+
captureException(errorWithoutStack("SemanticResponseFailure", result.message), {
|
|
3224
|
+
groupingKey: result.groupingKey,
|
|
3225
|
+
level: "warning",
|
|
3226
|
+
tags: {
|
|
3227
|
+
endpoint: shortUrl(request.url),
|
|
3228
|
+
method: request.method.toUpperCase(),
|
|
3229
|
+
signal: BEACON_SIGNAL.SEMANTIC_RESPONSE_FAILURE,
|
|
3230
|
+
...result.tags ?? {}
|
|
3231
|
+
}
|
|
3232
|
+
});
|
|
3233
|
+
}).catch(() => {});
|
|
3234
|
+
};
|
|
2596
3235
|
if (instrument.fetch !== false && typeof window.fetch === "function") {
|
|
2597
3236
|
const originalFetch = window.fetch;
|
|
2598
3237
|
const wrapped = async (...args) => {
|
|
@@ -2612,6 +3251,7 @@ var createBeacon = (options) => {
|
|
|
2612
3251
|
type: "fetch"
|
|
2613
3252
|
});
|
|
2614
3253
|
reportResponseSignal(url, method, response.status, Date.now() - start, responseTraceId(response.headers.get(BEACON_TRACE_HEADER)));
|
|
3254
|
+
classifySemanticResponse(response, { method, url });
|
|
2615
3255
|
return response;
|
|
2616
3256
|
} catch (error) {
|
|
2617
3257
|
const resolved = toError(error);
|
|
@@ -2666,6 +3306,20 @@ var createBeacon = (options) => {
|
|
|
2666
3306
|
});
|
|
2667
3307
|
if (!failed) {
|
|
2668
3308
|
reportResponseSignal(request.url, request.method, this.status, Date.now() - start, responseTraceId(this.getResponseHeader(BEACON_TRACE_HEADER)));
|
|
3309
|
+
if (instrument.classifyResponse !== undefined && this.status >= 200 && this.status < 300 && (this.responseType === "" || this.responseType === "text")) {
|
|
3310
|
+
const headers = new Headers;
|
|
3311
|
+
for (const line of this.getAllResponseHeaders().split(/\r?\n/u)) {
|
|
3312
|
+
const separator = line.indexOf(":");
|
|
3313
|
+
if (separator <= 0)
|
|
3314
|
+
continue;
|
|
3315
|
+
headers.append(line.slice(0, separator).trim(), line.slice(separator + 1).trim());
|
|
3316
|
+
}
|
|
3317
|
+
classifySemanticResponse(new Response(this.responseText, {
|
|
3318
|
+
headers,
|
|
3319
|
+
status: this.status,
|
|
3320
|
+
statusText: this.statusText
|
|
3321
|
+
}), request);
|
|
3322
|
+
}
|
|
2669
3323
|
} else {
|
|
2670
3324
|
const error = new Error(outcome === "timeout" ? "XMLHttpRequest timed out" : outcome === "aborted" ? "XMLHttpRequest was aborted" : "XMLHttpRequest completed with status 0");
|
|
2671
3325
|
error.name = outcome === "timeout" ? "TimeoutError" : outcome === "aborted" ? "AbortError" : "XMLHttpRequestError";
|
|
@@ -2691,6 +3345,7 @@ var createBeacon = (options) => {
|
|
|
2691
3345
|
const patch = (key) => {
|
|
2692
3346
|
const original = history[key].bind(history);
|
|
2693
3347
|
history[key] = (...args) => {
|
|
3348
|
+
reportFormAbandonmentOnNavigation?.();
|
|
2694
3349
|
const result = original(...args);
|
|
2695
3350
|
record();
|
|
2696
3351
|
return result;
|
|
@@ -2700,8 +3355,12 @@ var createBeacon = (options) => {
|
|
|
2700
3355
|
};
|
|
2701
3356
|
};
|
|
2702
3357
|
cleanups.push(patch("pushState"), patch("replaceState"));
|
|
2703
|
-
|
|
2704
|
-
|
|
3358
|
+
const onPopState = () => {
|
|
3359
|
+
reportFormAbandonmentOnNavigation?.();
|
|
3360
|
+
record();
|
|
3361
|
+
};
|
|
3362
|
+
window.addEventListener("popstate", onPopState);
|
|
3363
|
+
cleanups.push(() => window.removeEventListener("popstate", onPopState));
|
|
2705
3364
|
}
|
|
2706
3365
|
const timer = setInterval(() => {
|
|
2707
3366
|
flush();
|
|
@@ -2734,6 +3393,7 @@ var createBeacon = (options) => {
|
|
|
2734
3393
|
await flush(true);
|
|
2735
3394
|
},
|
|
2736
3395
|
flush: () => flush(false),
|
|
3396
|
+
observeCapability,
|
|
2737
3397
|
setTags: (next) => {
|
|
2738
3398
|
tags = { ...tags, ...next };
|
|
2739
3399
|
},
|
|
@@ -2751,8 +3411,10 @@ var getBeacon = () => current;
|
|
|
2751
3411
|
var captureException = (error, context) => current?.captureException(error, context);
|
|
2752
3412
|
var captureMessage = (message, level, context) => current?.captureMessage(message, level, context);
|
|
2753
3413
|
var addBreadcrumb = (crumb) => current?.addBreadcrumb(crumb);
|
|
3414
|
+
var observeCapability = (name, operation) => current?.observeCapability(name, operation) ?? operation;
|
|
2754
3415
|
export {
|
|
2755
3416
|
redactBeaconEvent,
|
|
3417
|
+
observeCapability,
|
|
2756
3418
|
isKnownBeaconNoise,
|
|
2757
3419
|
initBeacon,
|
|
2758
3420
|
getBeacon,
|
|
@@ -2765,5 +3427,5 @@ export {
|
|
|
2765
3427
|
BEACON_ATTRIBUTE
|
|
2766
3428
|
};
|
|
2767
3429
|
|
|
2768
|
-
//# debugId=
|
|
3430
|
+
//# debugId=3F33DA64F851A28864756E2164756E21
|
|
2769
3431
|
//# sourceMappingURL=index.js.map
|