Crash detection: Track last user interaction to identify crashes happening after user interactions (#97914)

* Track last user interaction to identify crashes happening after user interactions

* Add keypress event and use capture phase
This commit is contained in:
Piotr Jamróz 2025-01-03 13:45:05 +01:00 committed by GitHub
parent 51d9b577d5
commit dc8e010cf3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -21,6 +21,7 @@ interface GrafanaCrashReport extends BaseStateReport {
email: string;
login: string;
name: string;
lastInteraction: number;
};
memory?: {
heapUtilization: number;
@ -36,6 +37,11 @@ export function initializeCrashDetection() {
return;
}
let lastInteraction = Date.now();
// Add last interaction listeners to capture phase to reduce skipped events when stopPropagation() is called
document.body.addEventListener('click', () => (lastInteraction = Date.now()), true);
document.body.addEventListener('keypress', () => (lastInteraction = Date.now()), true);
initCrashDetection<GrafanaCrashReport>({
id: nanoid(5),
@ -81,6 +87,7 @@ export function initializeCrashDetection() {
email: contextSrv.user.email,
login: contextSrv.user.login,
name: contextSrv.user.name,
lastInteraction,
};
if (isChromePerformance(performance)) {