The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): prevent navigation from stealing focus
Jakub Wolniewicz23954e3e3151
diff --git a/apps/desktop/electron/session-windows.test.ts b/apps/desktop/electron/session-windows.test.tsindex a3dbfc04e4a..1959cc44583 100644--- a/apps/desktop/electron/session-windows.test.ts+++ b/apps/desktop/electron/session-windows.test.ts@@ -203,6 +203,22 @@ test('chatWindowWebPreferences leaves background throttling to the runtime streaassert.equal('backgroundThrottling' in prefs, false)})+test('chat renderer navigation stays passive while explicit window actions may focus', () => {+ const prefs = chatWindowWebPreferences('/tmp/preload.cjs')++ // In-page/SPA navigation can happen while a transcript keeps streaming. It+ // must not use Electron's default navigation focus path to activate Hermes.+ assert.equal(prefs.focusOnNavigation, false)++ // Re-opening a session is an explicit user action and must still raise the+ // existing window; the passive navigation guard does not disable that path.+ const registry = createSessionWindowRegistry()+ const win = makeFakeWindow()+ registry.openOrFocus('s1', () => win)+ registry.openOrFocus('s1', () => win)+ assert.equal(win.calls.focus, 1)+})+test('chatWindowWebPreferences passes the preload path through and keeps the hardened defaults', () => {const prefs = chatWindowWebPreferences('/some/preload.cjs')diff --git a/apps/desktop/electron/session-windows.ts b/apps/desktop/electron/session-windows.tsindex 81736908fce..790f1c03a73 100644--- a/apps/desktop/electron/session-windows.ts+++ b/apps/desktop/electron/session-windows.ts@@ -37,6 +37,12 @@ const SESSION_WINDOW_MIN_HEIGHT = 620// session is silent" bug. Manual voice-start worked only because the button// click counted as the gesture. This is a native app the user deliberately// launched; there is no drive-by-autoplay concern to protect against.+//+// `focusOnNavigation: false` keeps renderer-driven work passive. Electron's+// default is true, so an in-page/SPA navigation can activate a blurred chat+// window while its transcript is streaming. Explicit user actions still call+// the main-process window focus paths (session re-open, notification/deep-link,+// app activation), preserving intentional raises without background focus theft.function chatWindowWebPreferences(preloadPath: string) {return {preload: preloadPath,@@ -45,7 +51,8 @@ function chatWindowWebPreferences(preloadPath: string) {sandbox: true,nodeIntegration: false,devTools: true,- autoplayPolicy: 'no-user-gesture-required' as const+ autoplayPolicy: 'no-user-gesture-required' as const,+ focusOnNavigation: false}}