tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

click-action.html (875B)


      1 <!doctype html>
      2 <meta charset="utf-8" />
      3 <script>
      4  navigator.serviceWorker.register("./click-action-sw.js", {
      5    scope: ".",
      6  });
      7 
      8  async function showNotification() {
      9    const { promise, resolve } = Promise.withResolvers();
     10    navigator.serviceWorker.addEventListener(
     11      "message",
     12      ev => resolve(ev.data),
     13      { once: true }
     14    );
     15 
     16    const result = await Notification.requestPermission();
     17    if (result !== "granted") {
     18      throw Error("Permission not granted");
     19    }
     20    const registration = await navigator.serviceWorker.ready;
     21    registration.showNotification("Notification with actions", {
     22      body: "Hello",
     23      actions: [
     24        {
     25          action: "action1",
     26          title: "Action 1",
     27        },
     28        {
     29          action: "action2",
     30          title: "Action 2",
     31        },
     32      ],
     33    });
     34 
     35    return await promise;
     36  }
     37 </script>