I'm trying push notifications using service workers. use my own server to send notifications and eventSource is used to establish the connection. after i open the webpage service worker is running perfectly. but it stops after few seconds. what i want is to run service worker without getting stopped. i want it to run until the browser is opened. can anyone recommend a way to do that. ?
this is my ServiceWorker JS
/**
*
*/
'use strict';
var eventSource2 = new EventSource("Servlet");
console.log('Started', eventSource2);
eventSource2.addEventListener('install', function(event) {
eventSource2.skipWaiting();
console.log('Installed', event);
});
eventSource2.addEventListener('push',function(event) {
console.log(event.data);
var title = event.data;
self.registration.showNotification(title,{
'body' : event.data,
'icon' : 'http://icons.iconarchive.com/icons/designbolts/free-multimedia/1024/iMac-icon.png',
'tag' : 'click',
});
console.log("data from down", event.data);
});
eventSource2.addEventListener('activate', function(event){
console.log('Activated', event);
});
eventSource2.addEventListener('fetch', function(event) {
console.log('Push message', event);
});