mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-21 17:10:12 +01:00
27 lines
752 B
TypeScript
27 lines
752 B
TypeScript
// https://github.com/siyuan-note/siyuan/pull/8012
|
|
export const registerServiceWorker = (
|
|
scriptURL: string,
|
|
options: RegistrationOptions = {
|
|
scope: "/",
|
|
type: "classic",
|
|
updateViaCache: "all",
|
|
},
|
|
) => {
|
|
|
|
if (!("serviceWorker" in window.navigator)
|
|
|| !("caches" in window)
|
|
|| !("fetch" in window)
|
|
|| navigator.serviceWorker == null
|
|
) {
|
|
return;
|
|
}
|
|
|
|
// REF https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration
|
|
window.navigator.serviceWorker
|
|
.register(scriptURL, options)
|
|
.then(registration => {
|
|
registration.update();
|
|
}).catch(e => {
|
|
console.debug(`Registration failed with ${e}`);
|
|
});
|
|
};
|