我在我的react应用中实现了服务工作者,以设置推送通知,并且通知在chrome上正常工作,但在Firefox上却无法正常工作。我只有在通知弹出窗口中的目标URL与windowClient.url不匹配但在firefox windowClient.url中提供正确的URL时才在showung push通知中包含代码。
这是我使用的代码:
self.addEventListener('install', function(e) {
self.skipWaiting();
});
self.addEventListener('activate', function(e) {
self.clients.claim();
});
self.addEventListener('push', function(event) {
event.waitUntil(
self.clients
.matchAll({
type: 'window',
includeUncontrolled: true,
})
.then(windowClients => {
var matchingClient = null;
url = null;
if (!(self.Notification && self.Notification.permission === 'granted')) {
return;
}
let data = {};
if (event.data) {
data = event.data.json();
}
url = data.action;
for (let i = 0; i < windowClients.length; i++) {
const windowClient = windowClients[i];
if (windowClient.url === url && windowClient.focused === true) {
matchingClient = url;
break;
}
}
if (!matchingClient) {
return self.registration.showNotification(data.title, {
body: data.body,
icon: 'logo.png',
});
}
}),
);
});
self.addEventListener('notificationclick', function(event) {
event.notification.close();
event.waitUntil(clients.openWindow(url));
});
firefox上的windowclient URL是否存在问题?我正在使用的firefox版本是66。