@@ -68,7 +68,7 @@ export async function subscribeUserToPush(serverKey: string) {
6868 log ( 'WebPush' , 'Registering service worker' ) ;
6969
7070 const sw = await getServiceWorker ( ) ;
71- if ( ! sw ) {
71+ if ( ! sw || ! sw . pushManager ) {
7272 log ( 'WebPush' , 'No service worker present' ) ;
7373 return ;
7474 }
@@ -153,12 +153,6 @@ export function useWebPush() {
153153 return ;
154154 }
155155
156- // Do we have a service worker running?
157- if ( ! getServiceWorker ( ) ) {
158- setStatus ( 'not-supported' ) ;
159- return ;
160- }
161-
162156 // Did the user deny us permissions? If yes,
163157 // we cannot ask again :/
164158 if ( Notification . permission === 'denied' ) {
@@ -180,6 +174,12 @@ export function useWebPush() {
180174 return ;
181175 }
182176
177+ // Older Safari is not spec compliant and does not have .pushManager:
178+ if ( ! sw . pushManager ) {
179+ setStatus ( 'not-supported' ) ;
180+ return ;
181+ }
182+
183183 const subscription = await sw . pushManager . getSubscription ( ) ;
184184 if ( ! subscription ) {
185185 setStatus ( 'not-subscribed' ) ;
@@ -258,7 +258,7 @@ export function useWebPush() {
258258 try {
259259 const sw = await getServiceWorker ( ) ;
260260 if ( sw ) {
261- const subscription = await sw . pushManager . getSubscription ( ) ;
261+ const subscription = await sw . pushManager ? .getSubscription ( ) ;
262262 await subscription ?. unsubscribe ( ) ;
263263 }
264264
0 commit comments