Web*_*ter 0 javascript notifications push-notification web-worker web-push
我self.addEventListener('notificationclick', function(event) {})在我的服务人员中使用来监听通知的点击
触发 notificationclick 事件以指示已单击由 ServiceWorkerRegistration.showNotification() 生成的系统通知。
当我使用ServiceWorkerRegistration.showNotification并单击通知时,它会触发侦听器,但是当我有一个远程通知时,它不会触发,我必须actions从服务器进行设置,并且如果用户单击它触发的操作按钮,但如果单击通知本身,则不会触发
有什么解决方法吗?
firebase-messaging.js 具有以下代码。
self.addEventListener("notificationclick", function(event) {
event.stopImmediatePropagation();
event.notification.close();
Run Code Online (Sandbox Code Playgroud)
在加载库之前定义我的通知单击函数。
self.addEventListener("notificationclick", function(event) {
console.log('notification open');
// log send to server
});
importScripts('https://www.gstatic.com/firebasejs/8.6.2/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/8.6.2/firebase-messaging.js');
firebase.initializeApp({
'messagingSenderId': 'xxxxx'
});
const messaging = firebase.messaging();
Run Code Online (Sandbox Code Playgroud)