From 70da8dad38e555e5a40cce427c5b552ec4b295ac Mon Sep 17 00:00:00 2001 From: Brian Krabach Date: Mon, 30 Mar 2026 19:03:27 -0700 Subject: [PATCH] fix: don't clear bells when browser tab is hidden sendHeartbeat() always reported _viewingSession even when the user switched to another browser tab. The server saw 'device is watching session X' and cleared bells immediately. Fix: use Page Visibility API (document.hidden) to send viewing_session=null when the tab is in the background. Bells accumulate correctly, favicon badge shows activity, and indicators appear in the dashboard/sidebar. When the user switches back to the muxplex tab, the next heartbeat restores the real session. --- muxplex/frontend/app.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/muxplex/frontend/app.js b/muxplex/frontend/app.js index ca51984..43f5e99 100644 --- a/muxplex/frontend/app.js +++ b/muxplex/frontend/app.js @@ -764,7 +764,14 @@ function handleBellTransitions(prevSessions, nextSessions) { */ async function sendHeartbeat() { try { - const payload = buildHeartbeatPayload(_deviceId, _viewingSession, _viewMode, _lastInteractionAt); + // When the browser tab is hidden (user switched tabs or minimized), report + // viewing_session as null. This prevents the server from clearing bells on + // the session — the user isn't actually looking at it, so activity should + // accumulate and show in the favicon badge / tab indicators. + var effectiveSession = (typeof document !== 'undefined' && document.hidden) + ? null + : _viewingSession; + const payload = buildHeartbeatPayload(_deviceId, effectiveSession, _viewMode, _lastInteractionAt); await api('POST', '/api/heartbeat', payload); } catch (err) { console.warn('[sendHeartbeat] heartbeat failed:', err);