|
|
@ -4,7 +4,19 @@ importScripts( |
|
|
|
"https://storage.googleapis.com/workbox-cdn/releases/6.4.1/workbox-sw.js", |
|
|
|
); |
|
|
|
|
|
|
|
self.addEventListener("install", (event) => { |
|
|
|
console.log("Service worker scripts importing...", event); |
|
|
|
importScripts( |
|
|
|
"safari-notifications.js", |
|
|
|
"nacl.js", |
|
|
|
"noble-curves.js", |
|
|
|
"noble-hashes.js", |
|
|
|
); |
|
|
|
console.log("Service worker scripts imported."); |
|
|
|
}); |
|
|
|
|
|
|
|
function logDbOrConsole(self, message, arg1, arg2) { |
|
|
|
console.log(`${new Date().toISOString()} ${message}`, arg1, arg2); |
|
|
|
let fullMessage = `${new Date().toISOString()} ${message}`; |
|
|
|
if (arg1) { |
|
|
|
fullMessage += `: ${JSON.stringify(arg1)}`; |
|
|
@ -12,24 +24,15 @@ function logDbOrConsole(self, message, arg1, arg2) { |
|
|
|
if (arg2) { |
|
|
|
fullMessage += ` -- ${JSON.stringify(arg2)}`; |
|
|
|
} |
|
|
|
const logged = self.logMessage(fullMessage); |
|
|
|
if (!logged) { |
|
|
|
console.log(`$new Date().toISOString()} ${message}`, arg1, arg2); |
|
|
|
} |
|
|
|
// const logged =
|
|
|
|
self.logMessage(fullMessage); |
|
|
|
// if (logged || !logged) {
|
|
|
|
// console.log(`${new Date().toISOString()} ${message}`, arg1, arg2);
|
|
|
|
// }
|
|
|
|
} |
|
|
|
|
|
|
|
self.addEventListener("install", (event) => { |
|
|
|
logDbOrConsole(self, "Installing service worker:", event); |
|
|
|
importScripts( |
|
|
|
"safari-notifications.js", |
|
|
|
"nacl.js", |
|
|
|
"noble-curves.js", |
|
|
|
"noble-hashes.js", |
|
|
|
); |
|
|
|
}); |
|
|
|
|
|
|
|
self.addEventListener("push", function (event) { |
|
|
|
logDbOrConsole(self, "Received push event:", event); |
|
|
|
logDbOrConsole(this, "Received push event:", event); |
|
|
|
event.waitUntil( |
|
|
|
(async () => { |
|
|
|
try { |
|
|
@ -58,28 +61,28 @@ self.addEventListener("push", function (event) { |
|
|
|
}); |
|
|
|
|
|
|
|
self.addEventListener("message", (event) => { |
|
|
|
logDbOrConsole(self, "Service worker message:", event); |
|
|
|
logDbOrConsole(this, "Service worker message:", event); |
|
|
|
if (event.data && event.data.type === "SEND_LOCAL_DATA") { |
|
|
|
self.secret = event.data.data; |
|
|
|
event.ports[0].postMessage({ success: true }); |
|
|
|
} |
|
|
|
logDbOrConsole(self, "Service worker posted message."); |
|
|
|
logDbOrConsole(this, "Service worker posted message."); |
|
|
|
}); |
|
|
|
|
|
|
|
self.addEventListener("activate", (event) => { |
|
|
|
logDbOrConsole(self, "Service worker activating...", event); |
|
|
|
logDbOrConsole(this, "Service worker activating...", event); |
|
|
|
// see https://developer.mozilla.org/en-US/docs/Web/API/Clients/claim
|
|
|
|
// and https://web.dev/articles/service-worker-lifecycle#clientsclaim
|
|
|
|
event.waitUntil(clients.claim()); |
|
|
|
logDbOrConsole(self, "Service worker activated."); |
|
|
|
logDbOrConsole(this, "Service worker activated."); |
|
|
|
}); |
|
|
|
|
|
|
|
self.addEventListener("fetch", (event) => { |
|
|
|
logDbOrConsole(self, "Got fetch event:", event); |
|
|
|
logDbOrConsole(this, "Got fetch event:", event); |
|
|
|
}); |
|
|
|
|
|
|
|
self.addEventListener("error", (event) => { |
|
|
|
logDbOrConsole(self, "Error in Service Worker:", event); |
|
|
|
logDbOrConsole(this, "Error in Service Worker:", event); |
|
|
|
console.error("Full Error:", event); |
|
|
|
console.error("Message:", event.message); |
|
|
|
console.error("File:", event.filename); |
|
|
|