open_window.js (584B)
1 navigator.serviceWorker.register("./service-worker.js", { 2 scope: ".", 3 }); 4 5 let params = new URL(location.href).searchParams; 6 /** @type {NotificationOptions} */ 7 let options = { 8 body: "Hello", 9 }; 10 if (params.has("action")) { 11 options.actions = [{ action: params.get("action"), title: "action" }]; 12 } 13 14 function showNotification() { 15 Notification.requestPermission(function (result) { 16 if (result === "granted") { 17 navigator.serviceWorker.ready.then(function (registration) { 18 registration.showNotification("Open Window Notification", options); 19 }); 20 } 21 }); 22 }