多个服务工作者处理推送通知

Multiple service workers handling push notifications

我正在构建第 3 方推送通知解决方案以集成到多个属性中。其中一些属性使用其他第 3 方服务以及监听推送事件的服务人员。所以我现在注册了两个服务人员来监听同一个事件,这会造成混乱。

我已经阅读了有关 service worker 作用域的内容,但这似乎并没有解决我的问题。我看不到将推送通知限制在一个范围内的方法。

我是不是没听懂?

否。 两个 Service Worker 无法共享一个范围。

你可以把 Service Worker 想象成高地人。 只能有一个。

您可以注册任意多个,但最后一个注册将始终覆盖其他注册。

根据 Spec

2.2. Service Worker Registration A service worker registration is a tuple of a scope url and a set of service workers, an installing worker, a waiting worker, and an active worker. A user agent may enable many service worker registrations at a single origin so long as the scope url of the service worker registration differs. A service worker registration of an identical scope url when one already exists in the user agent causes the existing service worker registration to be replaced.