mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-21 17:10:12 +01:00
🐛 Fix the request of PWA files without Authentication Header (#11586)
This commit is contained in:
parent
062275f69a
commit
060a1c500e
3 changed files with 23 additions and 13 deletions
|
|
@ -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}`);
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue