gpt4 book ai didi

javascript - Mozilla WebExtension 桌面通知显示时间和/或需要用户交互

转载 作者:行者123 更新时间:2023-12-02 14:12:09 26 4
gpt4 key购买 nike

我有一个 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;
}
}

有什么想法如何将显示时间设置为“必须交互”之类的内容吗?

最佳答案

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

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

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

但是,至少截至目前,字符串 requireInteraction does not exist in the Firefox source code .

关于javascript - Mozilla WebExtension 桌面通知显示时间和/或需要用户交互,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39450554/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com