Skip to content

Instantly share code, notes, and snippets.

@brittanydionigi
Created March 16, 2015 19:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brittanydionigi/689a42ac67b7a864dc62 to your computer and use it in GitHub Desktop.
Save brittanydionigi/689a42ac67b7a864dc62 to your computer and use it in GitHub Desktop.
messaging in service workers
// index.html -- Sending message TO service worker, FROM page:
navigator.serviceWorker.controller.postMessage(message);
// service-worker.js -- Handling message event in service worker by posting a message back to the page:
self.addEventListener('message', function(event) {
self.clients.matchAll().then(function(client) {
client[0].postMessage({
command: 'logMessage',
error: null,
message: 'hi there message here!!'
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment