From c85b4cefe8b8fc67c0b940ddbb16ca72313246bc Mon Sep 17 00:00:00 2001 From: NicolasCantu Date: Fri, 7 Feb 2025 14:34:23 +0100 Subject: [PATCH] [bug] fix worker initialization --- src/services/database.service.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/services/database.service.ts b/src/services/database.service.ts index 2eb491b..c470b90 100755 --- a/src/services/database.service.ts +++ b/src/services/database.service.ts @@ -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) {