From ed5e175a806f45469a6e5504ba0d3f5246997fad Mon Sep 17 00:00:00 2001 From: Kit La Touche Date: Wed, 30 Jul 2025 23:08:40 -0400 Subject: Test receiving push events when backgrounded And thus also displaying notifications. --- ui/service-worker.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'ui/service-worker.js') diff --git a/ui/service-worker.js b/ui/service-worker.js index 319b251..a88c5a2 100644 --- a/ui/service-worker.js +++ b/ui/service-worker.js @@ -54,10 +54,12 @@ self.addEventListener('fetch', (event) => { }); self.addEventListener('push', (event) => { - const payload = event.data?.text() ?? "no payload"; + // If the data isn't json, this dies hard: + const payload = event.data?.json() ?? null; event.waitUntil( - self.registration.showNotification("ServiceWorker Cookbook", { - body: payload, - }), + // How do we control the action you get when you click the notification? + self.registration.showNotification(payload.title, { + body: payload.body + }) ); }); -- cgit v1.2.3