Advertisement
Guest User

service-worker.js

a guest
Mar 23rd, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. self.addEventListener('push', function(event) {
  2.   //console.log('Received a push message', event);
  3.  
  4.   var title = 'Message title';
  5.   var body = 'We have received a push message.';  
  6.  
  7. if (typeof(self.data) !== 'undefined') {
  8.     if (typeof(self.data.message) !== 'undefined') {
  9.         title = "My custom message!";
  10.         body=self.data.message;
  11.  
  12.     }
  13. }
  14.  
  15.  
  16.   var icon = '/img/icon-192x192.png';  
  17.   var tag = 'simple-push-demo-notification-tag';
  18.  
  19.   event.waitUntil(  
  20.     self.registration.showNotification(title, {  
  21.       body: body,  
  22.       icon: icon,  
  23.       tag: tag  
  24.     })  
  25.   );  
  26. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement