首页 > 解决方案 > Chrome.notifications.update 未更新

问题描述

在后台脚本内的 chrome 扩展应用程序中,我正在尝试实现此代码,这是我的代码:

function foo(title, message, timeout) {
    chrome.notifications.create({
      type: 'progress',
      iconUrl: 'img/GS icon.png',
      title: title,
      message: message || '',
      progress: 0
    }, function(id) {
      // Automatically close the notification in 4 seconds by default
      var progress = 0;
      var interval = setInterval(function() {
        if (++progress <= 100) {
          chrome.notifications.update(id, {progress: progress}, function(updated) {
            if (!updated) {
              // the notification was closed
              clearInterval(interval);
            }
          });
        } else {
          chrome.notifications.clear(id);
          clearInterval(interval);
        }
      }, (timeout || 4000) / 100);
    });
  };

  window.onload=function(){
    foo('ttttitle','messsageee',10000);
  }

但它始终保持在 1% 并且不动:

在此处输入图像描述

找不到问题。

清单.json:

{
    "background": {
        "scripts": ["js/background.js"],
        "persistent": false
    },
    ...
}

标签: javascriptgoogle-chrome-extension

解决方案


推荐阅读