self.addEventListener('push', (e) => { console.log(e.data); const data = e.data.json(); console.log(data); if (data.requireInteraction) { self.registration.showNotification(data.title, { body: data.body, vibrate: [200, 100, 200], requireInteraction: data.requireInteraction, actions: [ { title: "I've collected my laundry!", action: "collect", } ], data: {timerId: data.timerId}, }); } else { self.registration.showNotification(data.title, { body: data.body, vibrate: [200, 100, 200], }); } }); self.addEventListener("notificationclick", (event) => { if (event.action === "collect") { timerId = event.data.timerId; console.log("finishing timer! w/ id "+timerId.toString()); fetch(`${API_URL}/finish`, { method: "POST", credentials: "include", headers: { "Content-Type": "application/json" }, body: JSON.stringify({id: timerId}), }); clients.openWindow("/timer/"); } else { clients.openWindow("/timer/"); } });