self.addEventListener('install', function(event) {
  // Automatically take over the previous worker.
  event.waitUntil(self.skipWaiting());
});

self.addEventListener('push', function(event) {
  console.debug('Service worker: push', event);

  var title = 'Yay a message.';
  var body = 'We have received a push message.';
  var icon = '/images/icon-192x192.png';
  var tag = 'simple-push-demo-notification-tag';

  event.waitUntil(
    self.registration.showNotification(title, {
      body: body,
      icon: icon,
      tag: tag
    })
  );
});

@@ -235,16 +235,280 @@
 vent);%0A%0A
+  event.waitUntil(self.registration.pushManager.getSubscription().then(function(subscription) %7B%0A    if (!subscription) %7B%0A      return;%0A    %7D%0A    return sendRpc('CM_Component_Example.time', %7BsubscriptionId: subscription.subscriptionId%7D).then(function(result) %7B%0A    
   var ti
@@ -523,28 +523,43 @@
 ay a message
-.';%0A
+ - ' + result;%0A    
   var body =
@@ -595,16 +595,20 @@
 sage.';%0A
+    
   var ic
@@ -640,16 +640,20 @@
 2.png';%0A
+    
   var ta
@@ -700,25 +700,8 @@
 %0A%0A  
-event.waitUntil(%0A
     
@@ -744,16 +744,18 @@
 itle, %7B%0A
+  
       bo
@@ -770,16 +770,18 @@
 ,%0A      
+  
 icon: ic
@@ -790,16 +790,18 @@
 ,%0A      
+  
 tag: tag
@@ -805,20 +805,1109 @@
 tag%0A
+  
     %7D)
+;
 %0A  
+  %7D);%0A  %7D));%0A%7D);%0A%0Aself.addEventListener('notificationclick', function(event) %7B%0A  event.notification.close();%0A  event.waitUntil(openWindow('/now'));%0A%7D);%0A%0A/**%0A * @param %7BString%7D method%0A * @param %7BObject%7D params%0A * @returns %7BPromise%7D%0A */%0Afunction sendRpc(method, params) %7B%0A  var rpcData = JSON.stringify(%7Bmethod: method, params: params%7D);%0A  return fetch('/rpc/null', %7Bmethod: 'POST', body: rpcData%7D).then(function(response) %7B%0A    return response.json().then(function(result) %7B%0A      if (result%5B'error'%5D) %7B%0A        throw new Error('RPC call failed: ' + result%5B'error'%5D);%0A      %7D%0A      return result%5B'success'%5D%5B'result'%5D;%0A    %7D);%0A  %7D);%0A%7D%0A%0A/**%0A * @param %7BString%7D path%0A * @returns %7BPromise%7D%0A */%0Afunction openWindow(path) %7B%0A  return clients.matchAll(%7Btype: 'window'%7D).then(function(clientList) %7B%0A    for (var i = 0; i %3C clientList.length; i++) %7B%0A      var client = clientList%5Bi%5D;%0A      var url = new URL(client.url);%0A      if (url.pathname === path && 'focus' in client) %7B%0A        return client.focus();%0A      %7D%0A    %7D%0A    if (clients.openWindow) %7B%0A      return clients.openWindow(path);%0A    %7D%0A  %7D
 );%0A%7D
-);
 %0A

Extend SW functionality with RPC call and window opening