From dc8e010cf325f6465dae4d444844077ca8c423ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Jamr=C3=B3z?= Date: Fri, 3 Jan 2025 13:45:05 +0100 Subject: [PATCH] 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 --- public/app/core/crash/index.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/public/app/core/crash/index.ts b/public/app/core/crash/index.ts index e3ef01ed25d..68022a81aea 100644 --- a/public/app/core/crash/index.ts +++ b/public/app/core/crash/index.ts @@ -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({ 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)) {