Chrome (macOS) 不显示桌面推送通知

Har*_*oli 2 macos google-chrome push-notification firebase-cloud-messaging angular

我已将基于 FCM 的推送通知集成到我的 Angular 应用程序中,在 ubuntu 和 Windows 设备上触发推送通知,但无法在 macOS 上工作。我附上firebase-messaging-sw.js的代码:

importScripts('https://www.gstatic.com/firebasejs/4.8.1/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/4.8.1/firebase-messaging.js');

firebase.initializeApp({
    'messagingSenderId': SENDER_ID
});

self.addEventListener('fetch', event => {
    event.waitUntil(async function() {
        // Exit early if we don't have access to the client.
        // Eg, if it's cross-origin.
        if (!event.clientId) return;

        // Get the client.
        const client = await clients.get(event.clientId);
        // Exit early if we don't get the client.
        // Eg, if it closed.
        if (!client) return;

        // Send a message to the client.
        self.clients.matchAll().then(function(clients) {
            clients.forEach(function(client) {
                client.postMessage({
                    msg: "Hey I just got a fetch from you!",
                    url: event.request.url
                });
            });
        });

    }());
})

const messaging = firebase.messaging();

messaging.setBackgroundMessageHandler(function(payload) {
    // Customize notification here
    const notificationTitle = 'Background Message Title';
    const notificationOptions = {
        body: 'Background Message body.',
        icon: '/firebase-logo.png'
    };

    return self.registration.showNotification(notificationTitle,
        notificationOptions);
});
Run Code Online (Sandbox Code Playgroud)

我们是否需要添加任何额外的配置来添加对 macOS Chrome 的支持?

Duc*_*Mai 11

对于在 Mac 上没有收到推送通知的人,请确保您已在系统偏好设置 -> 通知 -> Chrome 中启用 Chrome 通知

即使我只是简单地复制并粘贴 Firebase 教程中的代码,我也在努力解决这个问题:)