javascriptservice-worker

How can I know if my web application is open or closed inside a service worker?


It is possible to know if my web application has anyone tab open inside a service worker?


Solution

  • Something like this solve my problem.

    self.addEventListener('push', (event) => {
    
      self.clients.matchAll({includeUncontrolled: true, type: 'window'})
      .then((clients) => {
        if(clients && clients.length > 0) {
          // Show notification or do other dependent code
        }
      });
    
    }, false);