Javascript 如何处理来自服务工作者以外的其他js的推送通知?

Javascript 如何处理来自服务工作者以外的其他js的推送通知?,javascript,jquery,push-notification,progressive-web-apps,service-worker,Javascript,Jquery,Push Notification,Progressive Web Apps,Service Worker,是否可以处理来自服务工作者以外的任何js的推送通知?如果是,如何进行 我的处境: 我最近在我的项目中实现了web推送通知(我遵循了这一点) 我的项目中有:index.html、index.js和一名服务人员 在我的index.js中,有一个时刻我将加载程序显示为微调器。我想等待,直到从我的服务器收到一个推送通知,该通知将发送给我,例如,一个ID。一旦收到通知,我想删除我的加载程序,并在我的index.js中显示一个弹出/对话框 怎么做?如何通知我的index.js我收到推送通知?除了服务工作者之

是否可以处理来自服务工作者以外的任何js的推送通知?如果是,如何进行

我的处境:

我最近在我的项目中实现了web推送通知(我遵循了这一点)

我的项目中有:index.html、index.js和一名服务人员

在我的index.js中,有一个时刻我将加载程序显示为微调器。我想等待,直到从我的服务器收到一个推送通知,该通知将发送给我,例如,一个ID。一旦收到通知,我想删除我的加载程序,并在我的index.js中显示一个弹出/对话框

怎么做?如何通知我的index.js我收到推送通知?除了服务工作者之外,我们还能在index.js中捕获推送通知吗?我们可以处理index.js中的推送通知吗

我的尝试: 我的服务人员:

self.addEventListener('push', function(event) {
    console.log('[Service Worker] Push Received.');
    console.log(`[Service Worker] Push had this data: "${event.data.text()}"`);

    if (event.data.text().toLowerCase().indexOf("id") >= 0) {
      displayDialog(event.data.text()); // HERE I tried to call a function from index.js, but not working
    }
  
    const title = 'My project';
    const options = {
      body: `${event.data.text()}`,
      icon: './images/logo/logo192.png',
      badge: './images/logo/logo192.png'
    };
  
    event.waitUntil(self.registration.showNotification(title, options));
});
  
self.addEventListener('notificationclick', function(event) {
    console.log('[Service Worker] Notification click Received.');
  
    event.notification.close();
  
    event.waitUntil(
      clients.openWindow('https://developers.google.com/web/')
    );
});
My index.js(不是所有代码,但在index.js中,我还订阅或取消订阅推送通知):

function displayDialog(id) {
  $(."loader").hide(); // I remove the loader
  // Here I display my dialog and do other things
}
$(."loader").show(); // Now I have to wait that I receive a push notification from my server