Push notifications (beta)

Leanplum now supports web push notifications (currently in beta). This is the only messaging channel we currently support via our Javascript SDK.

Supported browsers

Web push is supported in the following browsers:

BrowserMinimum supported version
SafariNot supported
EdgeNot supported
Samsung Internet BrowserNot supported

Note Due to an iOS limitation, we do not support web push on any mobile browsers on iOS, including Safari and Chrome.

Enabling Web Push

To enable web push, you first need to include the Service Worker file in your root directory, and register it in your code so the browser can utilize it to run the necessary background processes. Our SDK has a method that handles the Service Worker registration for you; you just need to pass the filepath to registerForWebPush. The Leanplum SDK also includes a fully working sw.min.js file that you can use as your Worker.

For security reasons, service workers only run over HTTPS.

Before registering the device for push, we recommend checking that the device and browser support web push, and that the device has not already been registered. You can do this with isWebPushSupported and isWebPushSubscribed, both of which return a boolean.

import leanplum from `leanplum-javascript-sdk`

let isSubscribedToWebPush = false;
let isWebPushSupported = leanplum.isWebPushSupported();
  leanplum.isWebPushSubscribed().then(subscriptionStatus => {
      isSubscribedToWebPush = subscriptionStatus;

Then, you can register the device for push:

if(isWebPushSupported && !isSubscribedToWebPush){
  // Register by passing SW filepath (which is in our root directory).
  leanplum.registerForWebPush('/sw.min.js', subscriptionStatus => {
    console.log('Subscription status: %s', subscriptionStatus);

After registering successfully, the device will be able to receive web push notifications, and the browser will handle displaying the messages themselves. The notification includes the title, message, icon, and push image (beta). However, Firefox and Opera do not support push images on any platform.

You can customize how your notification is displayed via the showNotification function.

  1. Title is required. If the push notification does not include a title, the showNotification function will drop the push on the SDK side.
  2. We only support Open URL as the action. The SDK will ignore other actions.

For more information on sending a web push from Leanplum, see how to Send a Web Push Notification.

Web push methods

The following SDK methods are available for web push.

isWebPushSupportedDetermines if web push is supported by the user's browser. Returns a boolean of True or False.
isWebPushSubscribedDetermines if the user is subscribed for web push. Returns a promise that resolves if True and rejects if False.
registerForWebPushRegisters the user's browser for web push. Returns a promise that resolves on success, and rejects otherwise.
unregisterFromWebPushUnregisters the user's browser for web push. Returns a promise that resolves on success, and rejects otherwise.


We have provided a sample implementation in an angularJS app in our SDK package, where a toggle registers and unregisters a user for web push. Specifically, see our implementation for toggle initialization and toggle switching.