From b11f0cd58b2d2e3517edf6b9a7ad1b8e63534661 Mon Sep 17 00:00:00 2001 From: ciregenz Date: Fri, 26 Jun 2026 07:31:06 -0700 Subject: [PATCH] [eric] browser: force the guest page-world to always report visible/foregrounded (main-world inject) so an off-screen kept-alive Discord doesn't background + drop its session = logout --- electron/main.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/electron/main.js b/electron/main.js index 4b04e562..efdf1d84 100644 --- a/electron/main.js +++ b/electron/main.js @@ -2209,6 +2209,28 @@ app.on('web-contents-created', (_event, contents) => { `).catch(() => {}); }); + // Force the guest's PAGE WORLD to always report visible/foregrounded. When a kept-alive browser card sits on another dashboard it's parked off-screen; the page-visibility API then reads hidden, so a real-time app (Discord) backgrounds itself, drops its gateway socket, and on return can't resume the session -> "please log in again". The webview-preload patches this too but only in the isolated world (contextIsolation), so the page's OWN code never sees it; injecting here in the main world is what actually keeps Discord logged in while hidden. document.hasFocus is forced true for the same reason; visibilitychange/freeze/pagehide are swallowed so nothing downstream reacts to a backgrounding that, to us, never happens. + contents.on('dom-ready', () => { + contents.executeJavaScript(` + (function(){ + try { + if (window.__openswarm_vis__) return; window.__openswarm_vis__ = true; + var def = function(o, k, v){ try { Object.defineProperty(o, k, { get: function(){ return v; }, configurable: true }); } catch(e){} }; + def(document, 'hidden', false); + def(document, 'visibilityState', 'visible'); + def(document, 'webkitHidden', false); + def(document, 'webkitVisibilityState', 'visible'); + try { document.hasFocus = function(){ return true; }; } catch(e){} + var swallow = function(e){ e.stopImmediatePropagation(); }; + ['visibilitychange','webkitvisibilitychange','freeze','pagehide'].forEach(function(t){ + window.addEventListener(t, swallow, true); + document.addEventListener(t, swallow, true); + }); + } catch (e) {} + })(); + `).catch(() => {}); + }); + // WebAuthn/passkey shim. Injected on every dom-ready in the main world // via executeJavaScript (which uses V8's direct evaluation path and // bypasses Trusted Types CSP — inline