Firebase服务人员



我已将操作添加到我的firebase通知、View和Opt Out中。我希望用户被引导到通知附带的url。下面的代码应该可以工作,但不能。请告诉我我做错了什么。

const messaging = firebase.messaging();

messaging.onBackgroundMessage((payload) => {
console.log('[firebase-messaging-sw.js] Received background message ', payload);
// Customize notification here
var notificationTopic = topic;
var notificationTitle = title;
var notificationOptions = {
body: body,
icon: icon,
image: image,
badge: badge,
click_action: url,
actions: [
{action: 'view', title: 'View'},
{action: 'unsubscribe', title: 'Opt-Out'}
]
}
self.registration.showNotification(notificationTitle, notificationOptions);

});
self.addEventListener('notificationclick', function(event) {

event.notification.close();

event.waitUntil(clients.matchAll({
type: "window"
}).then(function(clientList) {
for (var i = 0; i < clientList.length; i++) {
var client = clientList[i];
if (client.url == url && 'focus' in client)
return client.focus();
}
if (clients.openWindow)
return clients.openWindow(url);
}));
});

我遇到了同样的问题,当天,我投降了,只是在一个新的选项卡中打开了URL;数据";目标

最新更新