notification_sw
This is a serviceworker that just listens to the notification click
by arcturus
JavaScript
function log_to_client(client, msg) {
return new Promise(function(resolve, reject) {
var msgChannel = new MessageChannel();
msgChannel.port1.onmessage = function(event){
if(event.data.error){
reject(event.data.error);
}else{
resolve(event.data);
}
};
client.postMessage(msg, [msgChannel.port2]);
});
}
function log(msg) {
clients.matchAll().then(function(clients) {
clients.forEach(function(client) {
log_to_client(client, msg);
});
});
}
self.onnotificationclick = function(event) {
log('On notification click: ' + event.notification.tag);
event.notification.close();
};
self.onactivate = function(event) {
log('On activate in SW');
}