Files
workbox/demos/functions/views/demo/workbox-broadcast-cache-update.hbs
T
Jeffrey PosnickandGitHub 9d88f2abae The contents of v3, reconciled with master (#1357)
* 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
2018-03-13 15:20:33 -04:00

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>