Super simple and small Web Push and Notification service
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 

32 lignes
918 B

  1. // (A) INSTANT WORKER ACTIVATION
  2. self.addEventListener("install", evt => self.skipWaiting());
  3. // (B) CLAIM CONTROL INSTANTLY
  4. self.addEventListener("activate", evt => self.clients.claim());
  5. // (C) LISTEN TO PUSH
  6. self.addEventListener("push", evt => {
  7. const data = evt.data.json();
  8. console.log("got: " + evt.data);
  9. self.registration.showNotification(data.title, {
  10. body: data.body,
  11. icon: data.icon,
  12. image: data.image
  13. });
  14. });
  15. // (D) HANDLE USER INTERACTION
  16. // https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerGlobalScope/notificationclick_event
  17. self.addEventListener( "notificationclick", (event) => {
  18. event.notification.close();
  19. if (event.action === "archive") {
  20. // User selected the Archive action.
  21. //archiveEmail();
  22. } else {
  23. // User selected (e.g., clicked in) the main body of notification.
  24. //clients.openWindow("/inbox");
  25. }
  26. },
  27. false,
  28. );