"This site has been updated in the background" issue with Chrome push notifications in Blazor WASM

Viewed 152

I'm using Chrome, I've got everything set up according to many stack overflow posts and google developer docs, however the issue is that the 'push' event doesn't seem to be getting called. Here is my 'push' event...

    self.addEventListener('push', event => {
    const payload = event.data.json();
    event.waitUntil(
        self.registration.showNotification('My Website', {
            body: payload.message,
            icon: 'img/icon-512.png',
            vibrate: [100, 50, 100],
            data: { url: payload.url }
        })
    );
});

On a published website the push notification gives me the error 'This site has been updated in the background'. However in local host it accepts the notification sent from my server and displays that, but not the local notification in 'push'. Debugging the push event it seems like its not called.

1 Answers

So I found the answer, when you create a Blazor WASM app as a PWA it adds a service-worker.js file and if you expand that file in the inspector it also has a service-worker.published.js file. This file needs to be updated with whatever you want in the service-worker.js file.

Related