Created
July 11, 2018 18:16
-
-
Save vinicius73/117d1992db4c5d2c2d4a0956e6603c70 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
self.addEventListener('notificationclick', function(e) { | |
// Android doesn't automatically close notifications on click | |
e.notification.close(); | |
// Focus tab if open | |
e.waitUntil(clients.matchAll({ | |
type: 'window' | |
}).then(function(clientList) { | |
for (var i = 0; i < clientList.length; ++i) { | |
var client = clientList[i]; | |
if (client.url === '/' && 'focus' in client) { | |
return client.focus(); | |
} | |
} | |
if (clients.openWindow) { | |
return clients.openWindow('/'); | |
} | |
})(); | |
})); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment