From f3e2cfa31b4b27e0e2d22ca8a9732f2a946fa447 Mon Sep 17 00:00:00 2001 From: mdatagent Date: Sun, 25 Oct 2026 11:52:17 +0200 Subject: [PATCH] fix(web): keep dictating when the tab or app goes to the background Hiding the page (switching browser tabs, opening a link, switching apps) stopped the recording and sent it for transcription. Recording now continues while the page is hidden, and the screen wake lock is taken again when the page becomes visible. Hiding the page while the microphone is still starting behaves as before. Co-Authored-By: Claude Opus 5.5 --- .../web/src/voice-input/VoiceInputControl.tsx | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/apps/web/src/voice-input/VoiceInputControl.tsx b/apps/web/src/voice-input/VoiceInputControl.tsx index 47dc9e9ee831..df4bcb03b0ae 100644 --- a/apps/web/src/voice-input/VoiceInputControl.tsx +++ b/apps/web/src/voice-input/VoiceInputControl.tsx @@ -276,17 +276,17 @@ function VoiceInputSession( controllerRef.current = controller; const sharedControllerRef = props.controllerRef; sharedControllerRef.current = controller; - const background = () => { - if (controller.currentState.phase !== "idle") - diagnostics.log("visibility", { - visibility: document.visibilityState, - phase: controller.currentState.phase, - }); - if (!document.hidden) return; - if (controller.currentState.phase === "recording") void controller.stop(); - else void controller.appMovedToBackground(); + const visibilityChanged = () => { + const phase = controller.currentState.phase; + if (phase !== "idle") + diagnostics.log("visibility", { visibility: document.visibilityState, phase }); + if (!document.hidden) { + keepScreenAwake(wakeLockWanted); + return; + } + if (phase === "preparing") void controller.appMovedToBackground(); }; - document.addEventListener("visibilitychange", background); + document.addEventListener("visibilitychange", visibilityChanged); return () => { mounted = false; diagnostics.flush(); @@ -297,7 +297,7 @@ function VoiceInputSession( controllerRef.current = null; if (sharedControllerRef.current === controller) sharedControllerRef.current = null; onBusyChange(false); - document.removeEventListener("visibilitychange", background); + document.removeEventListener("visibilitychange", visibilityChanged); }; }, [ supported,