serviceworker.js 644 B

12345678910111213
  1. self.addEventListener('push', function (event) {
  2. if (event.data == null) return;
  3. var json = event.data.json();
  4. const options = { body: json.body, icon: '/favicon-303x303.png', data: { url: json.url } };
  5. if (json.icon) { options.icon = '/images/notify/icons128-' + json.icon + '.png'; }
  6. event.waitUntil(self.registration.showNotification(json.title, options));
  7. });
  8. self.addEventListener('notificationclick', function (event) {
  9. event.notification.close();
  10. if ((event.notification.data.url != null) && (event.notification.data.url != '')) { event.waitUntil(self.clients.openWindow(event.notification.data.url)); }
  11. });