Chrome : Version 121.0.6167.160 (Official Build) (64-bit)
Edge: Version 121.0.2277.106 (Official build) (64-bit)
Problem
We have a published a Chrome web addon (on Chrome Store) and we wanted to send Push notifications to users having installed on their browser.
So, to add this new feature:
On BO, I used the web-push library in our hosted NodeJS server (Express + MongoDB) to be able to subscribe all our users' addon instances (through FCM Vapid keys). The mongoDB persists all subscriptions JSON objects ({endpoint, keys})
On FO, i.e. on our web addon, we are relying on a registered ServiceWorker (which will act as a proxy between Push server and web addon) listening to "push" events from server.
In a normal scenario, all works like a charm and the notifications are gracefully poping on desktop.
Now, when I decide to deactivate my web addon (i.e. from Extensions manage page in Dev Mode), and my ServiceWorker remains registered, and I ignit a notification Push from server, I encounter errors on both sides :
on BO, this WebPushError saying that the 'push subscription has unsubscribed or expired
WebPushError: Received unexpected response code
at IncomingMessage.<anonymous> (/app/node_modules/web-push/src/web-push-lib.js:378:20)
at IncomingMessage.emit (node:events:530:35)
at endReadableNT (node:internal/streams/readable:1696:12)
at processTicksAndRejections (node:internal/process/task_queues:82:21) {
statusCode: 410,
headers: {
'content-type': 'text/plain; charset=utf-8',
'x-content-type-options': 'nosniff',
'x-frame-options': 'SAMEORIGIN',
'x-xss-protection': '0',
date: 'Thu, 08 Feb 2024 16:37:48 GMT',
'content-length': '47',
'alt-svc': 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000'
},
body: 'push subscription has unsubscribed or expired.\n',
endpoint: 'https://fcm.googleapis.com/fcm/send/f7MxvCg_.....
on FO side, I get this error on "Application - push messaging" menu in devtools, saying Unsubscribed due to error - DELIVERY_PERMISSION_DENIED
So, from the push server point of view I understand the problem because the subscription has been unsubscribed by the PushManager associated with the ServiceWorker.
But I don't understand why this unsubscription happens ??
Is it because the ServiceWorker can't dispatch the push message to the deactivated addon, without a subscription's endpoint, and this causes the unsubscription due to this error ??
Expected
To have the push dispatched and have the notification, as usual when the web addon is activated.
Features Used
[x] VAPID Support
[x] Sending with Payload
Example / Reproduce Case
ServiceWorker.js (addon)
// Event listener for push event.
self.addEventListener("push", (event) => {
console.debug("Push event", event);
const { title = "Test title", body = "Test message." } = event.data?.json();
const icon = "icons/icon_1024x1024.png";
event.waitUntil(
self?.registration?.showNotification(title, {
body,
icon,
}) // Show a notification with title and message
); // Keep the service worker alive until the notification is created
});
self.addEventListener("pushsubscriptionchange", (event) => {
console.debug(event);
});
NOTE: Please test in a least two browsers (i.e. Chrome and Firefox). This helps with diagnosing problems quicker.
Setup
Operating System: Linux (Ubuntu 22.04 LTS) Node Version: 21.5.0 web-push Version: ^3.6.6
Chrome : Version 121.0.6167.160 (Official Build) (64-bit) Edge: Version 121.0.2277.106 (Official build) (64-bit)
Problem
We have a published a Chrome web addon (on Chrome Store) and we wanted to send Push notifications to users having installed on their browser.
So, to add this new feature:
On BO, I used the web-push library in our hosted NodeJS server (Express + MongoDB) to be able to subscribe all our users' addon instances (through FCM Vapid keys). The mongoDB persists all subscriptions JSON objects ({endpoint, keys})
On FO, i.e. on our web addon, we are relying on a registered ServiceWorker (which will act as a proxy between Push server and web addon) listening to "push" events from server.
In a normal scenario, all works like a charm and the notifications are gracefully poping on desktop.
Now, when I decide to deactivate my web addon (i.e. from Extensions manage page in Dev Mode), and my ServiceWorker remains registered, and I ignit a notification Push from server, I encounter errors on both sides :
WebPushError
saying that the'push subscription has unsubscribed or expired
Unsubscribed due to error - DELIVERY_PERMISSION_DENIED
So, from the push server point of view I understand the problem because the subscription has been unsubscribed by the PushManager associated with the ServiceWorker.
But I don't understand why this unsubscription happens ?? Is it because the ServiceWorker can't dispatch the push message to the deactivated addon, without a subscription's endpoint, and this causes the unsubscription due to this error ??
Expected
To have the push dispatched and have the notification, as usual when the web addon is activated.
Features Used
Example / Reproduce Case
subscriptionRouter.js (server)
notificationRouter.js (server)
Other
I have tried to debug using either ServiceWorker registration
onerror
orpushsubscriptionchange
events, but in vain...