[bug] fix worker initialization

This commit is contained in:
NicolasCantu 2025-02-07 14:34:23 +01:00
parent 1349ef4994
commit c85b4cefe8

View File

@ -121,14 +121,15 @@ class Database {
this.serviceWorkerRegistration = registration
await this.checkForUpdates();
// Set up the message channels
this.messageChannel.port1.onmessage = this.handleAddObjectResponse;
this.messageChannelForGet.port1.onmessage = this.handleGetObjectResponse;
registration.active?.postMessage(
const messageChannel = new MessageChannel();
messageChannel.port1.onmessage = this.handleAddObjectResponse;
const readyRegistration = await navigator.serviceWorker.ready;
readyRegistration.active?.postMessage(
{
type: 'START',
},
[this.messageChannel.port2],
[messageChannel.port2],
);
// Optionally, initialize service worker with some data
} catch (error) {