self.addEventListener('push', (e) => { console.log(e.data); const received_data = e.data.json(); console.log(received_data); if (received_data.requireInteraction) { self.registration.showNotification(received_data.title, { body: received_data.body, vibrate: [200, 100, 200], requireInteraction: received_data.requireInteraction, actions: [ { title: "I've collected my laundry!", action: "collect", } ], data: {timerId: received_data.timerId}, }); } else { self.registration.showNotification(received_data.title, { body: received_data.body, vibrate: [200, 100, 200], }); } }); self.addEventListener("notificationclick", (event) => { if (event.action === "collect") { console.log(event); timerId = event.notification.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/"); event.notification.close(); } else { clients.openWindow("/timer/"); event.notification.close(); } });