Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Fix the request of PWA files without `Authentication` Header (#11586)

Yingyi / 颖逸060a1c500e37
diff --git a/app/src/assets/template/desktop/index.tpl b/app/src/assets/template/desktop/index.tpl
index cbbe239bc1..3a7824d87f 100644
--- a/app/src/assets/template/desktop/index.tpl
+++ b/app/src/assets/template/desktop/index.tpl
@@ -6,7 +6,7 @@
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, viewport-fit=cover, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
- <link rel="manifest" href="/manifest.webmanifest">
+ <link rel="manifest" href="/manifest.webmanifest" crossorigin="use-credentials">
<link rel="apple-touch-icon" href="../../icon.png">
<style id="editorAttr" type="text/css"></style>
</head>
diff --git a/app/src/assets/template/mobile/index.tpl b/app/src/assets/template/mobile/index.tpl
index 830cbe1073..40439b22aa 100644
--- a/app/src/assets/template/mobile/index.tpl
+++ b/app/src/assets/template/mobile/index.tpl
@@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, height=device-height, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, viewport-fit=cover">
- <link rel="manifest" href="/manifest.webmanifest">
+ <link rel="manifest" href="/manifest.webmanifest" crossorigin="use-credentials">
</head>
<body class="fn__flex-column">
<div id="loading" class="b3-dialog b3-dialog--open">
diff --git a/app/src/util/serviceWorker.ts b/app/src/util/serviceWorker.ts
index e437249df4..d7e3916bd1 100644
--- a/app/src/util/serviceWorker.ts
+++ b/app/src/util/serviceWorker.ts
@@ -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}`);
+ });
};