How can I wake up service worker when browser closed

我的梦境 提交于 2019-12-24 19:15:04

问题


I am playing with service worker stuff. I already made it as well as manifest json. I want to trigger service worker start after following scenario:

Added push integration and sending push notification from server side. Received it in client side, but only if I am in my application page.

Here are the steps what I want to try to start service worker:

  1. I opened the web page for the first time
  2. Service - Worker is installed
  3. I totally close the browser
  4. I re-open the browser
  5. Now I need to trigger Service -Worker start - How ?

I want to know what I can use or what I need to add in my service worker js or manifest json to make this scenario possible.


回答1:


You cannot start the Service Worker just like that.

The Service Worker is handled by the browser and started when a matching event occurs. Web push notification is one such an event. If the user has accepted to receive notifications from your web application's backend server, then the push notification will be shown to the user through the Service Worker even if the user is not on your website.

But you cannot "just start" the Service Worker and have it do something when the browser is opened without accessing your page.

I highly recommend you to read Google's Web Fundamentals series on push notifications: https://developers.google.com/web/fundamentals/push-notifications



来源:https://stackoverflow.com/questions/58258677/how-can-i-wake-up-service-worker-when-browser-closed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!