Javascript Firefox未在service worker中打开推送消息窗口
Firebase云消息传递 我有一切设置,推送消息接收良好,当我点击它,它会打开新窗口。。。但只有在Chrome浏览器中,Firefox浏览器才不会打开它 我特别允许弹出窗口,但没有任何区别 我只是调试了一个小时Javascript Firefox未在service worker中打开推送消息窗口,javascript,firebase,firefox,web-push,Javascript,Firebase,Firefox,Web Push,Firebase云消息传递 我有一切设置,推送消息接收良好,当我点击它,它会打开新窗口。。。但只有在Chrome浏览器中,Firefox浏览器才不会打开它 我特别允许弹出窗口,但没有任何区别 我只是调试了一个小时 self.addEventListener('notificationclick', function(e) { console.log("This is printed to console fine"); clients.openWindow('https://ex
self.addEventListener('notificationclick', function(e) {
console.log("This is printed to console fine");
clients.openWindow('https://example.com'); // this makes no error, nothing
});
有什么想法吗
适用于Firefox47.0
在Firefox Quantum 60中不起作用
订阅了一个bug。我已从服务人员中删除:
const messaging = firebase.messaging();
现在它正在发挥作用
这简直是胡说八道。找到了原因
Firebase.messaging
是罪魁祸首,仅当您(从服务器)发送消息负载时:
由于firebase sdk中的某些原因,notification
属性的存在将阻止notificationclick
传播
您可以发送以下内容
{
"data": {
//...
}
}
我也为此挣扎了一段时间 对于其他有问题的人,我想补充一点: 您仍然可以使用firebase.messaging(),但必须确保将其放在事件侦听器之后 为了说明这一点: 这不起作用(clients.openWindow不起任何作用): 这确实有效(clients.openWindow按预期打开链接): 仍然不确定根本原因。我还怀疑messaging()会弄乱点击事件,并使Firefox拒绝打开窗口,因为它认为用户在收到通知时没有直接采取行动 但至少我有一个解决办法,可以继续下去
希望能有帮助。你救了我一天!您是否找到了一些在服务工作者内部使用firebase.messaging的解决方法?@hacker13ua问题是,您只能在onnotificationclick或close期间打开窗口,但firebase.messaging似乎会接收这些事件,当调用我们的处理程序onnotificationclick时,为时已晚!如果您使用“event.waitUntil(clients.openWindow(您的url地址))”,它将显示一个错误,表明事件不可用。但是,如果您删除firebase.messaging,它会正常工作。@Aurélien Warnon有一个更好的解决方法。但nutsIt在以下三种情况下的工作方式有所不同:浏览器关闭/未聚焦/聚焦。如果您输入“data”键,它将跳过处理通知消息的默认函数,这样做将解决其他问题。但是它并没有解决窗口的问题,因为onclick事件被执行了。这个修复在我挣扎了一段时间后对我有效。我不知道它是如何进行内部架构的,但在firebase js sdk/sw-controller.ts中看到这一行173:
//阻止其他侦听器接收事件
我认为这会阻止我的侦听器接收事件
{
"data": {
//...
}
}
const messaging = firebase.messaging();
// Add an event listener to handle notification clicks
self.addEventListener('notificationclick', function (event) {
if (event.action === 'close') {
event.notification.close();
} else if (event.notification.data.target_url && '' !== event.notification.data.target_url.trim()) {
clients.openWindow(event.notification.data.target_url);
}
});
messaging.setBackgroundMessageHandler(function (payload) {
// ... add custom notification handling ...
});
// Add an event listener to handle notification clicks
self.addEventListener('notificationclick', function (event) {
if (event.action === 'close') {
event.notification.close();
} else if (event.notification.data.target_url && '' !== event.notification.data.target_url.trim()) {
clients.openWindow(event.notification.data.target_url);
}
});
const messaging = firebase.messaging();
messaging.setBackgroundMessageHandler(function (payload) {
// ... add custom notification handling ...
});