Files
devsune/docs/sw.js
2025-08-23 04:27:54 +00:00

17 lines
618 B
JavaScript

const V = "1";
const send = (m) => self.clients.matchAll({ type: "window", includeUncontrolled: true }).then((cs) => cs.forEach((c) => c.postMessage(m)));
self.addEventListener("install", (e) => {
self.skipWaiting();
});
self.addEventListener("activate", (e) => {
e.waitUntil((async () => {
await self.clients.claim();
await send({ type: "SW_ACTIVE", v: V, ts: Date.now() });
})());
});
self.addEventListener("message", (e) => {
if (e.data && e.data.type === "PING") {
(e.source || null)?.postMessage({ type: "PONG", v: V, ts: Date.now() }) || send({ type: "PONG", v: V, ts: Date.now() });
}
});