New notification permissions request bar?

Desktop notification and Push Notification are just two different implementations of showing a native notification on the device.

The desktop notification feature was implemented by having the clients subscribe to a messageBus channel and it uses the browser’s Web Notifications API to display a notification on the user’s desktop. When the tab is closed, it kills the messageBus subscription which is why the user would stop getting the native notification. This feature works across all the major desktop browser.

Push Notification on the other hand requires the client to have a service worker registered. When the client enables push notification, it uses the service worker API to create a pushManager subscription which is sent and stored on the server. That subscription object contains a unique (I think) endpoint to a push service and the encryption keys that are used to encrypt the payload.

Browsers that support web push each implement their own push service, which is a system for processing messages and routing them to the correct clients. Push messages destined to become notifications are sent from a server directly to the push service, and contain the information necessary for the push service to send it to the right client and wake up the correct service worker.

Currently one service worker can be registered per domain and that service worker runs in the background even if all the tabs to a site are closed. This is why we’re still able to display native notification even when all the tabs are closed.

When a notification is created in Discourse, we basically add a callback that would sent a payload to the respective browser’s push service which then does its magic on routing the payload to the client. Currently, only Safari lacks support for the Push API which I think may be coming soon since service workers have already been implemented in latest version.

9 Likes