siyuan/app/src/util/serviceWorker.ts

18 lines
688 B
TypeScript
Raw Normal View History

// https://github.com/siyuan-note/siyuan/pull/8012
2023-04-25 10:57:14 +08:00
export const registerServiceWorker = (scriptURL: string, scope = "/", workerType: WorkerType = "module") => {
2023-04-19 18:56:48 +08:00
if (!("serviceWorker" in navigator) || typeof (navigator.serviceWorker) === "undefined" ||
!("caches" in window) || !("fetch" in window)) {
2023-04-19 18:55:50 +08:00
return;
}
// REF https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration
window.navigator.serviceWorker
.register(scriptURL, {
scope,
type: workerType,
}).then(registration => {
registration.update();
}).catch(e => {
console.debug(`Registration failed with ${e}`);
});
};