Skip to content

Instantly share code, notes, and snippets.

@deanhume
Created August 3, 2015 10:20
Show Gist options
  • Save deanhume/c0d29d40e0c77dfbab8f to your computer and use it in GitHub Desktop.
Save deanhume/c0d29d40e0c77dfbab8f to your computer and use it in GitHub Desktop.
Service Worker Notification Click
self.addEventListener('notificationclick', function(event) {
console.log('On notification click: ', event.notification.tag);
// Android doesn't close the notification when you click on it
// See: http://crbug.com/463146
event.notification.close();
// This looks to see if the current is already open and
// focuses if it is
event.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('https://deanhume.github.io/typography');
}
})
);
});
@rajeevAgilehub
Copy link

clients.matchAll I am getting lint error, it says clients is not defined

@deanhume
Copy link
Author

deanhume commented Aug 6, 2019

What browser are you using?

@rajeevAgilehub
Copy link

What browser are you using?

i m using Chrome,
i m developing in VS code Editor. I have installed Lint for error checking,
Lint is highlighting this as error, it is expecting it to be defined.
image

@way2datta
Copy link

@rajeevAgilehub Navigate to eslint config file and explore "env" section for more details.

"env": {
"clients": true,
"self": true.

Or otherwise, disable linting for this file only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment