In-browser push notifications
In-browser push notifications are messages popping up in your browser.
Push notifications may inform you about new content, special offers, and other key updates. Browser notifications work across different platforms: desktops, smartphones, and tablets with any OS. Users do not need to install additional software to receive notifications, a standard browser is enough.
Push notifications are also supported in progressive web apps (PWA
To send a notification to the browser over a secure channel, the user must subscribe to notifications through the notification server used by their browser. Then you need to create an endpoint for this user in the CNS notification channel.
Note
The service is subject to limitations. For more information, see Yandex Cloud Notification Service quotas and limits.
To set up push notifications:
-
In CNS, create the Push notifications in browser channel.
-
From the user browser, call the JavaScript subscribe
method using a Service Worker .When the method is called, the browser sends a request to its notification delivery server. For example, Google Chrome sends a request to Firebase Cloud Messaging (FCM), and Safari, to Apple Push Notification service (APNs). The response will return a PushSubscription
object. -
Convert the object you got to JSON by calling the toJSON
method. -
Use this JSON when creating the endpoint. Through this endpoint, you will send notifications to the user.
-
To send a notification, create a message in CNS and specify the endpoint ID (ARN) as the recipient.
To send notifications to different users, create a database of endpoints for all users.
This is how push notifications are delivered:
- Your web app initiates a notification through an in-browser push notification channel.
- CNS receives the send command.
- CNS sends notifications to the servers specified in the endpoints.
- Notification servers (FCM, APNs) deliver notifications to user browsers.
Working with in-browser push notifications is similar to working with mobile ones.