Skip to content

Instantly share code, notes, and snippets.

@elidupuis
Last active September 18, 2023 17:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elidupuis/12282bc8793f74b9b54876771f0c3bb5 to your computer and use it in GitHub Desktop.
Save elidupuis/12282bc8793f74b9b54876771f0c3bb5 to your computer and use it in GitHub Desktop.
Service worker `getNotifications()` test snippet

tl;dr

The service worker registration method getNotifications() never fulfills (neither resolves nor rejects) in MS Edge on macOS if notification permissions have been granted by the user.

Details

The bug appears to only exist if Notification.permission === 'granted', meaning that the user has granted permissions for notifications at the browser level. This bug has been experienced in Microsoft Edge on macOS, versions 86, 87 (beta), and 88 (dev). It does not appear to be present on Windows.

You can easily test this on any PWA application. First, you'll need to manually toggle notification permissions (granted is the only state where the bug exists) and then simply run the test snippet into your browser console. Test your own PWA or a well-known one like app.starbucks.com.

I've started a discussion on the MS Edge forum regarding this issue.

console.log(navigator.userAgent)
navigator.serviceWorker.ready
.then(reg => {
console.log('> SW READY')
console.log('Permission state:', Notification.permission);
return reg.getNotifications();
}).then(notifications => {
console.log('Notifications:', notifications);
})
.catch(e => console.log('> ERROR', e))
.finally(() => console.log('> COMPLETE'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment