@absolutejs/beacon 0.4.19 → 0.6.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 +29 -5
- package/dist/index.d.ts +97 -0
- package/dist/index.js +769 -32
- 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"
|
|
@@ -296,8 +315,9 @@ var META_IOS_WEBKIT_BRIDGE_FAILURE = "TypeError: undefined is not an object (eva
|
|
|
296
315
|
var isInstagramIosBridgeInjection = (event, userAgent) => INSTAGRAM_IOS_IN_APP_BROWSER.test(userAgent) && event.message === META_IOS_WEBKIT_BRIDGE_FAILURE && event.stack?.includes("sendDataToNative") === true && event.stack.includes("sendPageHideMessage");
|
|
297
316
|
var FACEBOOK_ANDROID_DETACHED_BRIDGE_MESSAGE = "Error invoking postMessage: Java object is gone";
|
|
298
317
|
var FACEBOOK_ANDROID_PERFORMANCE_LOGGER = "iabjs://navigation_performance_logger_android";
|
|
318
|
+
var KNOWN_CRAWLER_USER_AGENT = /(?:AdsBot-Google|Googlebot|bingbot|Baiduspider|YandexBot|DuckDuckBot|Applebot|Bytespider|PetalBot|SemrushBot|AhrefsBot|DotBot|MJ12bot|GPTBot|ClaudeBot|PerplexityBot|Google-NotebookLM|BitSightBot|Dataprovider\.com)/i;
|
|
299
319
|
var browserUserAgent = () => typeof navigator === "undefined" ? "" : navigator.userAgent;
|
|
300
|
-
var isKnownBeaconNoise = (event, userAgent = browserUserAgent()) => event.name === "UnhandledRejection" && CEF_SHARP_REJECTION.test(event.message) || FACEBOOK_IOS_IN_APP_BROWSER.test(userAgent) && FACEBOOK_IOS_HOST_INJECTION.has(event.message) || isInstagramIosBridgeInjection(event, userAgent) || event.name === "Error" && event.message === FACEBOOK_ANDROID_DETACHED_BRIDGE_MESSAGE && event.tags?.errorFilename === FACEBOOK_ANDROID_PERFORMANCE_LOGGER && event.stack?.includes(FACEBOOK_ANDROID_PERFORMANCE_LOGGER) === true;
|
|
320
|
+
var isKnownBeaconNoise = (event, userAgent = browserUserAgent()) => KNOWN_CRAWLER_USER_AGENT.test(userAgent) || event.name === "UnhandledRejection" && CEF_SHARP_REJECTION.test(event.message) || FACEBOOK_IOS_IN_APP_BROWSER.test(userAgent) && FACEBOOK_IOS_HOST_INJECTION.has(event.message) || isInstagramIosBridgeInjection(event, userAgent) || event.name === "Error" && event.message === FACEBOOK_ANDROID_DETACHED_BRIDGE_MESSAGE && event.tags?.errorFilename === FACEBOOK_ANDROID_PERFORMANCE_LOGGER && event.stack?.includes(FACEBOOK_ANDROID_PERFORMANCE_LOGGER) === true;
|
|
301
321
|
var errorWithStack = (name, message, location2) => {
|
|
302
322
|
const error = new Error(message);
|
|
303
323
|
error.name = name;
|
|
@@ -396,6 +416,48 @@ var shortUrl = (url) => {
|
|
|
396
416
|
return url.slice(0, SHORT_URL_MAX);
|
|
397
417
|
}
|
|
398
418
|
};
|
|
419
|
+
var UUID_PATH_SEGMENT = /\b[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\b/giu;
|
|
420
|
+
var LONG_IDENTIFIER_SEGMENT = /\b(?:[0-9a-f]{16,}|\d{8,})\b/giu;
|
|
421
|
+
var VOLATILE_SIGNAL_TAGS = new Set([
|
|
422
|
+
"actionId",
|
|
423
|
+
"closeCount",
|
|
424
|
+
"currentRelease",
|
|
425
|
+
"durationMs",
|
|
426
|
+
"elapsedMs",
|
|
427
|
+
"errorCount",
|
|
428
|
+
"interactionId",
|
|
429
|
+
"loadCount",
|
|
430
|
+
"newestRelease",
|
|
431
|
+
"obscuredPx",
|
|
432
|
+
"responseMs",
|
|
433
|
+
"shiftValue",
|
|
434
|
+
"signal",
|
|
435
|
+
"spillPx",
|
|
436
|
+
"stallCount",
|
|
437
|
+
"thresholdMs",
|
|
438
|
+
"userAgent",
|
|
439
|
+
"viewportHeight",
|
|
440
|
+
"viewportWidth",
|
|
441
|
+
"windowMs"
|
|
442
|
+
]);
|
|
443
|
+
var normalizeSignalIdentityPart = (value) => value.replace(UUID_PATH_SEGMENT, ":id").replace(LONG_IDENTIFIER_SEGMENT, ":id").slice(0, SIGNAL_IDENTITY_PART_MAX);
|
|
444
|
+
var SIGNAL_IDENTITY_PART_MAX = 160;
|
|
445
|
+
var stableIdentityHash = (value, seed) => {
|
|
446
|
+
let hash = seed;
|
|
447
|
+
for (let index = 0;index < value.length; index += 1) {
|
|
448
|
+
hash ^= value.charCodeAt(index);
|
|
449
|
+
hash = Math.imul(hash, 16777619);
|
|
450
|
+
}
|
|
451
|
+
return (hash >>> 0).toString(16).padStart(8, "0");
|
|
452
|
+
};
|
|
453
|
+
var signalGroupingKey = (signalTags) => {
|
|
454
|
+
const identity = [
|
|
455
|
+
`route=${normalizeSignalIdentityPart(shortUrl(location.href))}`,
|
|
456
|
+
...Object.entries(signalTags).filter(([key]) => !VOLATILE_SIGNAL_TAGS.has(key)).sort(([left], [right]) => left.localeCompare(right)).map(([key, value]) => `${key}=${normalizeSignalIdentityPart(String(value))}`)
|
|
457
|
+
].join("|");
|
|
458
|
+
const hash = stableIdentityHash(identity, 2166136261) + stableIdentityHash(identity, 2654435769);
|
|
459
|
+
return `beacon-signal:${signalTags.signal}:${hash}`;
|
|
460
|
+
};
|
|
399
461
|
var isInvisibleAnchor = (anchor) => {
|
|
400
462
|
if (anchor.target === "_blank" || anchor.hasAttribute("download"))
|
|
401
463
|
return true;
|
|
@@ -490,8 +552,37 @@ var observeLongTasks = (report, navigationType) => {
|
|
|
490
552
|
} catch {}
|
|
491
553
|
};
|
|
492
554
|
var isVitalName = (name) => VITAL_NAMES.has(name);
|
|
555
|
+
var vitalAttribution = (value) => {
|
|
556
|
+
if (value === undefined)
|
|
557
|
+
return;
|
|
558
|
+
const allowed = [
|
|
559
|
+
"element",
|
|
560
|
+
"elementRenderDelay",
|
|
561
|
+
"inputDelay",
|
|
562
|
+
"interactionTarget",
|
|
563
|
+
"interactionType",
|
|
564
|
+
"largestShiftTarget",
|
|
565
|
+
"largestShiftValue",
|
|
566
|
+
"loadState",
|
|
567
|
+
"presentationDelay",
|
|
568
|
+
"processingDuration",
|
|
569
|
+
"resourceLoadDelay",
|
|
570
|
+
"resourceLoadDuration",
|
|
571
|
+
"timeToFirstByte",
|
|
572
|
+
"url"
|
|
573
|
+
];
|
|
574
|
+
const result = {};
|
|
575
|
+
for (const key of allowed) {
|
|
576
|
+
const item = value[key];
|
|
577
|
+
if (typeof item === "string")
|
|
578
|
+
result[key] = item.slice(0, 300);
|
|
579
|
+
else if (typeof item === "number" || typeof item === "boolean")
|
|
580
|
+
result[key] = item;
|
|
581
|
+
}
|
|
582
|
+
return Object.keys(result).length === 0 ? undefined : result;
|
|
583
|
+
};
|
|
493
584
|
var loadWebVitals = async () => {
|
|
494
|
-
const mod = await import("web-vitals");
|
|
585
|
+
const mod = await import("web-vitals/attribution");
|
|
495
586
|
return mod;
|
|
496
587
|
};
|
|
497
588
|
var observeWebVitals = (webVitals, report) => {
|
|
@@ -507,6 +598,7 @@ var noopBeacon = {
|
|
|
507
598
|
captureMessage: () => {},
|
|
508
599
|
close: async () => {},
|
|
509
600
|
flush: async () => {},
|
|
601
|
+
observeCapability: async (_name, operation) => operation,
|
|
510
602
|
setTags: () => {},
|
|
511
603
|
setUser: () => {}
|
|
512
604
|
};
|
|
@@ -548,6 +640,14 @@ var createBeacon = (options) => {
|
|
|
548
640
|
const RAGE_WINDOW_MS = 1000;
|
|
549
641
|
const RAGE_RADIUS_PX = 40;
|
|
550
642
|
const DEAD_CLICK_WINDOW_MS = 1500;
|
|
643
|
+
const ERROR_CLICK_WINDOW_DEFAULT_MS = 2000;
|
|
644
|
+
const SLOW_INTERACTION_DEFAULT_MS = 1000;
|
|
645
|
+
const BLANK_APP_ROOT_SETTLE_DEFAULT_MS = 3000;
|
|
646
|
+
const DISRUPTIVE_LAYOUT_SHIFT_DEFAULT_MIN = 0.1;
|
|
647
|
+
const SLOW_RESOURCE_DEFAULT_MS = 5000;
|
|
648
|
+
const MEDIA_STALL_DEFAULT_MS = 1e4;
|
|
649
|
+
const THRASHED_CURSOR_DEFAULT_REVERSALS = 8;
|
|
650
|
+
const THRASHED_CURSOR_WINDOW_MS = 2000;
|
|
551
651
|
const NAVIGATION_RESPONSE_DEFAULT_MS = 8000;
|
|
552
652
|
const LAYOUT_OVERFLOW_SETTLE_DEFAULT_MS = 600;
|
|
553
653
|
const LAYOUT_OVERFLOW_MAX_REPORTS_DEFAULT = 5;
|
|
@@ -589,7 +689,7 @@ var createBeacon = (options) => {
|
|
|
589
689
|
const MAIN_THREAD_STALL_DEFAULT_WINDOW_MS = 1e4;
|
|
590
690
|
const RELOAD_LOOP_COUNT = 4;
|
|
591
691
|
const RELOAD_LOOP_WINDOW_MS = 60000;
|
|
592
|
-
const RELOAD_LOOP_STORAGE_KEY = "beacon:reload-
|
|
692
|
+
const RELOAD_LOOP_STORAGE_KEY = "beacon:reload-history-v2";
|
|
593
693
|
const STALE_RELEASE_STORAGE_KEY = "beacon:release-first-seen";
|
|
594
694
|
const STALE_RELEASE_GRACE_MS = 600000;
|
|
595
695
|
const STALE_RELEASE_HISTORY_LIMIT = 5;
|
|
@@ -604,6 +704,9 @@ var createBeacon = (options) => {
|
|
|
604
704
|
let externalNavigationCount = 0;
|
|
605
705
|
let inSignalConsole = false;
|
|
606
706
|
let pageLifecycleEnding = false;
|
|
707
|
+
let recentInteraction;
|
|
708
|
+
let reportErrorClick = null;
|
|
709
|
+
let reportFormAbandonmentOnNavigation = null;
|
|
607
710
|
let overflowScanOnNavigation = null;
|
|
608
711
|
let recordRequestForStorm = null;
|
|
609
712
|
const OVERLAY_VIEWPORT_COVERAGE_MIN = 0.9;
|
|
@@ -655,7 +758,8 @@ var createBeacon = (options) => {
|
|
|
655
758
|
schemaVersion: vitalsOptions.schemaVersion ?? 1,
|
|
656
759
|
...vitalsOptions.sdkVersion === undefined ? {} : { sdkVersion: vitalsOptions.sdkVersion },
|
|
657
760
|
...traceId === undefined ? {} : { traceId },
|
|
658
|
-
value: metric.value
|
|
761
|
+
value: metric.value,
|
|
762
|
+
...vitalAttribution(metric.attribution) === undefined ? {} : { attribution: vitalAttribution(metric.attribution) }
|
|
659
763
|
};
|
|
660
764
|
vitalsOptions.onVital?.(vital);
|
|
661
765
|
if (vitalsOptions.transport !== undefined) {
|
|
@@ -697,6 +801,17 @@ var createBeacon = (options) => {
|
|
|
697
801
|
let flushPendingNetworkFailures = () => {};
|
|
698
802
|
let tags = {};
|
|
699
803
|
let user;
|
|
804
|
+
let actionSequence = 0;
|
|
805
|
+
let activeAction;
|
|
806
|
+
const beginAction = (type, target) => {
|
|
807
|
+
actionSequence += 1;
|
|
808
|
+
activeAction = {
|
|
809
|
+
at: Date.now(),
|
|
810
|
+
id: `${sessionId}:${actionSequence}`,
|
|
811
|
+
target,
|
|
812
|
+
type
|
|
813
|
+
};
|
|
814
|
+
};
|
|
700
815
|
const flush = async (useBeacon = false) => {
|
|
701
816
|
flushPendingNetworkFailures();
|
|
702
817
|
if (buffer.length === 0)
|
|
@@ -733,7 +848,16 @@ var createBeacon = (options) => {
|
|
|
733
848
|
const replayId = options.getReplayId?.();
|
|
734
849
|
if (replayId !== undefined)
|
|
735
850
|
enriched.replayId = replayId;
|
|
736
|
-
const
|
|
851
|
+
const action = activeAction !== undefined && Date.now() - activeAction.at <= 1e4 ? activeAction : undefined;
|
|
852
|
+
const mergedTags = {
|
|
853
|
+
...tags,
|
|
854
|
+
...action === undefined ? {} : {
|
|
855
|
+
actionId: action.id,
|
|
856
|
+
actionTarget: action.target,
|
|
857
|
+
actionType: action.type
|
|
858
|
+
},
|
|
859
|
+
...event.tags
|
|
860
|
+
};
|
|
737
861
|
if (Object.keys(mergedTags).length > 0)
|
|
738
862
|
enriched.tags = mergedTags;
|
|
739
863
|
const extra = { sessionId, ...event.extra };
|
|
@@ -815,12 +939,48 @@ var createBeacon = (options) => {
|
|
|
815
939
|
`);
|
|
816
940
|
}
|
|
817
941
|
captureException(error, {
|
|
942
|
+
groupingKey: signalGroupingKey(signalTags),
|
|
818
943
|
level: "warning",
|
|
819
944
|
tags: signalTags,
|
|
820
945
|
...traceId !== undefined ? { traceId } : {},
|
|
821
946
|
...extra !== undefined ? { extra } : {}
|
|
822
947
|
});
|
|
823
948
|
};
|
|
949
|
+
if (signals !== null && signals.errorClicks !== false) {
|
|
950
|
+
const windowMs = signals.errorClickWindowMs ?? ERROR_CLICK_WINDOW_DEFAULT_MS;
|
|
951
|
+
reportErrorClick = (errorName) => {
|
|
952
|
+
const interaction = recentInteraction;
|
|
953
|
+
if (interaction === undefined || Date.now() - interaction.at > windowMs)
|
|
954
|
+
return;
|
|
955
|
+
recentInteraction = undefined;
|
|
956
|
+
emitSignal(`Error click — ${interaction.target} — ${shortUrl(location.href)}`, {
|
|
957
|
+
errorName,
|
|
958
|
+
interactionType: interaction.type,
|
|
959
|
+
signal: BEACON_SIGNAL.ERROR_CLICK,
|
|
960
|
+
target: interaction.target
|
|
961
|
+
});
|
|
962
|
+
};
|
|
963
|
+
cleanups.push(() => {
|
|
964
|
+
reportErrorClick = null;
|
|
965
|
+
});
|
|
966
|
+
}
|
|
967
|
+
const observeCapability = async (name, operation) => {
|
|
968
|
+
try {
|
|
969
|
+
return await operation;
|
|
970
|
+
} catch (error) {
|
|
971
|
+
const resolved = toError(error);
|
|
972
|
+
captureException(errorWithoutStack("CapabilityFailure", `Browser capability failed — ${name}`), {
|
|
973
|
+
groupingKey: `browser-capability:${name}`,
|
|
974
|
+
level: "warning",
|
|
975
|
+
tags: {
|
|
976
|
+
capability: name.slice(0, SIGNAL_TEXT_MAX),
|
|
977
|
+
errorName: resolved.name,
|
|
978
|
+
signal: BEACON_SIGNAL.CAPABILITY_FAILURE
|
|
979
|
+
}
|
|
980
|
+
});
|
|
981
|
+
throw error;
|
|
982
|
+
}
|
|
983
|
+
};
|
|
824
984
|
const responseTraceId = (value) => {
|
|
825
985
|
const traceId = value?.trim().toLowerCase();
|
|
826
986
|
return traceId !== undefined && /^[0-9a-f]{32}$/.test(traceId) ? traceId : undefined;
|
|
@@ -893,7 +1053,16 @@ var createBeacon = (options) => {
|
|
|
893
1053
|
let networkFailureTimer;
|
|
894
1054
|
const networkState = () => {
|
|
895
1055
|
const online = typeof navigator.onLine === "boolean" ? navigator.onLine : null;
|
|
1056
|
+
const connection = navigator.connection;
|
|
896
1057
|
return {
|
|
1058
|
+
...connection === undefined ? {} : {
|
|
1059
|
+
connection: {
|
|
1060
|
+
...typeof connection.downlink === "number" ? { downlink: connection.downlink } : {},
|
|
1061
|
+
...typeof connection.effectiveType === "string" ? { effectiveType: connection.effectiveType } : {},
|
|
1062
|
+
...typeof connection.rtt === "number" ? { rtt: connection.rtt } : {},
|
|
1063
|
+
...typeof connection.saveData === "boolean" ? { saveData: connection.saveData } : {}
|
|
1064
|
+
}
|
|
1065
|
+
},
|
|
897
1066
|
online,
|
|
898
1067
|
visibilityState: typeof document.visibilityState === "string" ? document.visibilityState : "unknown"
|
|
899
1068
|
};
|
|
@@ -988,6 +1157,7 @@ var createBeacon = (options) => {
|
|
|
988
1157
|
},
|
|
989
1158
|
method: method.toUpperCase(),
|
|
990
1159
|
online: state.online,
|
|
1160
|
+
...state.connection === undefined ? {} : { connection: state.connection },
|
|
991
1161
|
transport: transportKind,
|
|
992
1162
|
visibilityState: state.visibilityState
|
|
993
1163
|
};
|
|
@@ -1018,7 +1188,7 @@ var createBeacon = (options) => {
|
|
|
1018
1188
|
routerAcceptedNavigation = control instanceof HTMLAnchorElement && handledEvent.defaultPrevented;
|
|
1019
1189
|
};
|
|
1020
1190
|
const responded = () => mutated || formStateChanged(formBefore) || location.href !== urlBefore || window.scrollY !== scrollBefore || document.activeElement !== activeBefore || networkRequestCount !== networkRequestsBefore || externalNavigationCount !== externalNavigationsBefore;
|
|
1021
|
-
const finish = (didRespond) => {
|
|
1191
|
+
const finish = (didRespond, navigationStalled = false) => {
|
|
1022
1192
|
if (finished)
|
|
1023
1193
|
return;
|
|
1024
1194
|
finished = true;
|
|
@@ -1027,7 +1197,7 @@ var createBeacon = (options) => {
|
|
|
1027
1197
|
if (timer2 !== undefined)
|
|
1028
1198
|
window.clearTimeout(timer2);
|
|
1029
1199
|
pendingClickCleanups.delete(cancel);
|
|
1030
|
-
report(didRespond);
|
|
1200
|
+
report(didRespond, navigationStalled);
|
|
1031
1201
|
};
|
|
1032
1202
|
const cancel = () => {
|
|
1033
1203
|
if (finished)
|
|
@@ -1040,8 +1210,7 @@ var createBeacon = (options) => {
|
|
|
1040
1210
|
};
|
|
1041
1211
|
const observer = new MutationObserver(() => {
|
|
1042
1212
|
mutated = true;
|
|
1043
|
-
|
|
1044
|
-
finish(true);
|
|
1213
|
+
finish(true);
|
|
1045
1214
|
});
|
|
1046
1215
|
observer.observe(document.body, {
|
|
1047
1216
|
attributes: true,
|
|
@@ -1060,7 +1229,10 @@ var createBeacon = (options) => {
|
|
|
1060
1229
|
return;
|
|
1061
1230
|
}
|
|
1062
1231
|
extended = true;
|
|
1063
|
-
timer2 = window.setTimeout(() =>
|
|
1232
|
+
timer2 = window.setTimeout(() => {
|
|
1233
|
+
const didRespond = responded();
|
|
1234
|
+
finish(didRespond, !didRespond);
|
|
1235
|
+
}, navigationResponseMs - DEAD_CLICK_WINDOW_MS);
|
|
1064
1236
|
}, DEAD_CLICK_WINDOW_MS);
|
|
1065
1237
|
};
|
|
1066
1238
|
const clickSignalMessage = (message, control) => `${message} — ${shortUrl(location.href)} — ${describeElement(control)}`;
|
|
@@ -1119,6 +1291,37 @@ var createBeacon = (options) => {
|
|
|
1119
1291
|
cleanups.push(() => observer.disconnect());
|
|
1120
1292
|
} catch {}
|
|
1121
1293
|
}
|
|
1294
|
+
if (signals !== null && signals.browserPolicyViolations !== false && typeof ReportingObserver !== "undefined") {
|
|
1295
|
+
try {
|
|
1296
|
+
const reportTypes = [
|
|
1297
|
+
"deprecation",
|
|
1298
|
+
"permissions-policy-violation",
|
|
1299
|
+
"integrity-violation",
|
|
1300
|
+
"coep"
|
|
1301
|
+
];
|
|
1302
|
+
const reported = new Set;
|
|
1303
|
+
const observer = new ReportingObserver((reports) => {
|
|
1304
|
+
for (const report of reports) {
|
|
1305
|
+
const body = report.body;
|
|
1306
|
+
const id = typeof body.id === "string" && body.id !== "" ? body.id.slice(0, SIGNAL_TEXT_MAX) : report.type;
|
|
1307
|
+
const key = `${report.type}|${id}|${shortUrl(report.url || location.href)}`;
|
|
1308
|
+
if (reported.has(key))
|
|
1309
|
+
continue;
|
|
1310
|
+
reported.add(key);
|
|
1311
|
+
emitSignal(`Browser policy violation — ${report.type} ${id} — ${shortUrl(location.href)}`, {
|
|
1312
|
+
policyId: id,
|
|
1313
|
+
reportType: report.type,
|
|
1314
|
+
reportUrl: report.url || location.href,
|
|
1315
|
+
signal: BEACON_SIGNAL.BROWSER_POLICY_VIOLATION,
|
|
1316
|
+
...typeof body.sourceFile === "string" ? { sourceFile: body.sourceFile } : {},
|
|
1317
|
+
...typeof body.lineNumber === "number" ? { sourceLine: String(body.lineNumber) } : {}
|
|
1318
|
+
});
|
|
1319
|
+
}
|
|
1320
|
+
}, { buffered: true, types: reportTypes });
|
|
1321
|
+
observer.observe();
|
|
1322
|
+
cleanups.push(() => observer.disconnect());
|
|
1323
|
+
} catch {}
|
|
1324
|
+
}
|
|
1122
1325
|
if (signals !== null && signals.mainThreadStalls !== false && typeof PerformanceObserver !== "undefined") {
|
|
1123
1326
|
const stallMs = signals.mainThreadStallMs ?? MAIN_THREAD_STALL_DEFAULT_MS;
|
|
1124
1327
|
const stallCount = signals.mainThreadStallCount ?? MAIN_THREAD_STALL_DEFAULT_COUNT;
|
|
@@ -1138,10 +1341,18 @@ var createBeacon = (options) => {
|
|
|
1138
1341
|
if (stallTimes.length < stallCount)
|
|
1139
1342
|
continue;
|
|
1140
1343
|
reported = true;
|
|
1344
|
+
const animationFrame = entry;
|
|
1345
|
+
const script = [...animationFrame.scripts ?? []].sort((left, right) => (right.duration ?? 0) - (left.duration ?? 0))[0];
|
|
1141
1346
|
emitSignal(`Main-thread stall — repeated long frames blocked the page — ${shortUrl(location.href)}`, {
|
|
1347
|
+
...animationFrame.blockingDuration === undefined ? {} : {
|
|
1348
|
+
blockingDurationMs: String(Math.round(animationFrame.blockingDuration))
|
|
1349
|
+
},
|
|
1142
1350
|
durationMs: String(Math.round(entry.duration)),
|
|
1143
1351
|
entryType: entry.entryType,
|
|
1144
1352
|
signal: BEACON_SIGNAL.MAIN_THREAD_STALL,
|
|
1353
|
+
...script?.functionName === undefined ? {} : { scriptFunction: script.functionName },
|
|
1354
|
+
...script?.invoker === undefined ? {} : { scriptInvoker: script.invoker },
|
|
1355
|
+
...script?.sourceURL === undefined ? {} : { scriptSource: shortUrl(script.sourceURL) },
|
|
1145
1356
|
stallCount: String(stallTimes.length),
|
|
1146
1357
|
windowMs: String(stallWindowMs)
|
|
1147
1358
|
});
|
|
@@ -1166,6 +1377,71 @@ var createBeacon = (options) => {
|
|
|
1166
1377
|
cleanups.push(() => observer.disconnect());
|
|
1167
1378
|
} catch {}
|
|
1168
1379
|
}
|
|
1380
|
+
if (signals !== null && typeof document !== "undefined") {
|
|
1381
|
+
const discardedDocument = document;
|
|
1382
|
+
if (signals.documentDiscards !== false && discardedDocument.wasDiscarded === true) {
|
|
1383
|
+
emitSignal(`Document discarded — the browser reloaded a discarded tab — ${shortUrl(location.href)}`, { signal: BEACON_SIGNAL.DOCUMENT_DISCARDED });
|
|
1384
|
+
}
|
|
1385
|
+
if (signals.bfcacheBlocks !== false && typeof performance !== "undefined") {
|
|
1386
|
+
const navigation = performance.getEntriesByType("navigation")[0];
|
|
1387
|
+
if (navigation?.type === "back_forward" && navigation.notRestoredReasons != null) {
|
|
1388
|
+
const reasons = new Set;
|
|
1389
|
+
const visit = (node) => {
|
|
1390
|
+
if (node === null || typeof node !== "object")
|
|
1391
|
+
return;
|
|
1392
|
+
const detail = node;
|
|
1393
|
+
for (const reason of detail.reasons ?? []) {
|
|
1394
|
+
if (typeof reason.reason === "string")
|
|
1395
|
+
reasons.add(reason.reason);
|
|
1396
|
+
}
|
|
1397
|
+
for (const child of detail.children ?? [])
|
|
1398
|
+
visit(child);
|
|
1399
|
+
};
|
|
1400
|
+
visit(navigation.notRestoredReasons);
|
|
1401
|
+
const reasonList = [...reasons].filter((reason) => reason !== "masked").slice(0, 10);
|
|
1402
|
+
if (reasonList.length > 0) {
|
|
1403
|
+
emitSignal(`Back-forward cache blocked — ${reasonList.join(", ")} — ${shortUrl(location.href)}`, {
|
|
1404
|
+
reasons: reasonList.join(","),
|
|
1405
|
+
signal: BEACON_SIGNAL.BFCACHE_BLOCKED
|
|
1406
|
+
});
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
if (instrument.networkChanges !== false && typeof navigator !== "undefined") {
|
|
1412
|
+
const connection = navigator.connection;
|
|
1413
|
+
if (connection !== undefined) {
|
|
1414
|
+
const onConnectionChange = () => {
|
|
1415
|
+
addBreadcrumb({
|
|
1416
|
+
data: {
|
|
1417
|
+
...typeof connection.downlink === "number" ? { downlink: connection.downlink } : {},
|
|
1418
|
+
...typeof connection.effectiveType === "string" ? { effectiveType: connection.effectiveType } : {},
|
|
1419
|
+
...typeof connection.rtt === "number" ? { rtt: connection.rtt } : {},
|
|
1420
|
+
...typeof connection.saveData === "boolean" ? { saveData: connection.saveData } : {}
|
|
1421
|
+
},
|
|
1422
|
+
message: "Network quality changed",
|
|
1423
|
+
type: "custom"
|
|
1424
|
+
});
|
|
1425
|
+
};
|
|
1426
|
+
connection.addEventListener("change", onConnectionChange);
|
|
1427
|
+
cleanups.push(() => connection.removeEventListener("change", onConnectionChange));
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
if (instrument.userTiming === true && typeof PerformanceObserver !== "undefined") {
|
|
1431
|
+
try {
|
|
1432
|
+
const observer = new PerformanceObserver((list) => {
|
|
1433
|
+
for (const entry of list.getEntries()) {
|
|
1434
|
+
addBreadcrumb({
|
|
1435
|
+
data: { durationMs: Math.round(entry.duration) },
|
|
1436
|
+
message: `Performance measure ${entry.name.slice(0, SIGNAL_TEXT_MAX)}`,
|
|
1437
|
+
type: "custom"
|
|
1438
|
+
});
|
|
1439
|
+
}
|
|
1440
|
+
});
|
|
1441
|
+
observer.observe({ buffered: true, type: "measure" });
|
|
1442
|
+
cleanups.push(() => observer.disconnect());
|
|
1443
|
+
} catch {}
|
|
1444
|
+
}
|
|
1169
1445
|
if (instrument.globalErrors !== false) {
|
|
1170
1446
|
const onError = (event) => {
|
|
1171
1447
|
if (event instanceof ErrorEvent) {
|
|
@@ -1175,6 +1451,7 @@ var createBeacon = (options) => {
|
|
|
1175
1451
|
level: "error",
|
|
1176
1452
|
tags: errorEventTags(event)
|
|
1177
1453
|
});
|
|
1454
|
+
reportErrorClick?.(error.name);
|
|
1178
1455
|
return;
|
|
1179
1456
|
}
|
|
1180
1457
|
const target = event.target;
|
|
@@ -1213,6 +1490,7 @@ var createBeacon = (options) => {
|
|
|
1213
1490
|
const reason = event.reason;
|
|
1214
1491
|
if (reason instanceof Error) {
|
|
1215
1492
|
captureException(reason, { level: "error" });
|
|
1493
|
+
reportErrorClick?.(reason.name);
|
|
1216
1494
|
return;
|
|
1217
1495
|
}
|
|
1218
1496
|
if (typeof reason === "object" && reason !== null && typeof reason.stack === "string") {
|
|
@@ -1226,6 +1504,7 @@ var createBeacon = (options) => {
|
|
|
1226
1504
|
},
|
|
1227
1505
|
level: "error"
|
|
1228
1506
|
});
|
|
1507
|
+
reportErrorClick?.("UnhandledRejection");
|
|
1229
1508
|
};
|
|
1230
1509
|
window.addEventListener("unhandledrejection", onRejection);
|
|
1231
1510
|
cleanups.push(() => window.removeEventListener("unhandledrejection", onRejection));
|
|
@@ -1243,6 +1522,8 @@ var createBeacon = (options) => {
|
|
|
1243
1522
|
const text = args.map(String).join(" ").trim().slice(0, SIGNAL_TEXT_MAX);
|
|
1244
1523
|
if (text !== "")
|
|
1245
1524
|
emitSignal(text, { signal: BEACON_SIGNAL.CONSOLE_ERROR }, undefined, undefined, wrappedConsole, 2);
|
|
1525
|
+
if (text !== "")
|
|
1526
|
+
reportErrorClick?.("ConsoleError");
|
|
1246
1527
|
inSignalConsole = false;
|
|
1247
1528
|
}
|
|
1248
1529
|
original.apply(console, args);
|
|
@@ -1300,9 +1581,16 @@ var createBeacon = (options) => {
|
|
|
1300
1581
|
const target = event.target;
|
|
1301
1582
|
if (!(target instanceof Element))
|
|
1302
1583
|
return;
|
|
1303
|
-
|
|
1584
|
+
const targetName = describeElement(target);
|
|
1585
|
+
beginAction("click", targetName);
|
|
1586
|
+
addBreadcrumb({ message: targetName, type: "click" });
|
|
1304
1587
|
if (signals === null)
|
|
1305
1588
|
return;
|
|
1589
|
+
recentInteraction = {
|
|
1590
|
+
at: Date.now(),
|
|
1591
|
+
target: targetName,
|
|
1592
|
+
type: "click"
|
|
1593
|
+
};
|
|
1306
1594
|
const control = deadClickCandidate(target, event);
|
|
1307
1595
|
if (control === null)
|
|
1308
1596
|
return;
|
|
@@ -1313,11 +1601,18 @@ var createBeacon = (options) => {
|
|
|
1313
1601
|
const clickedAt = Date.now();
|
|
1314
1602
|
const x = event instanceof MouseEvent ? event.clientX : 0;
|
|
1315
1603
|
const y = event instanceof MouseEvent ? event.clientY : 0;
|
|
1316
|
-
observeClickResponse(control, event, (responded) => {
|
|
1604
|
+
observeClickResponse(control, event, (responded, navigationStalled) => {
|
|
1317
1605
|
if (responded) {
|
|
1318
1606
|
unresponsiveClicks = unresponsiveClicks.filter((click) => click.control !== control);
|
|
1319
1607
|
return;
|
|
1320
1608
|
}
|
|
1609
|
+
if (navigationStalled && signals.stalledNavigations !== false) {
|
|
1610
|
+
emitSignal(clickSignalMessage("Navigation stalled — accepted route never settled", control), {
|
|
1611
|
+
signal: BEACON_SIGNAL.NAVIGATION_STALLED,
|
|
1612
|
+
target: describeElement(control)
|
|
1613
|
+
});
|
|
1614
|
+
return;
|
|
1615
|
+
}
|
|
1321
1616
|
if (detectDead) {
|
|
1322
1617
|
emitSignal(clickSignalMessage("Dead click — control didn't respond", control), {
|
|
1323
1618
|
signal: BEACON_SIGNAL.DEAD_CLICK,
|
|
@@ -1338,7 +1633,38 @@ var createBeacon = (options) => {
|
|
|
1338
1633
|
});
|
|
1339
1634
|
};
|
|
1340
1635
|
document.addEventListener("click", onClick, true);
|
|
1341
|
-
|
|
1636
|
+
const onInteractionSubmit = (event) => {
|
|
1637
|
+
if (!(event.target instanceof HTMLFormElement))
|
|
1638
|
+
return;
|
|
1639
|
+
const target = describeElement(event.target);
|
|
1640
|
+
beginAction("submit", target);
|
|
1641
|
+
recentInteraction = {
|
|
1642
|
+
at: Date.now(),
|
|
1643
|
+
target,
|
|
1644
|
+
type: "submit"
|
|
1645
|
+
};
|
|
1646
|
+
};
|
|
1647
|
+
const onInteractionKey = (event) => {
|
|
1648
|
+
if (event.key !== "Enter" && event.key !== " ")
|
|
1649
|
+
return;
|
|
1650
|
+
const target = event.target;
|
|
1651
|
+
if (!(target instanceof Element))
|
|
1652
|
+
return;
|
|
1653
|
+
const targetName = describeElement(target);
|
|
1654
|
+
beginAction("keyboard", targetName);
|
|
1655
|
+
recentInteraction = {
|
|
1656
|
+
at: Date.now(),
|
|
1657
|
+
target: targetName,
|
|
1658
|
+
type: "keyboard"
|
|
1659
|
+
};
|
|
1660
|
+
};
|
|
1661
|
+
document.addEventListener("submit", onInteractionSubmit, true);
|
|
1662
|
+
document.addEventListener("keydown", onInteractionKey, true);
|
|
1663
|
+
cleanups.push(() => {
|
|
1664
|
+
document.removeEventListener("click", onClick, true);
|
|
1665
|
+
document.removeEventListener("submit", onInteractionSubmit, true);
|
|
1666
|
+
document.removeEventListener("keydown", onInteractionKey, true);
|
|
1667
|
+
});
|
|
1342
1668
|
}
|
|
1343
1669
|
if (signals !== null && typeof document !== "undefined" && typeof window.getComputedStyle === "function") {
|
|
1344
1670
|
const detectOverflow = signals.layoutOverflows !== false;
|
|
@@ -1346,6 +1672,7 @@ var createBeacon = (options) => {
|
|
|
1346
1672
|
const detectInvisibleText = signals.invisibleText !== false;
|
|
1347
1673
|
const detectStuckLoading = signals.stuckLoading !== false;
|
|
1348
1674
|
const detectThemeMismatch = signals.themeMismatches !== false;
|
|
1675
|
+
const detectBlankAppRoot = signals.blankAppRoots !== false;
|
|
1349
1676
|
const overflowSettleMs = signals.layoutOverflowSettleMs ?? LAYOUT_OVERFLOW_SETTLE_DEFAULT_MS;
|
|
1350
1677
|
const overflowMaxReports = signals.layoutOverflowMaxReports ?? LAYOUT_OVERFLOW_MAX_REPORTS_DEFAULT;
|
|
1351
1678
|
const stuckLoadingMs = signals.stuckLoadingMs ?? STUCK_LOADING_DEFAULT_MS;
|
|
@@ -1366,6 +1693,21 @@ var createBeacon = (options) => {
|
|
|
1366
1693
|
return "xl";
|
|
1367
1694
|
};
|
|
1368
1695
|
const isScanExempt = (element) => element.closest(`[${BEACON_ATTRIBUTE.SCAN}="allow"]`) !== null;
|
|
1696
|
+
const hasHiddenAncestor = (element, requirePointerEvents = false) => {
|
|
1697
|
+
let current = element;
|
|
1698
|
+
while (current !== null) {
|
|
1699
|
+
if (current.hasAttribute("hidden") || current.hasAttribute("inert") || current.getAttribute("aria-hidden") === "true") {
|
|
1700
|
+
return true;
|
|
1701
|
+
}
|
|
1702
|
+
const style = window.getComputedStyle(current);
|
|
1703
|
+
if (style.display === "none" || style.visibility === "hidden" || style.visibility === "collapse" || Number.parseFloat(style.opacity || "1") <= 0.01 || requirePointerEvents && style.pointerEvents === "none") {
|
|
1704
|
+
return true;
|
|
1705
|
+
}
|
|
1706
|
+
current = current.parentElement;
|
|
1707
|
+
}
|
|
1708
|
+
return false;
|
|
1709
|
+
};
|
|
1710
|
+
const isMaterialIconGlyph = (element) => [...element.classList].some((name) => name === "material-icons" || name.startsWith("material-symbols"));
|
|
1369
1711
|
const seenScanIssues = new Set;
|
|
1370
1712
|
let scanIssueReports = 0;
|
|
1371
1713
|
const SCAN_ISSUE_MAX_REPORTS = 10;
|
|
@@ -1413,13 +1755,16 @@ var createBeacon = (options) => {
|
|
|
1413
1755
|
if (element.getAttribute(BEACON_ATTRIBUTE.OVERFLOW) === "allow")
|
|
1414
1756
|
return;
|
|
1415
1757
|
const style = window.getComputedStyle(element);
|
|
1416
|
-
if (
|
|
1758
|
+
if (hasHiddenAncestor(element))
|
|
1417
1759
|
return;
|
|
1418
1760
|
const rect = element.getBoundingClientRect();
|
|
1419
1761
|
if (rect.width === 0 && rect.height === 0)
|
|
1420
1762
|
return;
|
|
1763
|
+
if ((style.position === "absolute" || style.position === "fixed") && (rect.right <= 0 || rect.left >= viewportRight || rect.bottom <= 0 || rect.top >= document.documentElement.clientHeight)) {
|
|
1764
|
+
return;
|
|
1765
|
+
}
|
|
1421
1766
|
const inFlow = style.position !== "absolute" && style.position !== "fixed";
|
|
1422
|
-
if (inFlow) {
|
|
1767
|
+
if (inFlow && !isMaterialIconGlyph(element)) {
|
|
1423
1768
|
const viewportSpill = Math.max(rect.right - viewportRight, -rect.left);
|
|
1424
1769
|
if (viewportSpill > LAYOUT_OVERFLOW_VIEWPORT_TOLERANCE_PX) {
|
|
1425
1770
|
reportOverflow(element, "viewport", "spills past the viewport edge", viewportSpill);
|
|
@@ -1461,7 +1806,7 @@ var createBeacon = (options) => {
|
|
|
1461
1806
|
for (const control of Array.from(controls)) {
|
|
1462
1807
|
if (sampled >= OCCLUSION_SAMPLE_LIMIT)
|
|
1463
1808
|
return;
|
|
1464
|
-
if (isScanExempt(control))
|
|
1809
|
+
if (isScanExempt(control) || hasHiddenAncestor(control, true))
|
|
1465
1810
|
continue;
|
|
1466
1811
|
const rect = control.getBoundingClientRect();
|
|
1467
1812
|
if (rect.width === 0 || rect.height === 0)
|
|
@@ -1735,6 +2080,25 @@ var createBeacon = (options) => {
|
|
|
1735
2080
|
reportScanIssue(indicator, BEACON_SIGNAL.STUCK_LOADING, `Stuck loading — ${describeElement(indicator)} never resolved`, { visibleMs: String(now - firstSeen) });
|
|
1736
2081
|
}
|
|
1737
2082
|
};
|
|
2083
|
+
const checkBlankAppRoots = () => {
|
|
2084
|
+
if (document.visibilityState === "hidden")
|
|
2085
|
+
return;
|
|
2086
|
+
const roots = document.querySelectorAll(`[${BEACON_ATTRIBUTE.APP_ROOT}]`);
|
|
2087
|
+
for (const root of Array.from(roots)) {
|
|
2088
|
+
if (isScanExempt(root))
|
|
2089
|
+
continue;
|
|
2090
|
+
const rect = root.getBoundingClientRect();
|
|
2091
|
+
if (rect.width === 0 || rect.height === 0)
|
|
2092
|
+
continue;
|
|
2093
|
+
const text = (root.textContent ?? "").trim();
|
|
2094
|
+
const meaningful = text !== "" || root.querySelector("button, input, select, textarea, img, svg, canvas, video, iframe, [role=alert]") !== null;
|
|
2095
|
+
const loading = root.querySelector(`[aria-busy="true"], [role="progressbar"], [${BEACON_ATTRIBUTE.LOADING}]`) !== null;
|
|
2096
|
+
if (meaningful || loading)
|
|
2097
|
+
continue;
|
|
2098
|
+
const name = root.getAttribute(BEACON_ATTRIBUTE.APP_ROOT)?.trim() || describeElement(root);
|
|
2099
|
+
reportScanIssue(root, BEACON_SIGNAL.BLANK_APP_ROOT, `Blank application root — ${name} rendered no meaningful content`, {});
|
|
2100
|
+
}
|
|
2101
|
+
};
|
|
1738
2102
|
const runSettledScan = () => {
|
|
1739
2103
|
if (detectOverflow)
|
|
1740
2104
|
scanForOverflow();
|
|
@@ -1781,6 +2145,97 @@ var createBeacon = (options) => {
|
|
|
1781
2145
|
stuckTimer.unref?.();
|
|
1782
2146
|
cleanups.push(() => clearInterval(stuckTimer));
|
|
1783
2147
|
}
|
|
2148
|
+
if (detectBlankAppRoot) {
|
|
2149
|
+
const blankTimer = setTimeout(checkBlankAppRoots, signals.blankAppRootSettleMs ?? BLANK_APP_ROOT_SETTLE_DEFAULT_MS);
|
|
2150
|
+
cleanups.push(() => clearTimeout(blankTimer));
|
|
2151
|
+
}
|
|
2152
|
+
}
|
|
2153
|
+
if (signals !== null && signals.disruptiveLayoutShifts !== false && typeof PerformanceObserver !== "undefined") {
|
|
2154
|
+
const minimum = signals.disruptiveLayoutShiftMin ?? DISRUPTIVE_LAYOUT_SHIFT_DEFAULT_MIN;
|
|
2155
|
+
const reported = new Set;
|
|
2156
|
+
try {
|
|
2157
|
+
const observer = new PerformanceObserver((list) => {
|
|
2158
|
+
for (const raw of list.getEntries()) {
|
|
2159
|
+
const entry = raw;
|
|
2160
|
+
if (entry.hadRecentInput === true || (entry.value ?? 0) < minimum)
|
|
2161
|
+
continue;
|
|
2162
|
+
const targets = (entry.sources ?? []).map(({ node }) => node instanceof Element ? describeElement(node) : undefined).filter((target) => target !== undefined).slice(0, 5);
|
|
2163
|
+
const key = targets.join(",") || "unknown";
|
|
2164
|
+
if (reported.has(key))
|
|
2165
|
+
continue;
|
|
2166
|
+
reported.add(key);
|
|
2167
|
+
emitSignal(`Disruptive layout shift — ${key} — ${shortUrl(location.href)}`, {
|
|
2168
|
+
shiftValue: String(entry.value ?? 0),
|
|
2169
|
+
signal: BEACON_SIGNAL.DISRUPTIVE_LAYOUT_SHIFT,
|
|
2170
|
+
target: key
|
|
2171
|
+
});
|
|
2172
|
+
}
|
|
2173
|
+
});
|
|
2174
|
+
observer.observe({ buffered: true, type: "layout-shift" });
|
|
2175
|
+
cleanups.push(() => observer.disconnect());
|
|
2176
|
+
} catch {}
|
|
2177
|
+
}
|
|
2178
|
+
if (signals !== null && signals.slowInteractions !== false && typeof PerformanceObserver !== "undefined") {
|
|
2179
|
+
const minimum = signals.slowInteractionMs ?? SLOW_INTERACTION_DEFAULT_MS;
|
|
2180
|
+
const reported = new Set;
|
|
2181
|
+
try {
|
|
2182
|
+
const observer = new PerformanceObserver((list) => {
|
|
2183
|
+
for (const raw of list.getEntries()) {
|
|
2184
|
+
const entry = raw;
|
|
2185
|
+
if (entry.duration < minimum || entry.interactionId === undefined || entry.interactionId <= 0)
|
|
2186
|
+
continue;
|
|
2187
|
+
const target = entry.target instanceof Element ? describeElement(entry.target) : "unknown";
|
|
2188
|
+
const key = entry.interactionId;
|
|
2189
|
+
if (reported.has(key))
|
|
2190
|
+
continue;
|
|
2191
|
+
reported.add(key);
|
|
2192
|
+
emitSignal(`Slow interaction — ${entry.name} blocked for ${Math.round(entry.duration)}ms — ${shortUrl(location.href)}`, {
|
|
2193
|
+
durationMs: String(Math.round(entry.duration)),
|
|
2194
|
+
eventType: entry.name,
|
|
2195
|
+
interactionId: String(entry.interactionId),
|
|
2196
|
+
signal: BEACON_SIGNAL.SLOW_INTERACTION,
|
|
2197
|
+
target
|
|
2198
|
+
});
|
|
2199
|
+
}
|
|
2200
|
+
});
|
|
2201
|
+
observer.observe({
|
|
2202
|
+
buffered: true,
|
|
2203
|
+
durationThreshold: Math.max(16, Math.min(1040, minimum)),
|
|
2204
|
+
type: "event"
|
|
2205
|
+
});
|
|
2206
|
+
cleanups.push(() => observer.disconnect());
|
|
2207
|
+
} catch {}
|
|
2208
|
+
}
|
|
2209
|
+
if (signals !== null && signals.slowResources !== false && typeof PerformanceObserver !== "undefined") {
|
|
2210
|
+
const minimum = signals.slowResourceMs ?? SLOW_RESOURCE_DEFAULT_MS;
|
|
2211
|
+
const reported = new Set;
|
|
2212
|
+
try {
|
|
2213
|
+
const observer = new PerformanceObserver((list) => {
|
|
2214
|
+
for (const raw of list.getEntries()) {
|
|
2215
|
+
const entry = raw;
|
|
2216
|
+
if (entry.duration < minimum)
|
|
2217
|
+
continue;
|
|
2218
|
+
if (!/^(css|font|img|link|script)$/u.test(entry.initiatorType))
|
|
2219
|
+
continue;
|
|
2220
|
+
const resource = shortUrl(entry.name);
|
|
2221
|
+
const key = `${entry.initiatorType}|${resource}`;
|
|
2222
|
+
if (reported.has(key))
|
|
2223
|
+
continue;
|
|
2224
|
+
reported.add(key);
|
|
2225
|
+
emitSignal(`Slow resource — ${entry.initiatorType} ${resource}`, {
|
|
2226
|
+
cacheHit: String(entry.transferSize === 0),
|
|
2227
|
+
durationMs: String(Math.round(entry.duration)),
|
|
2228
|
+
initiatorType: entry.initiatorType,
|
|
2229
|
+
protocol: entry.nextHopProtocol || "unknown",
|
|
2230
|
+
signal: BEACON_SIGNAL.SLOW_RESOURCE,
|
|
2231
|
+
target: resource,
|
|
2232
|
+
transferSize: String(entry.transferSize)
|
|
2233
|
+
});
|
|
2234
|
+
}
|
|
2235
|
+
});
|
|
2236
|
+
observer.observe({ buffered: true, type: "resource" });
|
|
2237
|
+
cleanups.push(() => observer.disconnect());
|
|
2238
|
+
} catch {}
|
|
1784
2239
|
}
|
|
1785
2240
|
if (signals !== null && signals.embeddedContentStalls !== false && typeof document !== "undefined") {
|
|
1786
2241
|
const stallMs = signals.embeddedContentStallMs ?? EMBEDDED_CONTENT_STALL_DEFAULT_MS;
|
|
@@ -1863,6 +2318,153 @@ var createBeacon = (options) => {
|
|
|
1863
2318
|
stopWatching(frame);
|
|
1864
2319
|
});
|
|
1865
2320
|
}
|
|
2321
|
+
if (signals !== null && signals.mediaFailures !== false && typeof document !== "undefined") {
|
|
2322
|
+
const stallMs = signals.mediaStallMs ?? MEDIA_STALL_DEFAULT_MS;
|
|
2323
|
+
const watched = new Map;
|
|
2324
|
+
const watch = (media) => {
|
|
2325
|
+
if (watched.has(media) || !media.hasAttribute(BEACON_ATTRIBUTE.MEDIA))
|
|
2326
|
+
return;
|
|
2327
|
+
const name = media.getAttribute(BEACON_ATTRIBUTE.MEDIA)?.trim() || describeElement(media);
|
|
2328
|
+
let started = false;
|
|
2329
|
+
let stallTimer;
|
|
2330
|
+
const clearStall = () => {
|
|
2331
|
+
if (stallTimer !== undefined)
|
|
2332
|
+
clearTimeout(stallTimer);
|
|
2333
|
+
stallTimer = undefined;
|
|
2334
|
+
};
|
|
2335
|
+
const onPlay = () => {
|
|
2336
|
+
started = true;
|
|
2337
|
+
clearStall();
|
|
2338
|
+
};
|
|
2339
|
+
const onWaiting = () => {
|
|
2340
|
+
if (!started || media.ended || media.paused)
|
|
2341
|
+
return;
|
|
2342
|
+
clearStall();
|
|
2343
|
+
stallTimer = setTimeout(() => {
|
|
2344
|
+
if (!media.isConnected || media.ended || media.paused)
|
|
2345
|
+
return;
|
|
2346
|
+
emitSignal(`Media playback stalled — ${name} — ${shortUrl(location.href)}`, {
|
|
2347
|
+
currentTime: String(Math.round(media.currentTime)),
|
|
2348
|
+
networkState: String(media.networkState),
|
|
2349
|
+
readyState: String(media.readyState),
|
|
2350
|
+
signal: BEACON_SIGNAL.MEDIA_PLAYBACK_STALLED,
|
|
2351
|
+
target: name
|
|
2352
|
+
});
|
|
2353
|
+
}, stallMs);
|
|
2354
|
+
};
|
|
2355
|
+
const onError = () => {
|
|
2356
|
+
const error = media.error;
|
|
2357
|
+
emitSignal(`Media playback failed — ${name} — ${shortUrl(location.href)}`, {
|
|
2358
|
+
errorCode: String(error?.code ?? 0),
|
|
2359
|
+
networkState: String(media.networkState),
|
|
2360
|
+
signal: BEACON_SIGNAL.MEDIA_PLAYBACK_FAILED,
|
|
2361
|
+
target: name
|
|
2362
|
+
});
|
|
2363
|
+
};
|
|
2364
|
+
media.addEventListener("playing", onPlay);
|
|
2365
|
+
media.addEventListener("waiting", onWaiting);
|
|
2366
|
+
media.addEventListener("stalled", onWaiting);
|
|
2367
|
+
media.addEventListener("waitingforkey", onWaiting);
|
|
2368
|
+
media.addEventListener("error", onError);
|
|
2369
|
+
media.addEventListener("pause", clearStall);
|
|
2370
|
+
media.addEventListener("ended", clearStall);
|
|
2371
|
+
const cleanup = () => {
|
|
2372
|
+
clearStall();
|
|
2373
|
+
media.removeEventListener("playing", onPlay);
|
|
2374
|
+
media.removeEventListener("waiting", onWaiting);
|
|
2375
|
+
media.removeEventListener("stalled", onWaiting);
|
|
2376
|
+
media.removeEventListener("waitingforkey", onWaiting);
|
|
2377
|
+
media.removeEventListener("error", onError);
|
|
2378
|
+
media.removeEventListener("pause", clearStall);
|
|
2379
|
+
media.removeEventListener("ended", clearStall);
|
|
2380
|
+
};
|
|
2381
|
+
watched.set(media, { cleanup, stallTimer });
|
|
2382
|
+
};
|
|
2383
|
+
const scan = (root) => {
|
|
2384
|
+
if (root instanceof HTMLMediaElement)
|
|
2385
|
+
watch(root);
|
|
2386
|
+
for (const media of Array.from(root.querySelectorAll?.(`audio[${BEACON_ATTRIBUTE.MEDIA}], video[${BEACON_ATTRIBUTE.MEDIA}]`) ?? [])) {
|
|
2387
|
+
if (media instanceof HTMLMediaElement)
|
|
2388
|
+
watch(media);
|
|
2389
|
+
}
|
|
2390
|
+
};
|
|
2391
|
+
scan(document);
|
|
2392
|
+
const observer = new MutationObserver((records) => {
|
|
2393
|
+
for (const record of records) {
|
|
2394
|
+
for (const node of Array.from(record.addedNodes)) {
|
|
2395
|
+
if (node instanceof Element)
|
|
2396
|
+
scan(node);
|
|
2397
|
+
}
|
|
2398
|
+
}
|
|
2399
|
+
});
|
|
2400
|
+
observer.observe(document.documentElement, {
|
|
2401
|
+
childList: true,
|
|
2402
|
+
subtree: true
|
|
2403
|
+
});
|
|
2404
|
+
cleanups.push(() => {
|
|
2405
|
+
observer.disconnect();
|
|
2406
|
+
for (const { cleanup } of watched.values())
|
|
2407
|
+
cleanup();
|
|
2408
|
+
watched.clear();
|
|
2409
|
+
});
|
|
2410
|
+
}
|
|
2411
|
+
if (signals !== null && signals.storageFailures !== false && typeof Storage !== "undefined") {
|
|
2412
|
+
const originalSetItem = Storage.prototype.setItem;
|
|
2413
|
+
const wrappedSetItem = function(key, value) {
|
|
2414
|
+
try {
|
|
2415
|
+
originalSetItem.call(this, key, value);
|
|
2416
|
+
} catch (error) {
|
|
2417
|
+
const resolved = toError(error);
|
|
2418
|
+
emitSignal(`Browser storage failure — ${resolved.name} — ${shortUrl(location.href)}`, {
|
|
2419
|
+
errorName: resolved.name,
|
|
2420
|
+
signal: BEACON_SIGNAL.STORAGE_FAILURE,
|
|
2421
|
+
storage: this === localStorage ? "localStorage" : "sessionStorage"
|
|
2422
|
+
});
|
|
2423
|
+
throw error;
|
|
2424
|
+
}
|
|
2425
|
+
};
|
|
2426
|
+
try {
|
|
2427
|
+
Storage.prototype.setItem = wrappedSetItem;
|
|
2428
|
+
cleanups.push(() => {
|
|
2429
|
+
Storage.prototype.setItem = originalSetItem;
|
|
2430
|
+
});
|
|
2431
|
+
} catch {}
|
|
2432
|
+
}
|
|
2433
|
+
if (signals !== null && signals.storageFailures !== false && typeof indexedDB !== "undefined") {
|
|
2434
|
+
const factory = indexedDB;
|
|
2435
|
+
const originalOpen = factory.open.bind(factory);
|
|
2436
|
+
const originalDeleteDatabase = factory.deleteDatabase.bind(factory);
|
|
2437
|
+
const reported = new WeakSet;
|
|
2438
|
+
const watch = (request, operation, database) => {
|
|
2439
|
+
request.addEventListener("error", () => {
|
|
2440
|
+
if (reported.has(request))
|
|
2441
|
+
return;
|
|
2442
|
+
reported.add(request);
|
|
2443
|
+
const error = request.error;
|
|
2444
|
+
emitSignal(`IndexedDB ${operation} failure — ${error?.name ?? "UnknownError"} — ${shortUrl(location.href)}`, {
|
|
2445
|
+
database: database.slice(0, SIGNAL_TEXT_MAX),
|
|
2446
|
+
errorName: error?.name ?? "UnknownError",
|
|
2447
|
+
operation,
|
|
2448
|
+
signal: BEACON_SIGNAL.STORAGE_FAILURE,
|
|
2449
|
+
storage: "indexedDB"
|
|
2450
|
+
});
|
|
2451
|
+
}, { once: true });
|
|
2452
|
+
return request;
|
|
2453
|
+
};
|
|
2454
|
+
const wrappedOpen = (name, version) => watch(version === undefined ? originalOpen(name) : originalOpen(name, version), "open", name);
|
|
2455
|
+
const wrappedDeleteDatabase = (name) => watch(originalDeleteDatabase(name), "delete", name);
|
|
2456
|
+
try {
|
|
2457
|
+
factory.open = wrappedOpen;
|
|
2458
|
+
factory.deleteDatabase = wrappedDeleteDatabase;
|
|
2459
|
+
cleanups.push(() => {
|
|
2460
|
+
if (factory.open === wrappedOpen)
|
|
2461
|
+
factory.open = originalOpen;
|
|
2462
|
+
if (factory.deleteDatabase === wrappedDeleteDatabase) {
|
|
2463
|
+
factory.deleteDatabase = originalDeleteDatabase;
|
|
2464
|
+
}
|
|
2465
|
+
});
|
|
2466
|
+
} catch {}
|
|
2467
|
+
}
|
|
1866
2468
|
if (signals !== null && signals.webglContextLosses !== false && typeof document !== "undefined") {
|
|
1867
2469
|
const graceMs = signals.webglRestoreGraceMs ?? WEBGL_RESTORE_GRACE_DEFAULT_MS;
|
|
1868
2470
|
const pending = new Map;
|
|
@@ -2022,6 +2624,48 @@ var createBeacon = (options) => {
|
|
|
2022
2624
|
document.addEventListener("wheel", onWheel, { passive: true });
|
|
2023
2625
|
cleanups.push(() => document.removeEventListener("wheel", onWheel));
|
|
2024
2626
|
}
|
|
2627
|
+
if (signals.thrashedCursors !== false) {
|
|
2628
|
+
const reversalThreshold = signals.thrashedCursorReversals ?? THRASHED_CURSOR_DEFAULT_REVERSALS;
|
|
2629
|
+
let points = [];
|
|
2630
|
+
let previous;
|
|
2631
|
+
let reported = false;
|
|
2632
|
+
const onPointerMove = (event) => {
|
|
2633
|
+
if (reported || event.pointerType === "touch")
|
|
2634
|
+
return;
|
|
2635
|
+
if (previous === undefined) {
|
|
2636
|
+
previous = { x: event.clientX, y: event.clientY };
|
|
2637
|
+
return;
|
|
2638
|
+
}
|
|
2639
|
+
const dx = event.clientX - previous.x;
|
|
2640
|
+
const dy = event.clientY - previous.y;
|
|
2641
|
+
previous = { x: event.clientX, y: event.clientY };
|
|
2642
|
+
if (Math.hypot(dx, dy) < 8)
|
|
2643
|
+
return;
|
|
2644
|
+
const now = Date.now();
|
|
2645
|
+
points = points.filter((point) => now - point.at < THRASHED_CURSOR_WINDOW_MS);
|
|
2646
|
+
points.push({ at: now, dx, dy });
|
|
2647
|
+
let reversals = 0;
|
|
2648
|
+
for (let index = 1;index < points.length; index += 1) {
|
|
2649
|
+
const prior = points[index - 1];
|
|
2650
|
+
const current = points[index];
|
|
2651
|
+
if (prior.dx * current.dx < 0 || prior.dy * current.dy < 0)
|
|
2652
|
+
reversals += 1;
|
|
2653
|
+
}
|
|
2654
|
+
if (reversals < reversalThreshold)
|
|
2655
|
+
return;
|
|
2656
|
+
reported = true;
|
|
2657
|
+
const target = event.target instanceof Element ? describeElement(event.target) : "document";
|
|
2658
|
+
emitSignal(`Thrashed cursor — repeated direction changes — ${shortUrl(location.href)}`, {
|
|
2659
|
+
reversals: String(reversals),
|
|
2660
|
+
signal: BEACON_SIGNAL.THRASHED_CURSOR,
|
|
2661
|
+
target
|
|
2662
|
+
});
|
|
2663
|
+
};
|
|
2664
|
+
document.addEventListener("pointermove", onPointerMove, {
|
|
2665
|
+
passive: true
|
|
2666
|
+
});
|
|
2667
|
+
cleanups.push(() => document.removeEventListener("pointermove", onPointerMove));
|
|
2668
|
+
}
|
|
2025
2669
|
if (signals.focusLoss !== false || signals.modalFocusEscape !== false) {
|
|
2026
2670
|
const DIALOG_SELECTOR = '[role="dialog"], [aria-modal="true"], dialog';
|
|
2027
2671
|
const MODAL_SELECTOR = '[aria-modal="true"], dialog[open]';
|
|
@@ -2196,6 +2840,46 @@ var createBeacon = (options) => {
|
|
|
2196
2840
|
document.removeEventListener("invalid", onInvalid, true);
|
|
2197
2841
|
});
|
|
2198
2842
|
}
|
|
2843
|
+
if (signals.formAbandonment !== false) {
|
|
2844
|
+
const dirtyForms = new Set;
|
|
2845
|
+
const submittedForms = new WeakSet;
|
|
2846
|
+
const onInput = (event) => {
|
|
2847
|
+
const target = event.target;
|
|
2848
|
+
const form = target instanceof HTMLInputElement || target instanceof HTMLSelectElement || target instanceof HTMLTextAreaElement ? target.form : null;
|
|
2849
|
+
if (form?.hasAttribute(BEACON_ATTRIBUTE.FORM) === true) {
|
|
2850
|
+
dirtyForms.add(form);
|
|
2851
|
+
}
|
|
2852
|
+
};
|
|
2853
|
+
const onSubmit = (event) => {
|
|
2854
|
+
if (!(event.target instanceof HTMLFormElement))
|
|
2855
|
+
return;
|
|
2856
|
+
submittedForms.add(event.target);
|
|
2857
|
+
dirtyForms.delete(event.target);
|
|
2858
|
+
};
|
|
2859
|
+
const report = () => {
|
|
2860
|
+
for (const form of dirtyForms) {
|
|
2861
|
+
if (!form.isConnected || submittedForms.has(form))
|
|
2862
|
+
continue;
|
|
2863
|
+
const name = form.getAttribute(BEACON_ATTRIBUTE.FORM)?.trim() || describeElement(form);
|
|
2864
|
+
emitSignal(`Form abandonment — ${name} left dirty — ${shortUrl(location.href)}`, {
|
|
2865
|
+
fieldCount: String(form.elements.length),
|
|
2866
|
+
signal: BEACON_SIGNAL.FORM_ABANDONMENT,
|
|
2867
|
+
target: name
|
|
2868
|
+
});
|
|
2869
|
+
dirtyForms.delete(form);
|
|
2870
|
+
}
|
|
2871
|
+
};
|
|
2872
|
+
reportFormAbandonmentOnNavigation = report;
|
|
2873
|
+
document.addEventListener("input", onInput, true);
|
|
2874
|
+
document.addEventListener("submit", onSubmit, true);
|
|
2875
|
+
window.addEventListener("pagehide", report);
|
|
2876
|
+
cleanups.push(() => {
|
|
2877
|
+
reportFormAbandonmentOnNavigation = null;
|
|
2878
|
+
document.removeEventListener("input", onInput, true);
|
|
2879
|
+
document.removeEventListener("submit", onSubmit, true);
|
|
2880
|
+
window.removeEventListener("pagehide", report);
|
|
2881
|
+
});
|
|
2882
|
+
}
|
|
2199
2883
|
}
|
|
2200
2884
|
if (signals !== null && (signals.stalledStreams !== false || signals.sseFlapping !== false) && typeof window.EventSource === "function") {
|
|
2201
2885
|
const stalledStreamMs = signals.stalledStreamMs ?? STALLED_STREAM_DEFAULT_MS;
|
|
@@ -2299,10 +2983,16 @@ var createBeacon = (options) => {
|
|
|
2299
2983
|
construct(target, args) {
|
|
2300
2984
|
const socket = Reflect.construct(target, args);
|
|
2301
2985
|
const label = shortUrl(String(args[0]));
|
|
2986
|
+
let applicationClose = false;
|
|
2987
|
+
const originalClose = socket.close.bind(socket);
|
|
2988
|
+
socket.close = (code, reason) => {
|
|
2989
|
+
applicationClose = true;
|
|
2990
|
+
originalClose(code, reason);
|
|
2991
|
+
};
|
|
2302
2992
|
socket.addEventListener("close", (event) => {
|
|
2303
|
-
if (pageLifecycleEnding)
|
|
2993
|
+
if (pageLifecycleEnding || applicationClose)
|
|
2304
2994
|
return;
|
|
2305
|
-
if (signals.socketAbnormalCloses !== false && typeof CloseEvent !== "undefined" && event instanceof CloseEvent &&
|
|
2995
|
+
if (signals.socketAbnormalCloses !== false && typeof CloseEvent !== "undefined" && event instanceof CloseEvent && !event.wasClean) {
|
|
2306
2996
|
const abnormalKey = `${label}|${event.code}`;
|
|
2307
2997
|
if (!reportedAbnormalCloses.has(abnormalKey)) {
|
|
2308
2998
|
reportedAbnormalCloses.add(abnormalKey);
|
|
@@ -2505,17 +3195,22 @@ var createBeacon = (options) => {
|
|
|
2505
3195
|
}
|
|
2506
3196
|
if (signals !== null && signals.reloadLoops !== false && typeof sessionStorage !== "undefined") {
|
|
2507
3197
|
try {
|
|
2508
|
-
const
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
3198
|
+
const navigation = performance.getEntriesByType("navigation")[0];
|
|
3199
|
+
if (navigation?.type !== "back_forward") {
|
|
3200
|
+
const now = Date.now();
|
|
3201
|
+
const route = normalizeSignalIdentityPart(shortUrl(location.href));
|
|
3202
|
+
const raw = sessionStorage.getItem(RELOAD_LOOP_STORAGE_KEY);
|
|
3203
|
+
const parsed = raw === null ? [] : JSON.parse(raw);
|
|
3204
|
+
const history2 = (Array.isArray(parsed) ? parsed : []).filter((entry) => entry !== null && typeof entry === "object" && typeof entry.at === "number" && typeof entry.route === "string" && now - entry.at < RELOAD_LOOP_WINDOW_MS);
|
|
3205
|
+
history2.push({ at: now, route });
|
|
3206
|
+
sessionStorage.setItem(RELOAD_LOOP_STORAGE_KEY, JSON.stringify(history2));
|
|
3207
|
+
const routeLoads = history2.filter((entry) => entry.route === route);
|
|
3208
|
+
if (routeLoads.length >= RELOAD_LOOP_COUNT) {
|
|
3209
|
+
emitSignal(`Reload loop — repeated page loads within a minute — ${shortUrl(location.href)}`, {
|
|
3210
|
+
loadCount: String(routeLoads.length),
|
|
3211
|
+
signal: BEACON_SIGNAL.RELOAD_LOOP
|
|
3212
|
+
});
|
|
3213
|
+
}
|
|
2519
3214
|
}
|
|
2520
3215
|
} catch {}
|
|
2521
3216
|
}
|
|
@@ -2593,6 +3288,25 @@ var createBeacon = (options) => {
|
|
|
2593
3288
|
recordRequestForStorm = null;
|
|
2594
3289
|
});
|
|
2595
3290
|
}
|
|
3291
|
+
const classifySemanticResponse = (response, request) => {
|
|
3292
|
+
const classifier = instrument.classifyResponse;
|
|
3293
|
+
if (classifier === undefined || !response.ok)
|
|
3294
|
+
return;
|
|
3295
|
+
Promise.resolve(classifier(response.clone(), request)).then((result) => {
|
|
3296
|
+
if (result === undefined || result === false)
|
|
3297
|
+
return;
|
|
3298
|
+
captureException(errorWithoutStack("SemanticResponseFailure", result.message), {
|
|
3299
|
+
groupingKey: result.groupingKey,
|
|
3300
|
+
level: "warning",
|
|
3301
|
+
tags: {
|
|
3302
|
+
endpoint: shortUrl(request.url),
|
|
3303
|
+
method: request.method.toUpperCase(),
|
|
3304
|
+
signal: BEACON_SIGNAL.SEMANTIC_RESPONSE_FAILURE,
|
|
3305
|
+
...result.tags ?? {}
|
|
3306
|
+
}
|
|
3307
|
+
});
|
|
3308
|
+
}).catch(() => {});
|
|
3309
|
+
};
|
|
2596
3310
|
if (instrument.fetch !== false && typeof window.fetch === "function") {
|
|
2597
3311
|
const originalFetch = window.fetch;
|
|
2598
3312
|
const wrapped = async (...args) => {
|
|
@@ -2612,6 +3326,7 @@ var createBeacon = (options) => {
|
|
|
2612
3326
|
type: "fetch"
|
|
2613
3327
|
});
|
|
2614
3328
|
reportResponseSignal(url, method, response.status, Date.now() - start, responseTraceId(response.headers.get(BEACON_TRACE_HEADER)));
|
|
3329
|
+
classifySemanticResponse(response, { method, url });
|
|
2615
3330
|
return response;
|
|
2616
3331
|
} catch (error) {
|
|
2617
3332
|
const resolved = toError(error);
|
|
@@ -2666,6 +3381,20 @@ var createBeacon = (options) => {
|
|
|
2666
3381
|
});
|
|
2667
3382
|
if (!failed) {
|
|
2668
3383
|
reportResponseSignal(request.url, request.method, this.status, Date.now() - start, responseTraceId(this.getResponseHeader(BEACON_TRACE_HEADER)));
|
|
3384
|
+
if (instrument.classifyResponse !== undefined && this.status >= 200 && this.status < 300 && (this.responseType === "" || this.responseType === "text")) {
|
|
3385
|
+
const headers = new Headers;
|
|
3386
|
+
for (const line of this.getAllResponseHeaders().split(/\r?\n/u)) {
|
|
3387
|
+
const separator = line.indexOf(":");
|
|
3388
|
+
if (separator <= 0)
|
|
3389
|
+
continue;
|
|
3390
|
+
headers.append(line.slice(0, separator).trim(), line.slice(separator + 1).trim());
|
|
3391
|
+
}
|
|
3392
|
+
classifySemanticResponse(new Response(this.responseText, {
|
|
3393
|
+
headers,
|
|
3394
|
+
status: this.status,
|
|
3395
|
+
statusText: this.statusText
|
|
3396
|
+
}), request);
|
|
3397
|
+
}
|
|
2669
3398
|
} else {
|
|
2670
3399
|
const error = new Error(outcome === "timeout" ? "XMLHttpRequest timed out" : outcome === "aborted" ? "XMLHttpRequest was aborted" : "XMLHttpRequest completed with status 0");
|
|
2671
3400
|
error.name = outcome === "timeout" ? "TimeoutError" : outcome === "aborted" ? "AbortError" : "XMLHttpRequestError";
|
|
@@ -2691,6 +3420,7 @@ var createBeacon = (options) => {
|
|
|
2691
3420
|
const patch = (key) => {
|
|
2692
3421
|
const original = history[key].bind(history);
|
|
2693
3422
|
history[key] = (...args) => {
|
|
3423
|
+
reportFormAbandonmentOnNavigation?.();
|
|
2694
3424
|
const result = original(...args);
|
|
2695
3425
|
record();
|
|
2696
3426
|
return result;
|
|
@@ -2700,8 +3430,12 @@ var createBeacon = (options) => {
|
|
|
2700
3430
|
};
|
|
2701
3431
|
};
|
|
2702
3432
|
cleanups.push(patch("pushState"), patch("replaceState"));
|
|
2703
|
-
|
|
2704
|
-
|
|
3433
|
+
const onPopState = () => {
|
|
3434
|
+
reportFormAbandonmentOnNavigation?.();
|
|
3435
|
+
record();
|
|
3436
|
+
};
|
|
3437
|
+
window.addEventListener("popstate", onPopState);
|
|
3438
|
+
cleanups.push(() => window.removeEventListener("popstate", onPopState));
|
|
2705
3439
|
}
|
|
2706
3440
|
const timer = setInterval(() => {
|
|
2707
3441
|
flush();
|
|
@@ -2734,6 +3468,7 @@ var createBeacon = (options) => {
|
|
|
2734
3468
|
await flush(true);
|
|
2735
3469
|
},
|
|
2736
3470
|
flush: () => flush(false),
|
|
3471
|
+
observeCapability,
|
|
2737
3472
|
setTags: (next) => {
|
|
2738
3473
|
tags = { ...tags, ...next };
|
|
2739
3474
|
},
|
|
@@ -2751,8 +3486,10 @@ var getBeacon = () => current;
|
|
|
2751
3486
|
var captureException = (error, context) => current?.captureException(error, context);
|
|
2752
3487
|
var captureMessage = (message, level, context) => current?.captureMessage(message, level, context);
|
|
2753
3488
|
var addBreadcrumb = (crumb) => current?.addBreadcrumb(crumb);
|
|
3489
|
+
var observeCapability = (name, operation) => current?.observeCapability(name, operation) ?? operation;
|
|
2754
3490
|
export {
|
|
2755
3491
|
redactBeaconEvent,
|
|
3492
|
+
observeCapability,
|
|
2756
3493
|
isKnownBeaconNoise,
|
|
2757
3494
|
initBeacon,
|
|
2758
3495
|
getBeacon,
|
|
@@ -2765,5 +3502,5 @@ export {
|
|
|
2765
3502
|
BEACON_ATTRIBUTE
|
|
2766
3503
|
};
|
|
2767
3504
|
|
|
2768
|
-
//# debugId=
|
|
3505
|
+
//# debugId=76E798F97A6224E464756E2164756E21
|
|
2769
3506
|
//# sourceMappingURL=index.js.map
|