Skip to content

Instantly share code, notes, and snippets.

@elidupuis

elidupuis/README.md

Last active Oct 23, 2020
Embed
What would you like to do?
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