chrome.notifications.create无法正常工作,已创建警报,但未显示通知

时间:2018-09-15 19:40:15

标签: google-chrome-extension

我正在尝试在警报上创建通知,但是虽然警报似乎可以正常工作,但该通知没有显示。任何建议将不胜感激!

background.js

'use strict';

chrome.alarms.create({when: Date.now()+1200, periodInMinutes: 20});

chrome.alarms.onAlarm.addListener(function(alarm) {
    console.log("Got an alarm!", alarm);
    chrome.notifications.create('reminder', {
            type: 'basic',
            iconUrl: 'icon_100.png',
            title: 'Break Time!',
            message: 'You\'ve been staring at the screen for 20 minutes, take a break!'
        });
});

manifest.json

{
  "name": "Break Time",
  "version": "1.0",
  "icons": {
    "100": "icon_100.png"
  },
  "description": "Take a break from the computer every 20 min",
  "permissions": ["alarms", "notifications"],
  "background": {
    "scripts": ["background.js"],
    "persistent": false
  },
  "manifest_version": 2
}

1 个答案:

答案 0 :(得分:0)

iconUrl应该指向一个有效的URL。如果您的文件位于扩展文件夹中,则为:

chrome.extension.getURL("/icon_100.png")