summaryrefslogtreecommitdiff
path: root/src/content/papo.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/papo.js')
-rw-r--r--src/content/papo.js42
1 files changed, 21 insertions, 21 deletions
diff --git a/src/content/papo.js b/src/content/papo.js
index 6935d55..5a68d56 100644
--- a/src/content/papo.js
+++ b/src/content/papo.js
@@ -1,15 +1,22 @@
-// import * as assert from "node:assert/strict";
-
+const f1 = x => x + 1;
+const f2 = x => x - 1;
-// assert.deepEqual({a: 1}, {a: 1});
-// console.log(123);
-// console.log({ navigator });
+const configureStorage = async ({ navigator, err }) => {
+ const persistent = await navigator.storage?.persist?.();
+ if (persistent === undefined) {
+ err(`Persistent storage is not supported.`);
+ return;
+ }
-const f1 = x => x + 1;
-const f2 = x => x - 1;
+ if (!persistent) {
+ err(`Persistent storage is not enabled.`);
+ return;
+ }
+};
-const registerServiceWorker = async ({ serviceWorkerPath, err }) => {
+const registerServiceWorker = async ({ serviceWorkerPath, navigator, err }) => {
+ // FIXME: add explanation for permission before requesting it.
try {
await navigator.serviceWorker?.register(serviceWorkerPath)
} catch (e) {
@@ -17,26 +24,19 @@ const registerServiceWorker = async ({ serviceWorkerPath, err }) => {
}
};
+
+
export const main = async ({
serviceWorkerPath = "./service-worker.js",
- out = console.log,
- err = console.warn,
+ mknavigator = () => navigator,
+ out = console.log,
+ err = console.warn,
} = {}) => {
const env = {
serviceWorkerPath,
out,
err,
+ navigator: mknavigator(),
};
- setTimeout(() => {
- fetch("index.html", {
- headers: {
- "Connection": "upgrade",
- "Content-Type": "application/json",
- },
- });
- }, 1000);
await registerServiceWorker(env);
- // out("main called");
};
-
-// <body onload="setOnline()" ononline="setOnline()" onoffline="setOnline()" >