如何在固定时间间隔内实现 chrome 扩展弹出桌面通知

How to implement a chrome extension popup desktop notification on fixed time interval

本文关键字:扩展 chrome 通知 桌面 实现 定时间      更新时间:2023-09-26

我希望chrome在固定的时间间隔内通知我。我尝试编写此代码,但只显示一次。

var notification = webkitNotifications.createNotification(
  'icon.png',
  'Free your eyes',
  'Please take a break'
);
function showNotify()
{
  notification.show();
  setTimeout("showNotify()", 2000);
}
showNotify();

使用 setInterval() 定期运行代码。

尝试这样的事情:

function show() {
  var notification = /* ... */
}
setInterval(show, 2000);