HTML5 & Web APIs (50 Qs)•Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)
BroadcastChannel API and Web Locks API for Multi-Tab Coordination.
senior LevelCode ExampleSystem DesignGolangHTTP & REST APIs
In Simple Words:
BroadcastChannel: Allows different browser tabs or windows from the same origin to communicate in real-time:javascriptconst authChannel = new BroadcastChannel('auth'); // Tab A logs out: authChannel.postMessage({ action: 'LOGOUT' }); // Tab B receives message and redirects to login: authChannel.onmessage = (e) => { if (e.data.action === 'LOGOUT') window.location.href = '/login'; };- Web Locks API (
navigator.locks.request): Acquires an atomic lock across all browser tabs, preventing race conditions (e.g., ensuring only ONE tab synchronizes offline data to the server at a time).