Skip to content

Commit

Permalink
clarify origin of registration (mdn#22912)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael[tm] Smith <[email protected]>
  • Loading branch information
SephReed and sideshowbarker committed Dec 13, 2022
1 parent ac9ddbf commit b051dcb
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ Push is more complicated than notifications — we need to subscribe to a server
The technology is still at a very early stage — some working examples use the Google Cloud Messaging platform, but are being rewritten to support [VAPID](https://blog.mozilla.org/services/2016/08/23/sending-vapid-identified-webpush-notifications-via-mozillas-push-service/) (Voluntary Application Identification), which offers an extra layer of security for your app.
You can examine the [Service Workers Cookbook examples](https://github.com/mdn/serviceworker-cookbook/tree/master/push-payload), try to set up a push messaging server using [Firebase](https://firebase.google.com/), or build your own server (using Node.js for example).

As mentioned before, to be able to receive push messages, you have to have a service worker, the basics of which are already explained in the [Making PWAs work offline with Service workers](/en-US/docs/Web/Progressive_web_apps/Offline_Service_workers) article. Inside the service worker, a push service subscription mechanism is created.
As mentioned before, to be able to receive push messages, you have to have a service worker, the basics of which are already explained in the [Making PWAs work offline with Service workers](/en-US/docs/Web/Progressive_web_apps/Offline_Service_workers) article. Inside the service worker, a push-service subscription mechanism is created by calling the [`getSubscription()`](/en-US/docs/Web/API/PushManager/getSubscription/) method of the [`PushManager`](/en-US/docs/Web/API/PushManager) interface.

```js
registration.pushManager.getSubscription().then( /* ... */ );
navigator.serviceWorker.register('service-worker.js')
.then((registration) => {
return registration.pushManager.getSubscription().then( /* ... */ );
```
Once the user is subscribed, they can receive push notifications from the server.
Expand Down

0 comments on commit b051dcb

Please sign in to comment.