我可以使用 Service Worker 来获取用户的在线状态吗?
不仅是用户登录我的网站并执行某些操作。如果用户打开计算机并打开浏览器。
我希望服务工作人员能够对浏览器启动使用react并定期向我的服务器发送请求,但我找不到这样的事件/方式来做到这一点
最佳答案
根据您的使用案例,Background Sync可能是您需求的答案,但您可能需要文章的 future 部分中提到的periodicsync
:
We’re aiming to ship background sync to a stable version of Chrome in the first half of 2016. But we’re also working on a variant, “periodic background sync”. This will allow you to request a “periodicsync” event restricted by time interval, battery state and network state.
就今天而言,后台同步API,根据IsServiceWorkerReady在 Chrome 稳定版中提供。
Service Worker 还可以对 push
事件使用react - 也许这对您来说就足够了?
关于javascript - Service Worker 的在线状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38556384/