Closed ottopic closed 6 months ago
I have tried to add Safari desktop compatibility but I same problem of randomly popup of notification acceptance. Can you help me?
navigator.serviceWorker .getRegistration('./ngsw-worker.js') .then((registration) => { requestPermission(registration); }); async function requestPermission( registration: ServiceWorkerRegistration | undefined, ) { return new Promise((resolve) => { const timeoutId = setInterval(() => { if (Notification.permission === 'granted') { handleComplete(Notification.permission); } }, 3000); const handleComplete = (permission: NotificationPermission) => { clearInterval(timeoutId); resolve(permission); if (permission === 'granted') { getToken(messaging, { vapidKey: '...', serviceWorkerRegistration: registration, }) .then((currentToken) => { if (currentToken) { console.log(currentToken); } else { console.log( 'No registration token available. Request permission to generate one.', ); } }) .catch((err) => { console.log('Error token ', err); }); } }; Notification.requestPermission(handleComplete)?.then?.(handleComplete); }); }
I have tried to add Safari desktop compatibility but I same problem of randomly popup of notification acceptance. Can you help me?