MENU
Broadcast Channel
The Broadcast Channel API can be used to send data to every other worker, iframe, and tab.
This will work across tabs too.
RESETRUNFULL
RESETRUNFULL
// /shared/broadcast.js (fixed)
var bc = new BroadcastChannel('channelX');
setTimeout(()=>bc.postMessage(Date.now()),
Math.random()*15000);
bc.onmessage = e=>console.log(e.data);
<!DOCTYPE html><html><body style="height:100px">
<p></p>
<script>
var bc = new BroadcastChannel('channelX');
bc.onmessage = e=>{
document.querySelector("p").innerHTML += e.data + "<br/>";
}
for (let i=0; i<5; i++) new Worker('/shared/broadcast.js');
</script></body></html>