@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 +32 -1
- package/dist/index.d.ts +133 -0
- package/dist/index.js +974 -16
- package/dist/index.js.map +3 -3
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -10,39 +10,66 @@ 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",
|
|
19
|
+
CLIPBOARD_FAILURE: "clipboard_failure",
|
|
15
20
|
DEAD_CLICK: "dead_click",
|
|
21
|
+
DISRUPTIVE_LAYOUT_SHIFT: "disruptive_layout_shift",
|
|
22
|
+
DOCUMENT_DISCARDED: "document_discarded",
|
|
23
|
+
ERROR_CLICK: "error_click",
|
|
16
24
|
FETCH_FAILED: "fetch_failed",
|
|
17
25
|
FOCUS_LOST: "focus_lost",
|
|
18
26
|
FONT_FAILURE: "font_failure",
|
|
19
27
|
FORM_FRUSTRATION: "form_frustration",
|
|
28
|
+
FORM_ABANDONMENT: "form_abandonment",
|
|
29
|
+
FOCUSED_CONTROL_OFFSCREEN: "focused_control_offscreen",
|
|
20
30
|
HTTP_5XX: "http_5xx",
|
|
21
31
|
INVISIBLE_TEXT: "invisible_text",
|
|
32
|
+
EMBEDDED_CONTENT_STALLED: "embedded_content_stalled",
|
|
22
33
|
LAYOUT_OVERFLOW: "layout_overflow",
|
|
23
34
|
MAIN_THREAD_STALL: "main_thread_stall",
|
|
35
|
+
MEDIA_PLAYBACK_FAILED: "media_playback_failed",
|
|
36
|
+
MEDIA_PLAYBACK_STALLED: "media_playback_stalled",
|
|
24
37
|
MODAL_FOCUS_ESCAPE: "modal_focus_escape",
|
|
25
38
|
OCCLUDED_CONTROL: "occluded_control",
|
|
26
39
|
RAGE_CLICK: "rage_click",
|
|
27
40
|
RATE_LIMITED: "rate_limited",
|
|
41
|
+
NAVIGATION_STALLED: "navigation_stalled",
|
|
28
42
|
RELOAD_LOOP: "reload_loop",
|
|
29
43
|
REQUEST_STORM: "request_storm",
|
|
44
|
+
SEMANTIC_RESPONSE_FAILURE: "semantic_response_failure",
|
|
30
45
|
SCROLL_JAIL: "scroll_jail",
|
|
31
46
|
SLOW_RESPONSE: "slow_response",
|
|
47
|
+
SLOW_RESOURCE: "slow_resource",
|
|
48
|
+
SLOW_INTERACTION: "slow_interaction",
|
|
32
49
|
SOCKET_ABNORMAL_CLOSE: "socket_abnormal_close",
|
|
33
50
|
SOCKET_FLAPPING: "socket_flapping",
|
|
34
51
|
SSE_FLAPPING: "sse_flapping",
|
|
35
52
|
STALE_RELEASE: "stale_release",
|
|
36
53
|
STALLED_STREAM: "stalled_stream",
|
|
37
54
|
STUCK_LOADING: "stuck_loading",
|
|
55
|
+
THEME_MISMATCH: "theme_mismatch",
|
|
56
|
+
THRASHED_CURSOR: "thrashed_cursor",
|
|
57
|
+
STORAGE_FAILURE: "storage_failure",
|
|
58
|
+
WEBGL_CONTEXT_LOST: "webgl_context_lost",
|
|
38
59
|
SERVICE_WORKER_FAILURE: "service_worker_failure",
|
|
39
60
|
WORKER_FAILURE: "worker_failure"
|
|
40
61
|
};
|
|
41
62
|
var BEACON_ATTRIBUTE = {
|
|
63
|
+
APP_ROOT: "data-beacon-app-root",
|
|
42
64
|
DEAD_CLICK: "data-beacon-dead-click",
|
|
43
65
|
NAME: "data-beacon-name",
|
|
66
|
+
EMBED: "data-beacon-embed",
|
|
67
|
+
LOADING: "data-beacon-loading",
|
|
68
|
+
FORM: "data-beacon-form",
|
|
69
|
+
MEDIA: "data-beacon-media",
|
|
44
70
|
OVERFLOW: "data-beacon-overflow",
|
|
45
|
-
SCAN: "data-beacon-scan"
|
|
71
|
+
SCAN: "data-beacon-scan",
|
|
72
|
+
THEME: "data-beacon-theme"
|
|
46
73
|
};
|
|
47
74
|
var BEACON_TRACE_HEADER = "x-absolute-trace-id";
|
|
48
75
|
var inBrowser = () => typeof window !== "undefined";
|
|
@@ -482,8 +509,37 @@ var observeLongTasks = (report, navigationType) => {
|
|
|
482
509
|
} catch {}
|
|
483
510
|
};
|
|
484
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
|
+
};
|
|
485
541
|
var loadWebVitals = async () => {
|
|
486
|
-
const mod = await import("web-vitals");
|
|
542
|
+
const mod = await import("web-vitals/attribution");
|
|
487
543
|
return mod;
|
|
488
544
|
};
|
|
489
545
|
var observeWebVitals = (webVitals, report) => {
|
|
@@ -499,6 +555,7 @@ var noopBeacon = {
|
|
|
499
555
|
captureMessage: () => {},
|
|
500
556
|
close: async () => {},
|
|
501
557
|
flush: async () => {},
|
|
558
|
+
observeCapability: async (_name, operation) => operation,
|
|
502
559
|
setTags: () => {},
|
|
503
560
|
setUser: () => {}
|
|
504
561
|
};
|
|
@@ -540,6 +597,14 @@ var createBeacon = (options) => {
|
|
|
540
597
|
const RAGE_WINDOW_MS = 1000;
|
|
541
598
|
const RAGE_RADIUS_PX = 40;
|
|
542
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;
|
|
543
608
|
const NAVIGATION_RESPONSE_DEFAULT_MS = 8000;
|
|
544
609
|
const LAYOUT_OVERFLOW_SETTLE_DEFAULT_MS = 600;
|
|
545
610
|
const LAYOUT_OVERFLOW_MAX_REPORTS_DEFAULT = 5;
|
|
@@ -553,8 +618,16 @@ var createBeacon = (options) => {
|
|
|
553
618
|
const OCCLUSION_COVERAGE_MIN = 0.9;
|
|
554
619
|
const INVISIBLE_TEXT_SAMPLE_LIMIT = 40;
|
|
555
620
|
const INVISIBLE_TEXT_CONTRAST_MAX = 1.2;
|
|
621
|
+
const THEME_SURFACE_SAMPLE_LIMIT = 200;
|
|
622
|
+
const THEME_MISMATCH_DEFAULT_MIN_AREA = 1e4;
|
|
623
|
+
const THEME_DARK_SURFACE_LUMINANCE_MAX = 0.12;
|
|
624
|
+
const THEME_LIGHT_SURFACE_LUMINANCE_MIN = 0.85;
|
|
556
625
|
const STUCK_LOADING_DEFAULT_MS = 20000;
|
|
557
626
|
const STUCK_LOADING_POLL_MS = 5000;
|
|
627
|
+
const EMBEDDED_CONTENT_STALL_DEFAULT_MS = 15000;
|
|
628
|
+
const WEBGL_RESTORE_GRACE_DEFAULT_MS = 2000;
|
|
629
|
+
const FOCUSED_CONTROL_SETTLE_DEFAULT_MS = 500;
|
|
630
|
+
const KEYBOARD_VIEWPORT_HEIGHT_RATIO_MAX = 0.8;
|
|
558
631
|
const SCROLL_JAIL_EVENT_COUNT = 8;
|
|
559
632
|
const SCROLL_JAIL_WINDOW_MS = 2000;
|
|
560
633
|
const SCROLL_JAIL_BOUNDARY_TOLERANCE_PX = 2;
|
|
@@ -588,6 +661,9 @@ var createBeacon = (options) => {
|
|
|
588
661
|
let externalNavigationCount = 0;
|
|
589
662
|
let inSignalConsole = false;
|
|
590
663
|
let pageLifecycleEnding = false;
|
|
664
|
+
let recentInteraction;
|
|
665
|
+
let reportErrorClick = null;
|
|
666
|
+
let reportFormAbandonmentOnNavigation = null;
|
|
591
667
|
let overflowScanOnNavigation = null;
|
|
592
668
|
let recordRequestForStorm = null;
|
|
593
669
|
const OVERLAY_VIEWPORT_COVERAGE_MIN = 0.9;
|
|
@@ -639,7 +715,8 @@ var createBeacon = (options) => {
|
|
|
639
715
|
schemaVersion: vitalsOptions.schemaVersion ?? 1,
|
|
640
716
|
...vitalsOptions.sdkVersion === undefined ? {} : { sdkVersion: vitalsOptions.sdkVersion },
|
|
641
717
|
...traceId === undefined ? {} : { traceId },
|
|
642
|
-
value: metric.value
|
|
718
|
+
value: metric.value,
|
|
719
|
+
...vitalAttribution(metric.attribution) === undefined ? {} : { attribution: vitalAttribution(metric.attribution) }
|
|
643
720
|
};
|
|
644
721
|
vitalsOptions.onVital?.(vital);
|
|
645
722
|
if (vitalsOptions.transport !== undefined) {
|
|
@@ -681,6 +758,17 @@ var createBeacon = (options) => {
|
|
|
681
758
|
let flushPendingNetworkFailures = () => {};
|
|
682
759
|
let tags = {};
|
|
683
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
|
+
};
|
|
684
772
|
const flush = async (useBeacon = false) => {
|
|
685
773
|
flushPendingNetworkFailures();
|
|
686
774
|
if (buffer.length === 0)
|
|
@@ -717,7 +805,16 @@ var createBeacon = (options) => {
|
|
|
717
805
|
const replayId = options.getReplayId?.();
|
|
718
806
|
if (replayId !== undefined)
|
|
719
807
|
enriched.replayId = replayId;
|
|
720
|
-
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
|
+
};
|
|
721
818
|
if (Object.keys(mergedTags).length > 0)
|
|
722
819
|
enriched.tags = mergedTags;
|
|
723
820
|
const extra = { sessionId, ...event.extra };
|
|
@@ -805,6 +902,41 @@ var createBeacon = (options) => {
|
|
|
805
902
|
...extra !== undefined ? { extra } : {}
|
|
806
903
|
});
|
|
807
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
|
+
};
|
|
808
940
|
const responseTraceId = (value) => {
|
|
809
941
|
const traceId = value?.trim().toLowerCase();
|
|
810
942
|
return traceId !== undefined && /^[0-9a-f]{32}$/.test(traceId) ? traceId : undefined;
|
|
@@ -877,7 +1009,16 @@ var createBeacon = (options) => {
|
|
|
877
1009
|
let networkFailureTimer;
|
|
878
1010
|
const networkState = () => {
|
|
879
1011
|
const online = typeof navigator.onLine === "boolean" ? navigator.onLine : null;
|
|
1012
|
+
const connection = navigator.connection;
|
|
880
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
|
+
},
|
|
881
1022
|
online,
|
|
882
1023
|
visibilityState: typeof document.visibilityState === "string" ? document.visibilityState : "unknown"
|
|
883
1024
|
};
|
|
@@ -972,6 +1113,7 @@ var createBeacon = (options) => {
|
|
|
972
1113
|
},
|
|
973
1114
|
method: method.toUpperCase(),
|
|
974
1115
|
online: state.online,
|
|
1116
|
+
...state.connection === undefined ? {} : { connection: state.connection },
|
|
975
1117
|
transport: transportKind,
|
|
976
1118
|
visibilityState: state.visibilityState
|
|
977
1119
|
};
|
|
@@ -1002,7 +1144,7 @@ var createBeacon = (options) => {
|
|
|
1002
1144
|
routerAcceptedNavigation = control instanceof HTMLAnchorElement && handledEvent.defaultPrevented;
|
|
1003
1145
|
};
|
|
1004
1146
|
const responded = () => mutated || formStateChanged(formBefore) || location.href !== urlBefore || window.scrollY !== scrollBefore || document.activeElement !== activeBefore || networkRequestCount !== networkRequestsBefore || externalNavigationCount !== externalNavigationsBefore;
|
|
1005
|
-
const finish = (didRespond) => {
|
|
1147
|
+
const finish = (didRespond, navigationStalled = false) => {
|
|
1006
1148
|
if (finished)
|
|
1007
1149
|
return;
|
|
1008
1150
|
finished = true;
|
|
@@ -1011,7 +1153,7 @@ var createBeacon = (options) => {
|
|
|
1011
1153
|
if (timer2 !== undefined)
|
|
1012
1154
|
window.clearTimeout(timer2);
|
|
1013
1155
|
pendingClickCleanups.delete(cancel);
|
|
1014
|
-
report(didRespond);
|
|
1156
|
+
report(didRespond, navigationStalled);
|
|
1015
1157
|
};
|
|
1016
1158
|
const cancel = () => {
|
|
1017
1159
|
if (finished)
|
|
@@ -1024,8 +1166,7 @@ var createBeacon = (options) => {
|
|
|
1024
1166
|
};
|
|
1025
1167
|
const observer = new MutationObserver(() => {
|
|
1026
1168
|
mutated = true;
|
|
1027
|
-
|
|
1028
|
-
finish(true);
|
|
1169
|
+
finish(true);
|
|
1029
1170
|
});
|
|
1030
1171
|
observer.observe(document.body, {
|
|
1031
1172
|
attributes: true,
|
|
@@ -1044,7 +1185,10 @@ var createBeacon = (options) => {
|
|
|
1044
1185
|
return;
|
|
1045
1186
|
}
|
|
1046
1187
|
extended = true;
|
|
1047
|
-
timer2 = window.setTimeout(() =>
|
|
1188
|
+
timer2 = window.setTimeout(() => {
|
|
1189
|
+
const didRespond = responded();
|
|
1190
|
+
finish(didRespond, !didRespond);
|
|
1191
|
+
}, navigationResponseMs - DEAD_CLICK_WINDOW_MS);
|
|
1048
1192
|
}, DEAD_CLICK_WINDOW_MS);
|
|
1049
1193
|
};
|
|
1050
1194
|
const clickSignalMessage = (message, control) => `${message} — ${shortUrl(location.href)} — ${describeElement(control)}`;
|
|
@@ -1103,6 +1247,37 @@ var createBeacon = (options) => {
|
|
|
1103
1247
|
cleanups.push(() => observer.disconnect());
|
|
1104
1248
|
} catch {}
|
|
1105
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
|
+
}
|
|
1106
1281
|
if (signals !== null && signals.mainThreadStalls !== false && typeof PerformanceObserver !== "undefined") {
|
|
1107
1282
|
const stallMs = signals.mainThreadStallMs ?? MAIN_THREAD_STALL_DEFAULT_MS;
|
|
1108
1283
|
const stallCount = signals.mainThreadStallCount ?? MAIN_THREAD_STALL_DEFAULT_COUNT;
|
|
@@ -1122,10 +1297,18 @@ var createBeacon = (options) => {
|
|
|
1122
1297
|
if (stallTimes.length < stallCount)
|
|
1123
1298
|
continue;
|
|
1124
1299
|
reported = true;
|
|
1300
|
+
const animationFrame = entry;
|
|
1301
|
+
const script = [...animationFrame.scripts ?? []].sort((left, right) => (right.duration ?? 0) - (left.duration ?? 0))[0];
|
|
1125
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
|
+
},
|
|
1126
1306
|
durationMs: String(Math.round(entry.duration)),
|
|
1127
1307
|
entryType: entry.entryType,
|
|
1128
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) },
|
|
1129
1312
|
stallCount: String(stallTimes.length),
|
|
1130
1313
|
windowMs: String(stallWindowMs)
|
|
1131
1314
|
});
|
|
@@ -1150,6 +1333,69 @@ var createBeacon = (options) => {
|
|
|
1150
1333
|
cleanups.push(() => observer.disconnect());
|
|
1151
1334
|
} catch {}
|
|
1152
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
|
+
}
|
|
1153
1399
|
if (instrument.globalErrors !== false) {
|
|
1154
1400
|
const onError = (event) => {
|
|
1155
1401
|
if (event instanceof ErrorEvent) {
|
|
@@ -1159,6 +1405,7 @@ var createBeacon = (options) => {
|
|
|
1159
1405
|
level: "error",
|
|
1160
1406
|
tags: errorEventTags(event)
|
|
1161
1407
|
});
|
|
1408
|
+
reportErrorClick?.(error.name);
|
|
1162
1409
|
return;
|
|
1163
1410
|
}
|
|
1164
1411
|
const target = event.target;
|
|
@@ -1197,6 +1444,7 @@ var createBeacon = (options) => {
|
|
|
1197
1444
|
const reason = event.reason;
|
|
1198
1445
|
if (reason instanceof Error) {
|
|
1199
1446
|
captureException(reason, { level: "error" });
|
|
1447
|
+
reportErrorClick?.(reason.name);
|
|
1200
1448
|
return;
|
|
1201
1449
|
}
|
|
1202
1450
|
if (typeof reason === "object" && reason !== null && typeof reason.stack === "string") {
|
|
@@ -1210,6 +1458,7 @@ var createBeacon = (options) => {
|
|
|
1210
1458
|
},
|
|
1211
1459
|
level: "error"
|
|
1212
1460
|
});
|
|
1461
|
+
reportErrorClick?.("UnhandledRejection");
|
|
1213
1462
|
};
|
|
1214
1463
|
window.addEventListener("unhandledrejection", onRejection);
|
|
1215
1464
|
cleanups.push(() => window.removeEventListener("unhandledrejection", onRejection));
|
|
@@ -1227,6 +1476,8 @@ var createBeacon = (options) => {
|
|
|
1227
1476
|
const text = args.map(String).join(" ").trim().slice(0, SIGNAL_TEXT_MAX);
|
|
1228
1477
|
if (text !== "")
|
|
1229
1478
|
emitSignal(text, { signal: BEACON_SIGNAL.CONSOLE_ERROR }, undefined, undefined, wrappedConsole, 2);
|
|
1479
|
+
if (text !== "")
|
|
1480
|
+
reportErrorClick?.("ConsoleError");
|
|
1230
1481
|
inSignalConsole = false;
|
|
1231
1482
|
}
|
|
1232
1483
|
original.apply(console, args);
|
|
@@ -1237,6 +1488,35 @@ var createBeacon = (options) => {
|
|
|
1237
1488
|
});
|
|
1238
1489
|
}
|
|
1239
1490
|
}
|
|
1491
|
+
if (signals !== null && signals.clipboardFailures !== false && typeof navigator !== "undefined" && navigator.clipboard !== undefined && typeof navigator.clipboard.writeText === "function") {
|
|
1492
|
+
const clipboard = navigator.clipboard;
|
|
1493
|
+
const originalWriteText = clipboard.writeText;
|
|
1494
|
+
const wrappedWriteText = async (value) => {
|
|
1495
|
+
const target = typeof document !== "undefined" && document.activeElement instanceof Element ? describeElement(document.activeElement) : "unknown";
|
|
1496
|
+
const activation = navigator.userActivation?.isActive ?? false;
|
|
1497
|
+
try {
|
|
1498
|
+
return await originalWriteText.call(clipboard, value);
|
|
1499
|
+
} catch (error) {
|
|
1500
|
+
if (!pageLifecycleEnding && typeof document !== "undefined" && document.visibilityState !== "hidden") {
|
|
1501
|
+
const resolved = toError(error);
|
|
1502
|
+
emitSignal(`Clipboard write failed — ${target} — ${shortUrl(location.href)}`, {
|
|
1503
|
+
errorName: resolved.name,
|
|
1504
|
+
secureContext: String(globalThis.isSecureContext === true),
|
|
1505
|
+
signal: BEACON_SIGNAL.CLIPBOARD_FAILURE,
|
|
1506
|
+
target,
|
|
1507
|
+
userActivation: String(activation)
|
|
1508
|
+
});
|
|
1509
|
+
}
|
|
1510
|
+
throw error;
|
|
1511
|
+
}
|
|
1512
|
+
};
|
|
1513
|
+
try {
|
|
1514
|
+
clipboard.writeText = wrappedWriteText;
|
|
1515
|
+
cleanups.push(() => {
|
|
1516
|
+
clipboard.writeText = originalWriteText;
|
|
1517
|
+
});
|
|
1518
|
+
} catch {}
|
|
1519
|
+
}
|
|
1240
1520
|
if (instrument.clicks !== false && typeof document !== "undefined") {
|
|
1241
1521
|
if (signals !== null) {
|
|
1242
1522
|
const originalWindowOpen = window.open;
|
|
@@ -1255,9 +1535,16 @@ var createBeacon = (options) => {
|
|
|
1255
1535
|
const target = event.target;
|
|
1256
1536
|
if (!(target instanceof Element))
|
|
1257
1537
|
return;
|
|
1258
|
-
|
|
1538
|
+
const targetName = describeElement(target);
|
|
1539
|
+
beginAction("click", targetName);
|
|
1540
|
+
addBreadcrumb({ message: targetName, type: "click" });
|
|
1259
1541
|
if (signals === null)
|
|
1260
1542
|
return;
|
|
1543
|
+
recentInteraction = {
|
|
1544
|
+
at: Date.now(),
|
|
1545
|
+
target: targetName,
|
|
1546
|
+
type: "click"
|
|
1547
|
+
};
|
|
1261
1548
|
const control = deadClickCandidate(target, event);
|
|
1262
1549
|
if (control === null)
|
|
1263
1550
|
return;
|
|
@@ -1268,11 +1555,18 @@ var createBeacon = (options) => {
|
|
|
1268
1555
|
const clickedAt = Date.now();
|
|
1269
1556
|
const x = event instanceof MouseEvent ? event.clientX : 0;
|
|
1270
1557
|
const y = event instanceof MouseEvent ? event.clientY : 0;
|
|
1271
|
-
observeClickResponse(control, event, (responded) => {
|
|
1558
|
+
observeClickResponse(control, event, (responded, navigationStalled) => {
|
|
1272
1559
|
if (responded) {
|
|
1273
1560
|
unresponsiveClicks = unresponsiveClicks.filter((click) => click.control !== control);
|
|
1274
1561
|
return;
|
|
1275
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
|
+
}
|
|
1276
1570
|
if (detectDead) {
|
|
1277
1571
|
emitSignal(clickSignalMessage("Dead click — control didn't respond", control), {
|
|
1278
1572
|
signal: BEACON_SIGNAL.DEAD_CLICK,
|
|
@@ -1293,16 +1587,50 @@ var createBeacon = (options) => {
|
|
|
1293
1587
|
});
|
|
1294
1588
|
};
|
|
1295
1589
|
document.addEventListener("click", onClick, true);
|
|
1296
|
-
|
|
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
|
+
});
|
|
1297
1622
|
}
|
|
1298
1623
|
if (signals !== null && typeof document !== "undefined" && typeof window.getComputedStyle === "function") {
|
|
1299
1624
|
const detectOverflow = signals.layoutOverflows !== false;
|
|
1300
1625
|
const detectOcclusion = signals.occludedControls !== false;
|
|
1301
1626
|
const detectInvisibleText = signals.invisibleText !== false;
|
|
1302
1627
|
const detectStuckLoading = signals.stuckLoading !== false;
|
|
1628
|
+
const detectThemeMismatch = signals.themeMismatches !== false;
|
|
1629
|
+
const detectBlankAppRoot = signals.blankAppRoots !== false;
|
|
1303
1630
|
const overflowSettleMs = signals.layoutOverflowSettleMs ?? LAYOUT_OVERFLOW_SETTLE_DEFAULT_MS;
|
|
1304
1631
|
const overflowMaxReports = signals.layoutOverflowMaxReports ?? LAYOUT_OVERFLOW_MAX_REPORTS_DEFAULT;
|
|
1305
1632
|
const stuckLoadingMs = signals.stuckLoadingMs ?? STUCK_LOADING_DEFAULT_MS;
|
|
1633
|
+
const themeMismatchMinArea = signals.themeMismatchMinArea ?? THEME_MISMATCH_DEFAULT_MIN_AREA;
|
|
1306
1634
|
const seenOverflows = new Set;
|
|
1307
1635
|
let overflowReports = 0;
|
|
1308
1636
|
let overflowTimer;
|
|
@@ -1603,12 +1931,72 @@ var createBeacon = (options) => {
|
|
|
1603
1931
|
});
|
|
1604
1932
|
}
|
|
1605
1933
|
};
|
|
1934
|
+
const activeTheme = () => {
|
|
1935
|
+
const root = document.documentElement;
|
|
1936
|
+
const declared = window.getComputedStyle(root).colorScheme.trim();
|
|
1937
|
+
if (declared === "dark")
|
|
1938
|
+
return "dark";
|
|
1939
|
+
if (declared === "light")
|
|
1940
|
+
return "light";
|
|
1941
|
+
const dataTheme = root.getAttribute("data-theme");
|
|
1942
|
+
if (dataTheme === "dark" || dataTheme === "light")
|
|
1943
|
+
return dataTheme;
|
|
1944
|
+
if (root.classList.contains("dark"))
|
|
1945
|
+
return "dark";
|
|
1946
|
+
return null;
|
|
1947
|
+
};
|
|
1948
|
+
const scanForThemeMismatch = () => {
|
|
1949
|
+
const theme = activeTheme();
|
|
1950
|
+
if (theme === null)
|
|
1951
|
+
return;
|
|
1952
|
+
const roots = document.querySelectorAll(`[${BEACON_ATTRIBUTE.THEME}="adaptive"]`);
|
|
1953
|
+
const viewportWidth = document.documentElement.clientWidth;
|
|
1954
|
+
const viewportHeight = document.documentElement.clientHeight;
|
|
1955
|
+
let sampled = 0;
|
|
1956
|
+
for (const root of Array.from(roots)) {
|
|
1957
|
+
const candidates = [root, ...Array.from(root.querySelectorAll("*"))];
|
|
1958
|
+
for (const element of candidates) {
|
|
1959
|
+
if (sampled >= THEME_SURFACE_SAMPLE_LIMIT)
|
|
1960
|
+
return;
|
|
1961
|
+
if (element.closest(`[${BEACON_ATTRIBUTE.THEME}="allow"]`) !== null || isScanExempt(element) || element.matches("canvas, iframe, img, picture, svg, video")) {
|
|
1962
|
+
continue;
|
|
1963
|
+
}
|
|
1964
|
+
const rect = element.getBoundingClientRect();
|
|
1965
|
+
if (rect.width * rect.height < themeMismatchMinArea)
|
|
1966
|
+
continue;
|
|
1967
|
+
if (rect.bottom < 0 || rect.top > viewportHeight || rect.right < 0 || rect.left > viewportWidth) {
|
|
1968
|
+
continue;
|
|
1969
|
+
}
|
|
1970
|
+
const hasContent = (element.textContent ?? "").trim() !== "" || element.querySelector("button, input, select, textarea, [role=button]") !== null;
|
|
1971
|
+
if (!hasContent)
|
|
1972
|
+
continue;
|
|
1973
|
+
const style = window.getComputedStyle(element);
|
|
1974
|
+
if (style.display === "none" || style.visibility === "hidden" || style.backgroundImage !== "none" && style.backgroundImage !== "") {
|
|
1975
|
+
continue;
|
|
1976
|
+
}
|
|
1977
|
+
const surface = parseColor(style.backgroundColor);
|
|
1978
|
+
if (surface === null || surface.a < 0.95)
|
|
1979
|
+
continue;
|
|
1980
|
+
sampled += 1;
|
|
1981
|
+
const luminance = relativeLuminance(surface);
|
|
1982
|
+
const opposite = theme === "dark" ? luminance >= THEME_LIGHT_SURFACE_LUMINANCE_MIN : luminance <= THEME_DARK_SURFACE_LUMINANCE_MAX;
|
|
1983
|
+
if (!opposite)
|
|
1984
|
+
continue;
|
|
1985
|
+
reportScanIssue(element, BEACON_SIGNAL.THEME_MISMATCH, `Theme mismatch — ${describeElement(element)} renders an opposite-polarity surface in ${theme} mode`, {
|
|
1986
|
+
activeTheme: theme,
|
|
1987
|
+
area: String(Math.round(rect.width * rect.height)),
|
|
1988
|
+
surfaceColor: style.backgroundColor,
|
|
1989
|
+
surfaceLuminance: luminance.toFixed(3)
|
|
1990
|
+
});
|
|
1991
|
+
}
|
|
1992
|
+
}
|
|
1993
|
+
};
|
|
1606
1994
|
const loadingFirstSeen = new WeakMap;
|
|
1607
1995
|
const reportedStuckLoading = new WeakSet;
|
|
1608
1996
|
const checkStuckLoading = () => {
|
|
1609
1997
|
if (document.visibilityState === "hidden")
|
|
1610
1998
|
return;
|
|
1611
|
-
const indicators = document.querySelectorAll(
|
|
1999
|
+
const indicators = document.querySelectorAll(`[aria-busy="true"], [role="progressbar"], [${BEACON_ATTRIBUTE.LOADING}]`);
|
|
1612
2000
|
const now = Date.now();
|
|
1613
2001
|
for (const indicator of Array.from(indicators)) {
|
|
1614
2002
|
if (isScanExempt(indicator))
|
|
@@ -1628,6 +2016,25 @@ var createBeacon = (options) => {
|
|
|
1628
2016
|
reportScanIssue(indicator, BEACON_SIGNAL.STUCK_LOADING, `Stuck loading — ${describeElement(indicator)} never resolved`, { visibleMs: String(now - firstSeen) });
|
|
1629
2017
|
}
|
|
1630
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
|
+
};
|
|
1631
2038
|
const runSettledScan = () => {
|
|
1632
2039
|
if (detectOverflow)
|
|
1633
2040
|
scanForOverflow();
|
|
@@ -1635,6 +2042,8 @@ var createBeacon = (options) => {
|
|
|
1635
2042
|
scanForOcclusion();
|
|
1636
2043
|
if (detectInvisibleText)
|
|
1637
2044
|
scanForInvisibleText();
|
|
2045
|
+
if (detectThemeMismatch)
|
|
2046
|
+
scanForThemeMismatch();
|
|
1638
2047
|
if (detectStuckLoading)
|
|
1639
2048
|
checkStuckLoading();
|
|
1640
2049
|
};
|
|
@@ -1654,9 +2063,15 @@ var createBeacon = (options) => {
|
|
|
1654
2063
|
cleanups.push(() => window.removeEventListener("load", onLoad));
|
|
1655
2064
|
}
|
|
1656
2065
|
window.addEventListener("resize", scheduleOverflowScan);
|
|
2066
|
+
const themeObserver = new MutationObserver(scheduleOverflowScan);
|
|
2067
|
+
themeObserver.observe(document.documentElement, {
|
|
2068
|
+
attributeFilter: ["class", "data-theme", "style"],
|
|
2069
|
+
attributes: true
|
|
2070
|
+
});
|
|
1657
2071
|
overflowScanOnNavigation = scheduleOverflowScan;
|
|
1658
2072
|
cleanups.push(() => {
|
|
1659
2073
|
window.removeEventListener("resize", scheduleOverflowScan);
|
|
2074
|
+
themeObserver.disconnect();
|
|
1660
2075
|
overflowScanOnNavigation = null;
|
|
1661
2076
|
if (overflowTimer !== undefined)
|
|
1662
2077
|
clearTimeout(overflowTimer);
|
|
@@ -1666,8 +2081,427 @@ var createBeacon = (options) => {
|
|
|
1666
2081
|
stuckTimer.unref?.();
|
|
1667
2082
|
cleanups.push(() => clearInterval(stuckTimer));
|
|
1668
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 {}
|
|
2175
|
+
}
|
|
2176
|
+
if (signals !== null && signals.embeddedContentStalls !== false && typeof document !== "undefined") {
|
|
2177
|
+
const stallMs = signals.embeddedContentStallMs ?? EMBEDDED_CONTENT_STALL_DEFAULT_MS;
|
|
2178
|
+
const watched = new Map;
|
|
2179
|
+
const stopWatching = (frame) => {
|
|
2180
|
+
const state = watched.get(frame);
|
|
2181
|
+
if (state === undefined)
|
|
2182
|
+
return;
|
|
2183
|
+
clearTimeout(state.timer);
|
|
2184
|
+
frame.removeEventListener("load", state.onLoad);
|
|
2185
|
+
watched.delete(frame);
|
|
2186
|
+
};
|
|
2187
|
+
const watchFrame = (frame) => {
|
|
2188
|
+
stopWatching(frame);
|
|
2189
|
+
const name = frame.getAttribute(BEACON_ATTRIBUTE.EMBED);
|
|
2190
|
+
if (name === null)
|
|
2191
|
+
return;
|
|
2192
|
+
const onLoad = () => stopWatching(frame);
|
|
2193
|
+
const timer2 = setTimeout(() => {
|
|
2194
|
+
stopWatching(frame);
|
|
2195
|
+
if (pageLifecycleEnding || document.visibilityState === "hidden" || !frame.isConnected) {
|
|
2196
|
+
return;
|
|
2197
|
+
}
|
|
2198
|
+
const rect = frame.getBoundingClientRect();
|
|
2199
|
+
if (rect.width === 0 || rect.height === 0)
|
|
2200
|
+
return;
|
|
2201
|
+
const source = frame.getAttribute("src") ?? "";
|
|
2202
|
+
emitSignal(`Embedded content stalled — ${describeElement(frame)} never loaded — ${shortUrl(location.href)}`, {
|
|
2203
|
+
embed: name.slice(0, 64),
|
|
2204
|
+
elapsedMs: String(stallMs),
|
|
2205
|
+
signal: BEACON_SIGNAL.EMBEDDED_CONTENT_STALLED,
|
|
2206
|
+
sourcePath: shortUrl(source),
|
|
2207
|
+
target: describeElement(frame)
|
|
2208
|
+
});
|
|
2209
|
+
}, stallMs);
|
|
2210
|
+
watched.set(frame, { onLoad, timer: timer2 });
|
|
2211
|
+
frame.addEventListener("load", onLoad, { once: true });
|
|
2212
|
+
};
|
|
2213
|
+
const discoverFrames = (root) => {
|
|
2214
|
+
if (root instanceof HTMLIFrameElement && root.hasAttribute(BEACON_ATTRIBUTE.EMBED)) {
|
|
2215
|
+
watchFrame(root);
|
|
2216
|
+
}
|
|
2217
|
+
for (const frame of Array.from(root.querySelectorAll(`iframe[${BEACON_ATTRIBUTE.EMBED}]`))) {
|
|
2218
|
+
watchFrame(frame);
|
|
2219
|
+
}
|
|
2220
|
+
};
|
|
2221
|
+
discoverFrames(document);
|
|
2222
|
+
const observer = new MutationObserver((records) => {
|
|
2223
|
+
for (const record of records) {
|
|
2224
|
+
if (record.type === "attributes") {
|
|
2225
|
+
if (record.target instanceof HTMLIFrameElement) {
|
|
2226
|
+
watchFrame(record.target);
|
|
2227
|
+
}
|
|
2228
|
+
continue;
|
|
2229
|
+
}
|
|
2230
|
+
for (const node of Array.from(record.addedNodes)) {
|
|
2231
|
+
if (node instanceof Element)
|
|
2232
|
+
discoverFrames(node);
|
|
2233
|
+
}
|
|
2234
|
+
for (const node of Array.from(record.removedNodes)) {
|
|
2235
|
+
if (node instanceof HTMLIFrameElement)
|
|
2236
|
+
stopWatching(node);
|
|
2237
|
+
if (node instanceof Element) {
|
|
2238
|
+
for (const frame of Array.from(node.querySelectorAll("iframe"))) {
|
|
2239
|
+
stopWatching(frame);
|
|
2240
|
+
}
|
|
2241
|
+
}
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
});
|
|
2245
|
+
observer.observe(document.documentElement, {
|
|
2246
|
+
attributeFilter: [BEACON_ATTRIBUTE.EMBED, "src"],
|
|
2247
|
+
attributes: true,
|
|
2248
|
+
childList: true,
|
|
2249
|
+
subtree: true
|
|
2250
|
+
});
|
|
2251
|
+
cleanups.push(() => {
|
|
2252
|
+
observer.disconnect();
|
|
2253
|
+
for (const frame of Array.from(watched.keys()))
|
|
2254
|
+
stopWatching(frame);
|
|
2255
|
+
});
|
|
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
|
+
}
|
|
2404
|
+
if (signals !== null && signals.webglContextLosses !== false && typeof document !== "undefined") {
|
|
2405
|
+
const graceMs = signals.webglRestoreGraceMs ?? WEBGL_RESTORE_GRACE_DEFAULT_MS;
|
|
2406
|
+
const pending = new Map;
|
|
2407
|
+
const reported = new WeakSet;
|
|
2408
|
+
const clearPending = (canvas) => {
|
|
2409
|
+
const timer2 = pending.get(canvas);
|
|
2410
|
+
if (timer2 !== undefined)
|
|
2411
|
+
clearTimeout(timer2);
|
|
2412
|
+
pending.delete(canvas);
|
|
2413
|
+
};
|
|
2414
|
+
const onLost = (event) => {
|
|
2415
|
+
if (!(event.target instanceof HTMLCanvasElement))
|
|
2416
|
+
return;
|
|
2417
|
+
const canvas = event.target;
|
|
2418
|
+
clearPending(canvas);
|
|
2419
|
+
const timer2 = setTimeout(() => {
|
|
2420
|
+
pending.delete(canvas);
|
|
2421
|
+
if (reported.has(canvas) || pageLifecycleEnding || document.visibilityState === "hidden" || !canvas.isConnected) {
|
|
2422
|
+
return;
|
|
2423
|
+
}
|
|
2424
|
+
const rect = canvas.getBoundingClientRect();
|
|
2425
|
+
if (rect.width === 0 || rect.height === 0)
|
|
2426
|
+
return;
|
|
2427
|
+
reported.add(canvas);
|
|
2428
|
+
emitSignal(`WebGL context lost — ${describeElement(canvas)} did not restore — ${shortUrl(location.href)}`, {
|
|
2429
|
+
canvasHeight: String(canvas.height),
|
|
2430
|
+
canvasWidth: String(canvas.width),
|
|
2431
|
+
graceMs: String(graceMs),
|
|
2432
|
+
signal: BEACON_SIGNAL.WEBGL_CONTEXT_LOST,
|
|
2433
|
+
target: describeElement(canvas)
|
|
2434
|
+
});
|
|
2435
|
+
}, graceMs);
|
|
2436
|
+
pending.set(canvas, timer2);
|
|
2437
|
+
};
|
|
2438
|
+
const onRestored = (event) => {
|
|
2439
|
+
if (event.target instanceof HTMLCanvasElement)
|
|
2440
|
+
clearPending(event.target);
|
|
2441
|
+
};
|
|
2442
|
+
document.addEventListener("webglcontextlost", onLost, true);
|
|
2443
|
+
document.addEventListener("webglcontextrestored", onRestored, true);
|
|
2444
|
+
cleanups.push(() => {
|
|
2445
|
+
document.removeEventListener("webglcontextlost", onLost, true);
|
|
2446
|
+
document.removeEventListener("webglcontextrestored", onRestored, true);
|
|
2447
|
+
for (const timer2 of pending.values())
|
|
2448
|
+
clearTimeout(timer2);
|
|
2449
|
+
pending.clear();
|
|
2450
|
+
});
|
|
1669
2451
|
}
|
|
1670
2452
|
if (signals !== null && typeof document !== "undefined") {
|
|
2453
|
+
if (signals.focusedControlsOffscreen !== false && window.visualViewport !== undefined && window.visualViewport !== null) {
|
|
2454
|
+
const visualViewport = window.visualViewport;
|
|
2455
|
+
const settleMs = signals.focusedControlSettleMs ?? FOCUSED_CONTROL_SETTLE_DEFAULT_MS;
|
|
2456
|
+
const reported = new Set;
|
|
2457
|
+
let timer2;
|
|
2458
|
+
const checkFocusedControl = () => {
|
|
2459
|
+
timer2 = undefined;
|
|
2460
|
+
if (pageLifecycleEnding || document.visibilityState === "hidden" || visualViewport.height >= window.innerHeight * KEYBOARD_VIEWPORT_HEIGHT_RATIO_MAX) {
|
|
2461
|
+
return;
|
|
2462
|
+
}
|
|
2463
|
+
const active = document.activeElement;
|
|
2464
|
+
const editable = active instanceof HTMLInputElement || active instanceof HTMLTextAreaElement || active instanceof HTMLElement && active.isContentEditable;
|
|
2465
|
+
if (!editable || !(active instanceof HTMLElement))
|
|
2466
|
+
return;
|
|
2467
|
+
const rect = active.getBoundingClientRect();
|
|
2468
|
+
if (rect.width === 0 || rect.height === 0)
|
|
2469
|
+
return;
|
|
2470
|
+
const viewportTop = visualViewport.offsetTop;
|
|
2471
|
+
const viewportBottom = viewportTop + visualViewport.height;
|
|
2472
|
+
const obscuredPx = Math.max(viewportTop - rect.top, rect.bottom - viewportBottom, 0);
|
|
2473
|
+
if (obscuredPx <= 1)
|
|
2474
|
+
return;
|
|
2475
|
+
const target = describeElement(active);
|
|
2476
|
+
const key = target;
|
|
2477
|
+
if (reported.has(key))
|
|
2478
|
+
return;
|
|
2479
|
+
reported.add(key);
|
|
2480
|
+
emitSignal(`Focused control offscreen — ${target} is outside the mobile visual viewport — ${shortUrl(location.href)}`, {
|
|
2481
|
+
layoutViewportHeight: String(window.innerHeight),
|
|
2482
|
+
obscuredPx: String(Math.round(obscuredPx)),
|
|
2483
|
+
signal: BEACON_SIGNAL.FOCUSED_CONTROL_OFFSCREEN,
|
|
2484
|
+
target,
|
|
2485
|
+
visualViewportHeight: String(Math.round(visualViewport.height)),
|
|
2486
|
+
visualViewportOffsetTop: String(Math.round(visualViewport.offsetTop))
|
|
2487
|
+
});
|
|
2488
|
+
};
|
|
2489
|
+
const scheduleCheck = () => {
|
|
2490
|
+
if (timer2 !== undefined)
|
|
2491
|
+
clearTimeout(timer2);
|
|
2492
|
+
timer2 = setTimeout(checkFocusedControl, settleMs);
|
|
2493
|
+
};
|
|
2494
|
+
document.addEventListener("focusin", scheduleCheck, true);
|
|
2495
|
+
visualViewport.addEventListener("resize", scheduleCheck);
|
|
2496
|
+
visualViewport.addEventListener("scroll", scheduleCheck);
|
|
2497
|
+
cleanups.push(() => {
|
|
2498
|
+
document.removeEventListener("focusin", scheduleCheck, true);
|
|
2499
|
+
visualViewport.removeEventListener("resize", scheduleCheck);
|
|
2500
|
+
visualViewport.removeEventListener("scroll", scheduleCheck);
|
|
2501
|
+
if (timer2 !== undefined)
|
|
2502
|
+
clearTimeout(timer2);
|
|
2503
|
+
});
|
|
2504
|
+
}
|
|
1671
2505
|
if (signals.scrollJail !== false) {
|
|
1672
2506
|
const nearestScrollable = (start) => {
|
|
1673
2507
|
let node = start;
|
|
@@ -1726,6 +2560,48 @@ var createBeacon = (options) => {
|
|
|
1726
2560
|
document.addEventListener("wheel", onWheel, { passive: true });
|
|
1727
2561
|
cleanups.push(() => document.removeEventListener("wheel", onWheel));
|
|
1728
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
|
+
}
|
|
1729
2605
|
if (signals.focusLoss !== false || signals.modalFocusEscape !== false) {
|
|
1730
2606
|
const DIALOG_SELECTOR = '[role="dialog"], [aria-modal="true"], dialog';
|
|
1731
2607
|
const MODAL_SELECTOR = '[aria-modal="true"], dialog[open]';
|
|
@@ -1900,6 +2776,46 @@ var createBeacon = (options) => {
|
|
|
1900
2776
|
document.removeEventListener("invalid", onInvalid, true);
|
|
1901
2777
|
});
|
|
1902
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
|
+
}
|
|
1903
2819
|
}
|
|
1904
2820
|
if (signals !== null && (signals.stalledStreams !== false || signals.sseFlapping !== false) && typeof window.EventSource === "function") {
|
|
1905
2821
|
const stalledStreamMs = signals.stalledStreamMs ?? STALLED_STREAM_DEFAULT_MS;
|
|
@@ -2297,6 +3213,25 @@ var createBeacon = (options) => {
|
|
|
2297
3213
|
recordRequestForStorm = null;
|
|
2298
3214
|
});
|
|
2299
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
|
+
};
|
|
2300
3235
|
if (instrument.fetch !== false && typeof window.fetch === "function") {
|
|
2301
3236
|
const originalFetch = window.fetch;
|
|
2302
3237
|
const wrapped = async (...args) => {
|
|
@@ -2316,6 +3251,7 @@ var createBeacon = (options) => {
|
|
|
2316
3251
|
type: "fetch"
|
|
2317
3252
|
});
|
|
2318
3253
|
reportResponseSignal(url, method, response.status, Date.now() - start, responseTraceId(response.headers.get(BEACON_TRACE_HEADER)));
|
|
3254
|
+
classifySemanticResponse(response, { method, url });
|
|
2319
3255
|
return response;
|
|
2320
3256
|
} catch (error) {
|
|
2321
3257
|
const resolved = toError(error);
|
|
@@ -2370,6 +3306,20 @@ var createBeacon = (options) => {
|
|
|
2370
3306
|
});
|
|
2371
3307
|
if (!failed) {
|
|
2372
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
|
+
}
|
|
2373
3323
|
} else {
|
|
2374
3324
|
const error = new Error(outcome === "timeout" ? "XMLHttpRequest timed out" : outcome === "aborted" ? "XMLHttpRequest was aborted" : "XMLHttpRequest completed with status 0");
|
|
2375
3325
|
error.name = outcome === "timeout" ? "TimeoutError" : outcome === "aborted" ? "AbortError" : "XMLHttpRequestError";
|
|
@@ -2395,6 +3345,7 @@ var createBeacon = (options) => {
|
|
|
2395
3345
|
const patch = (key) => {
|
|
2396
3346
|
const original = history[key].bind(history);
|
|
2397
3347
|
history[key] = (...args) => {
|
|
3348
|
+
reportFormAbandonmentOnNavigation?.();
|
|
2398
3349
|
const result = original(...args);
|
|
2399
3350
|
record();
|
|
2400
3351
|
return result;
|
|
@@ -2404,8 +3355,12 @@ var createBeacon = (options) => {
|
|
|
2404
3355
|
};
|
|
2405
3356
|
};
|
|
2406
3357
|
cleanups.push(patch("pushState"), patch("replaceState"));
|
|
2407
|
-
|
|
2408
|
-
|
|
3358
|
+
const onPopState = () => {
|
|
3359
|
+
reportFormAbandonmentOnNavigation?.();
|
|
3360
|
+
record();
|
|
3361
|
+
};
|
|
3362
|
+
window.addEventListener("popstate", onPopState);
|
|
3363
|
+
cleanups.push(() => window.removeEventListener("popstate", onPopState));
|
|
2409
3364
|
}
|
|
2410
3365
|
const timer = setInterval(() => {
|
|
2411
3366
|
flush();
|
|
@@ -2438,6 +3393,7 @@ var createBeacon = (options) => {
|
|
|
2438
3393
|
await flush(true);
|
|
2439
3394
|
},
|
|
2440
3395
|
flush: () => flush(false),
|
|
3396
|
+
observeCapability,
|
|
2441
3397
|
setTags: (next) => {
|
|
2442
3398
|
tags = { ...tags, ...next };
|
|
2443
3399
|
},
|
|
@@ -2455,8 +3411,10 @@ var getBeacon = () => current;
|
|
|
2455
3411
|
var captureException = (error, context) => current?.captureException(error, context);
|
|
2456
3412
|
var captureMessage = (message, level, context) => current?.captureMessage(message, level, context);
|
|
2457
3413
|
var addBreadcrumb = (crumb) => current?.addBreadcrumb(crumb);
|
|
3414
|
+
var observeCapability = (name, operation) => current?.observeCapability(name, operation) ?? operation;
|
|
2458
3415
|
export {
|
|
2459
3416
|
redactBeaconEvent,
|
|
3417
|
+
observeCapability,
|
|
2460
3418
|
isKnownBeaconNoise,
|
|
2461
3419
|
initBeacon,
|
|
2462
3420
|
getBeacon,
|
|
@@ -2469,5 +3427,5 @@ export {
|
|
|
2469
3427
|
BEACON_ATTRIBUTE
|
|
2470
3428
|
};
|
|
2471
3429
|
|
|
2472
|
-
//# debugId=
|
|
3430
|
+
//# debugId=3F33DA64F851A28864756E2164756E21
|
|
2473
3431
|
//# sourceMappingURL=index.js.map
|