Estoy usando este código para enviar notificaciones a mi usuario:
Notification.requestPermission(function(result) { if (result === 'granted') { navigator.serviceWorker.ready .then(function(registration) { registration .showNotification('new message from ' + message.user, { body: message.message, vibrate: [200, 100, 200, 100, 200, 100, 200], tag: 'message' }); }) ; }else { alert('new message from ' + message.user + '\n please allow notification to get notification when a message receive.') } });¿Cómo redirigir al usuario a una URL específica después de hacer clic en la notificación?
Intento esto y trabajo, espero que sea útil para otros.
Notification.requestPermission(function(result) { if (result === 'granted') { navigator.serviceWorker.register('/sw.js'); navigator.serviceWorker.ready .then(function(registration) { registration .showNotification('new message from ' + message.user, { body: message.message, vibrate: [200, 100, 200, 100, 200, 100, 200], tag: 'message', data : {email: message.email} }) ; }) ; }else { alert('new message from ' + message.user + '\n please allow notification to get notification when a message receive.') } });y en el archivo 'sw.js' agregue esto:
self.addEventListener('notificationclick', function(event) { clients.openWindow('url'); event.notification.close(); }, false);