2

I'm writing a Chrome extension, and I keep getting an error message that chrome.alarms is undefined.

My manifest.json file:

{
  "manifest_version": 2,

  "name": "C",
  "description": "whatever",

  "version": "1.0",

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

  "permissions": ["background", "storage", "notifications", "alarms"],

   "browser_action": {
      "default_icon": "logo.png",
      "default_title": "C",
      "default_popup": "popup.html"
    }
}

In my background.js file:

chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
    chrome.alarms.create('arbitrary', {
        when: 1000,
        periodInMinutes: 0.05
    });
});

chrome.alarms.onAlarm.addListener(function (alarm) {
   console.log('alarm called');
});

In my popup.js file:

$(document).ready(function() {
   chrome.runtime.sendMessage({addressInfo: 'text'});
});

I have it loaded on my computer as an unpacked extension, so periodInMinutes and when 1 minute constraints specified by the Chrome API documentation don't apply here.

4

2 回答 2

2

我在发布此消息后不久就发现了问题。如果有人想知道,我所要做的就是从 Chrome 的扩展页面重新加载扩展。我猜除非重新加载扩展名,否则清单文件中的更改将不适用。

于 2013-10-24T17:17:17.220 回答
0

重新加载 manifests.json 文件可以解决问题。

于 2017-10-08T14:09:41.590 回答