Test service worker

This commit is contained in:
2023-01-19 11:03:51 +00:00
parent b66c3ccf6a
commit f759505904
8 changed files with 398 additions and 155 deletions

View File

@ -45,10 +45,21 @@ export default function Layout() {
async function goToNotifications(e: any) {
e.stopPropagation();
// request permissions to send notifications
if ("Notification" in window && Notification.permission !== "granted") {
if ("Notification" in window) {
try {
let res = await Notification.requestPermission();
console.debug(res);
if (Notification.permission !== "granted") {
let res = await Notification.requestPermission();
console.debug(res);
}
if (Notification.permission === "granted") {
let worker = await navigator.serviceWorker.ready;
worker.showNotification("Vibration Sample", {
body: "Buzz! Buzz!",
icon: "../images/touch/chrome-touch-icon-192x192.png",
vibrate: [200, 100, 200, 100, 200, 100, 200],
tag: "vibration-sample",
});
}
} catch (e) {
console.error(e);
}