Source code

Revision control

Copy as Markdown

Other Tools

<!doctype html>
<meta charset="utf-8" />
<script>
navigator.serviceWorker.register("./click-action-sw.js", {
scope: ".",
});
async function showNotification() {
const { promise, resolve } = Promise.withResolvers();
navigator.serviceWorker.addEventListener(
"message",
ev => resolve(ev.data),
{ once: true }
);
const result = await Notification.requestPermission();
if (result !== "granted") {
throw Error("Permission not granted");
}
const registration = await navigator.serviceWorker.ready;
registration.showNotification("Notification with actions", {
body: "Hello",
actions: [
{
action: "action1",
title: "Action 1",
},
{
action: "action2",
title: "Action 2",
},
],
});
return await promise;
}
</script>