关闭浏览器后如何唤醒服务人员 [英] How can I wake up service worker when browser closed

查看:159
本文介绍了关闭浏览器后如何唤醒服务人员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在玩服务人员的东西. 我已经做到了,以及清单json. 在以下情况下,我想触发服务人员启动:

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.

以下是我要尝试启动Service Worker的步骤:

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

  1. 我第一次打开网页
  2. 服务-工人已安装
  3. 我完全关闭了浏览器
  4. 我重新打开浏览器
  5. 现在我需要触发Service -Worker启动-怎么样?

我想知道我可以使用什么,或者需要在Service Worker js或manifest json中添加什么才能使这种情况成为可能.

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.

推荐答案

您不能像这样那样启动Service Worker .

Service Worker由浏览器处理,并在发生匹配事件时启动. Web推送通知就是这样的事件之一.如果用户已接受从您的Web应用程序的后端服务器接收通知,则即使用户不在您的网站上,该推送通知也将通过Service Worker向用户显示.

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.

但是您不能在启动浏览器而不访问您的页面时立即启动" Service Worker并让它执行某些操作.

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

我强烈建议您阅读有关推送通知的Google网络基础知识系列: https://developers.google.com/web/fundamentals/push-notifications

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

这篇关于关闭浏览器后如何唤醒服务人员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆