Mozilla WebExtension 桌面通知显示时间 and/or 需要用户交互

Mozilla WebExtension desktop notification display time and/or require user interaction

我有一个用于 Mozilla 的 WebExtension,它通过桌面通知功能通知我。

它完全符合我的要求,但 Firefox 会在 X 秒后自动关闭通知。是否可以显示通知直到用户点击它?

我做的事情是每 5 秒关闭并重新打开通知,因此用户必须单击它才能永久关闭它。

看起来像这样:

// This is the notification function
function notifyMeFunction() {    
    var notification = new Notification('Alert', {
        icon: chrome.extension.getURL('icons.png'),
        body: "New Notification",
        tag: "DesktopNotification",
    });


    notification.onclick = function(event) {
        notificationClicked = true;
    }

    notification.onclose = function(event) {
        notificationClicked = true;
    }
}

// Function which will self-open every 5 seconds
function notifyMe() {
    if (notificationClicked == false) {
        notifyMeFunction();
        setTimeout(notifyMe, 5000);
    } else {
       notificationClicked = false;
    }
}

关于如何将显示时间设置为类似 "must interact" 的任何想法?

目前(Firefox 版本 <= 51.0a1)没有向 API 指示用户必须与这些通知进行交互的方法。也没有任何方法可以指定向用户显示通知的时间长度。

注意:您正在使用 Web Notifications API, not the WebExtensions chrome.notifications API。两者都没有办法要求用户在 Firefox 中进行交互。

从 Chrome 50 开始,Google Chrome 确实有一个选项要求用户必须与通知交互:requireInteraction。因此,在某个时间点,Firefox 可能会支持这样的选项。

但是,至少在这个时间点,字符串 requireInteraction does not exist in the Firefox source code.