Skip to content

Instantly share code, notes, and snippets.

@gauntface
Created March 6, 2017 22:24
Show Gist options
  • Select an option

  • Save gauntface/b33d0fbd024c0560c6c082fe7fd2ad12 to your computer and use it in GitHub Desktop.

Select an option

Save gauntface/b33d0fbd024c0560c6c082fe7fd2ad12 to your computer and use it in GitHub Desktop.
self.addEventListener('push', function(event) {
let pushData = null;
if (event.data) {
pushData = event.data.text();
}
// Send message to page
const promiseChain = self.clients.matchAll({
includeUncontrolled: true
})
.then(function(clients) {
const sendMsgPromises = clients.map(function(client) {
return client.postMessage(pushData);
});
return Promise.all(sendMsgPromises);
});
event.waitUntil(promiseChain);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment