我如何知道我的 Web 应用程序在 Service Worker 中是打开还是关闭?

问题描述 投票:0回答:1

可以知道我的 Web 应用程序是否在 Service Worker 中打开了任何选项卡?

javascript service-worker
1个回答
1
投票

这样的东西解决了我的问题。

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);
© www.soinside.com 2019 - 2025. All rights reserved.