I’m building a web app using Dash that runs locally. While I know about Electron, I prefer working with Dash and pyinstaller for my project needs. My goal is to create multiple browser windows that can communicate with each other - where actions in one window affect the other.
I noticed that Spotify’s web player does exactly this on their site. When you have multiple tabs open, the play/pause buttons stay in sync, and even the current playback position updates simultaneously across all tabs. This happens in real time without any delays.
What’s the underlying technology that makes this possible? Are they using some kind of background workers or is there another approach for cross-tab communication?
spotify uses localStorage events and indexedDB 2gether. they have this “master tab” concept where 1 tab runs the show and the others just sync. when the master tab closes, another takes over. for ur dash, just use sqlite and have all windows check it every few hundred milliseconds - way simpler than dealing with browser apis.
I’ve tackled similar sync issues before. Spotify probably uses SharedArrayBuffer + Service Workers for cross-tab coordination. Service Workers run in the background and can talk to all tabs at once, keeping a central state that pushes updates instantly. For your Dash app, skip WebSockets and go with server-sent events (SSE) instead. Since Dash already handles server state, you can stream updates to all browser windows through SSE endpoints. Each window subscribes to the event stream - when one window does something, your server broadcasts the change to everyone subscribed. Works great with Dash’s callback system and you won’t need polling or messy client-side storage.
Spotify probably uses the Web Storage API - localStorage events plus the Broadcast Channel API. One tab updates playback state, writes to localStorage, and triggers storage events that other tabs pick up. The Broadcast Channel API is another clean way to send real-time messages between tabs without hitting a server.
For your Dash app, you’ve got a few options. Each browser window could check a shared state file periodically, or use WebSocket connections to your local server. Since Dash runs server-side, you can keep all the state in one place. Windows could either poll the server for updates or use WebSockets to get instant notifications when another window does something. This’ll be way easier than trying to copy browser cross-tab communication.