Skip to main content
InterviewHubPRO
Section Overview
Q34

Question 34 of 50

Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)

68%
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:

  1. BroadcastChannel: Allows different browser tabs or windows from the same origin to communicate in real-time:
    javascript
    const 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';
    };
    
  2. 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).