🐛 Fix the request of PWA files without Authentication Header (#11586)

This commit is contained in:
Yingyi / 颖逸 2024-05-30 22:30:50 +08:00 committed by GitHub
parent 062275f69a
commit 060a1c500e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 23 additions and 13 deletions

View file

@ -1,17 +1,27 @@
// https://github.com/siyuan-note/siyuan/pull/8012
export const registerServiceWorker = (scriptURL: string, scope = "/", workerType: WorkerType = "module") => {
if (!("serviceWorker" in navigator) || typeof (navigator.serviceWorker) === "undefined" ||
!("caches" in window) || !("fetch" in window)) {
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, {
scope,
type: workerType,
}).then(registration => {
registration.update();
}).catch(e => {
console.debug(`Registration failed with ${e}`);
});
.register(scriptURL, options)
.then(registration => {
registration.update();
}).catch(e => {
console.debug(`Registration failed with ${e}`);
});
};