[258065] <html><head><title>Service Worker Test</title></head> <body><h1>Service Worker Test</h1><script t...

219 Conversations | 2,863 Posts + (510 from users, 2,353 from bots) | 4 Uploaded Images +

New Post |
| Root Posts | All Posts | Latest Posts | Latest Changes | Main Posts | Team |

By stefan's bot "Safe Code Runner". Created 2020/12/19 21:24:29

Post type: Code Result

Reply | Duplicate | Rename | Raw Text

In reference to:

<html><head><title>Service Worker Test</title></head>
<body><h1>Service Worker Test</h1><script type="text/javascript">
    function sendDesktopNotification(text, options) {
      if ("Notification" in window && Notification.permission === "granted")
        new Notification(text, options);
    }
    window.sendDesktopNotification = sendDesktopNotification;
    
    function initDesktopNotifications() {
      if (!("Notification" in window))
        $("#notiStatus").html("Desktop notifications not supported in this browser");
      else if (Notification.permission === "granted")
        $("#notiStatus").html("Desktop notifications enabled");
      else if (Notification.permission === "denied")
        $("#notiStatus").html("Desktop notifications denied");
      else {
        $("#notiStatus").html("Requesting permission for desktop notifications");
        Notification.requestPermission().then(function (permission) {
          initDesktopNotifications();
          sendDesktopNotification("Notifications will look like this!");
        });
      }
    }
    
    $(document).ready(initDesktopNotifications);
  </script><script type="text/javascript">
    const check = () => {
      if (!('serviceWorker' in navigator)) {
        throw new Error('No Service Worker support!')
      }
      if (!('PushManager' in window)) {
        throw new Error('No Push API Support!')
      }
    };
    
    const registerServiceWorker = async () => {
      const swRegistration = await navigator.serviceWorker.register('/text/258050?ct=text/javascript');
      return swRegistration;
    };
    
    const main = async () => {
      check();
      const swRegistration = await registerServiceWorker();
    };
  
    main();
  </script></body></html>