Skip to content

Commit 7d4f79f

Browse files
fix push notificaiton in safari
1 parent 0db4456 commit 7d4f79f

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

pkg/app/gen/app-worker.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,21 @@ async function fetchWithCache(request) {
6161
// Push Notifications
6262
// -----------------------------------------------------------------------------
6363
self.addEventListener("push", (event) => {
64-
if (!event.data || !event.data.text()) {
65-
return;
66-
}
64+
event.waitUntil((async () => {
65+
let notification;
6766

68-
const notification = JSON.parse(event.data.text());
69-
if (!notification) {
70-
return;
71-
}
67+
try {
68+
notification = event.data ? event.data.json() : null;
69+
} catch {
70+
notification = null;
71+
}
7272

73-
event.waitUntil(
74-
showNotification(self.registration, notification)
75-
);
73+
if (!notification) {
74+
return;
75+
}
76+
77+
await showNotification(self.registration, notification);
78+
})());
7679
});
7780

7881
self.addEventListener("message", (event) => {

0 commit comments

Comments
 (0)