PostMessage from serviceWorker after push event

I need to send a message from a serviceWorker to a page after a push event. I am unable to specify the port property (e.g. https://jakearchibald.github.io/isserviceworkerready/demos/postMessage/ ) because I did not post this post

This code does not work (maybe I am doing something wrong)

self.registration.active.postMessage('fsdfasf');

      

+3


source to share


1 answer


Following the specs , what appears to be the correct implementation is picking Client

from Worker Worker and then using a postMessage

method like:



onmessage = function(event){
  clients.matchAll().then(function(clients){
    clients[0].postMesssage('yourmessage');
  });
}

      

+3


source







All Articles