dist/sw/sw.js
function pushListener(event) {
    var jsonString = event.data && event.data.text() ? event.data.text() : null;

    if (!jsonString) {
      console.log('Leanplum: Push received without payload, skipping display.');
      return;
    }

    // noinspection JSCheckFunctionSignatures
    var options = JSON.parse(jsonString);

    /** @namespace options.title The title of the push notification. **/
    /** @namespace options.tag The id of the push notification **/
    if (!options || !options.title || !options.tag) {
      console.log('Leanplum: No options, title or tag/id received, skipping ' + 'display.');
      return;
    }

    // Extract open action url. We only support open url action for now.
    /** @namespace options.data.openAction The openAction of the push notification. **/
    if (options.data && options.data.openAction && options.data.openAction.hasOwnProperty(ACTION_NAME_KEY) && options.data.openAction[ACTION_NAME_KEY] === OPEN_URL_ACTION && options.data.openAction.hasOwnProperty(ARG_URL)) {
      openActions[options.tag] = options.data.openAction[ARG_URL];
    }

    // Extract title and delete from options.
    var title = options.title;
    Reflect.deleteProperty(options, 'title');
    /** @namespace self.registration **/
    /** @namespace self.registration.showNotification **/
    event.waitUntil(self.registration.showNotification(title, options));
  }
function pushListener(event) {
    var jsonString = event.data && event.data.text() ? event.data.text() : null;

    if (!jsonString) {
      console.log('Leanplum: Push received without payload, skipping display.');
      return;
    }

    // noinspection JSCheckFunctionSignatures
    var options = JSON.parse(jsonString);

    /** @namespace options.title The title of the push notification. **/
    /** @namespace options.tag The id of the push notification **/
    if (!options || !options.title || !options.tag) {
      console.log('Leanplum: No options, title or tag/id received, skipping ' + 'display.');
      return;
    }

    // Extract open action url. We only support open url action for now.
    /** @namespace options.data.openAction The openAction of the push notification. **/
    if (options.data && options.data.openAction && options.data.openAction.hasOwnProperty(ACTION_NAME_KEY) && options.data.openAction[ACTION_NAME_KEY] === OPEN_URL_ACTION && options.data.openAction.hasOwnProperty(ARG_URL)) {
      openActions[options.tag] = options.data.openAction[ARG_URL];
    }

    // Extract title and delete from options.
    var title = options.title;
    Reflect.deleteProperty(options, 'title');
    /** @namespace self.registration **/
    /** @namespace self.registration.showNotification **/
    event.waitUntil(self.registration.showNotification(title, options));
  }
function pushListener ( event ) { var jsonString = event . data && event . data . text ( ) ? event . data . text ( ) : null ; if ( ! jsonString ) { console . log ( 'Leanplum: Push received without payload, skipping display.' ) ; return ; } // noinspection JSCheckFunctionSignatures var options = JSON . parse ( jsonString ) ; /** @namespace options.title The title of the push notification. **/ /** @namespace options.tag The id of the push notification **/ if ( ! options || ! options . title || ! options . tag ) { console . log ( 'Leanplum: No options, title or tag/id received, skipping ' + 'display.' ) ; return ; } // Extract open action url. We only support open url action for now. /** @namespace options.data.openAction The openAction of the push notification. **/ if ( options . data && options . data . openAction && options . data . openAction . hasOwnProperty ( ACTION_NAME_KEY ) && options . data . openAction [ ACTION_NAME_KEY ] === OPEN_URL_ACTION && options . data . openAction . hasOwnProperty ( ARG_URL ) ) { openActions [ options . tag ] = options . data . openAction [ ARG_URL ] ; } // Extract title and delete from options. var title = options . title ; Reflect . deleteProperty ( options , 'title' ) ; /** @namespace self.registration **/ /** @namespace self.registration.showNotification **/ event . waitUntil ( self . registration . showNotification ( title , options ) ) ; }
Triggered on push message received.
@param {object} event The push payload that the browser received.
Triggered on push message received .