javascript - Firefox 没有在 Service Worker 中为推送消息打开窗口
问题描述
Firebase 云消息传递
我已经完成了所有设置,推送消息接收良好,当我点击它时,它会打开新窗口......但只有在 Chrome 中,在 Firefox 中它没有打开。
我特别允许弹出窗口,但没有任何区别。
我只是调试了1个小时
self.addEventListener('notificationclick', function(e) {
console.log("This is printed to console fine");
clients.openWindow('https://example.com'); // this makes no error, nothing
});
有任何想法吗?
适用于 Firefox 47.0
在 Firefox Quantum 60 中不起作用
订阅了一个错误。
解决方案
我也为此苦苦挣扎了一段时间...
对于遇到问题的其他人,我想添加一些内容:
您仍然可以使用 firebase.messaging() 但您必须确保将其放在事件侦听器之后。
为了明确这一点:
这不起作用(clients.openWindow 什么都不做):
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 ...
});
这确实有效(clients.openWindow 按预期打开链接):
// 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 ...
});
仍然不确定根本原因。我还怀疑messaging() 搞砸了点击事件并让Firefox 拒绝打开一个窗口,因为它认为用户没有对通知采取直接行动。
但至少我有一个解决方法并且可以继续前进。
希望有帮助。
推荐阅读
- jakarta-ee - 从 JavaEE 发送的带有容器管理事务的 JMS 消息在容器提交事务之前不会发送
- python - 将 DataFrame 中凌乱的日期字符串转换为 python 和 pandas 中的“datetime”
- python - 使用 pygsheets 如何检测电子表格是否已经存在?
- python - 为什么我的编辑器没有给我语法错误,但是编译却给了我语法错误
- python - 相同功能的不同输出
- c# - 将异步任务从 c# 转换为 vb.net
- web-audio-api - Webaudio 增益在 0 时不静音
- java - Android Java 应用程序 - 发出通知时,发送者会收到通知,但运行该应用程序的其他设备不会
- docker - 如何为每个 docker 容器获取不同的 IP 地址?
- javascript - 元素 cloneNode(deep) 失败,控制台中仅给出未定义的错误