Skip to content

Instantly share code, notes, and snippets.

@vinicius73
Created July 11, 2018 18:16
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 vinicius73/117d1992db4c5d2c2d4a0956e6603c70 to your computer and use it in GitHub Desktop.
Save vinicius73/117d1992db4c5d2c2d4a0956e6603c70 to your computer and use it in GitHub Desktop.
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