mirror of
https://github.com/hanzoai/workbox.git
synced 2026-09-24 17:04:35 +00:00
* The contents of v3, reconciled with master. * Remove a few stray files. * Another extra file. * Two more deletions. * Setting up for stable release * v3.0.0 * Updating CDN and versions * Doc repair for wf (#1358) * Changing doc structure to work with WF * Changing doc structure to work with WF
40 lines
1.1 KiB
Handlebars
40 lines
1.1 KiB
Handlebars
<section>
|
|
<div class="container">
|
|
<div class="row">
|
|
<div class="col-lg-8 mx-auto">
|
|
<ol>
|
|
<li>Open DevTools</li>
|
|
<li>Go to the Console</li>
|
|
<li>Click any of the buttons below and view the logs:
|
|
<ul>
|
|
<li><p><button class="trigger-broadcast btn btn-outline-primary">Trigger a Broadcast</button></p></li>
|
|
</ul>
|
|
</li>
|
|
</ol>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
<script>
|
|
const triggerBroadcast = document.querySelector('.trigger-broadcast');
|
|
|
|
const broadcastChannel = new BroadcastChannel('broadcast-demo');
|
|
broadcastChannel.onmessage = (ev) => {
|
|
console.log(`Received a message on 'broadcast-demo' channel.`);
|
|
console.log(ev.data);
|
|
};
|
|
|
|
window.addEventListener('load', () => {
|
|
navigator.serviceWorker.register('/demo/workbox-broadcast-cache-update/sw.js')
|
|
.then((reg) => {
|
|
triggerBroadcast.addEventListener('click', () => {
|
|
const message = {
|
|
command: 'trigger-broadcast',
|
|
};
|
|
reg.active.postMessage(message);
|
|
});
|
|
});
|
|
});
|
|
</script>
|