Skip to content

Client ​

checkPrerequisites() ​

Checks whether the current browser supports the required APIs for push notifications.

It verifies:

  • The Push API (PushManager)
  • The Notifications API (Notification)

Throws ​

TypeDescription
NotificationsNotSupported (498)If the browser does not support push notifications or the Notifications API.

requestNotificationPermission() ​

Requests the user's permission to display notifications.

If the current permission state is default, the browser prompts the user to grant or deny permission.

Returns ​

TypeDescription
Promise<string>Resolves to the updated permission state: "granted", "denied", or "default".

Throws ​

TypeDescription
PermissionDeniedNotifications (499)If permission is denied (either previously or during the request).

getPushSubscription() ​

Retrieves the current push subscription from the registered service worker.

Returns ​

TypeDescription
`Promise<PushSubscriptionnull>`

Throws ​

TypeDescription
ServiceWorkerNotRegistered (497)If no service worker is registered.

subscribePushNotifications(publicVapidKey) ​

Subscribes the user to push notifications using the provided VAPID public key.

Parameters ​

NameTypeRequiredDescription
publicVapidKeyUint8Array | stringyesThe application’s public VAPID key.

Returns ​

TypeDescription
Promise<Object>Resolves to a serializable push subscription object.

unsubscribePushNotifications() ​

Unsubscribes the current push subscription.

Returns ​

TypeDescription
Promise<PushSubscription>Resolves to the unsubscribed PushSubscription object.

addSubscription(subscription, currentSubscription, subscriptionProperty) ​

Adds a push subscription to a subscription container object if it does not already exist.

If the subscription already exists (same endpoint), it is not duplicated.

Parameters ​

NameTypeRequiredDescription
subscriptionObjectyesThe object containing subscriptions.
currentSubscriptionObjectyesThe subscription to add.
subscriptionPropertystringyesThe property name that stores subscriptions.

Returns ​

TypeDescription
ArrayThe updated array of subscriptions.

removeSubscription(subscription, currentSubscription, subscriptionProperty) ​

Removes a push subscription from a subscription container object.

Parameters ​

NameTypeRequiredDescription
subscriptionObjectyesThe object containing subscriptions.
currentSubscriptionObjectyesThe subscription to remove.
subscriptionPropertystringyesThe property name that stores subscriptions.

Returns ​

TypeDescription
ObjectThe updated subscription object.