我正在编写一个Chrome扩展,我一直收到一个错误消息,chrome.alarms是未定义的。
我的manifest.json文件:
{
"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"
}
}在我的background.js文件中:
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');
});在我的popup.js文件中:
$(document).ready(function() {
chrome.runtime.sendMessage({addressInfo: 'text'});
});我把它作为一个未打包的扩展加载到我的计算机上,所以Chrome文档指定的periodInMinutes和when 1分钟约束在这里不适用。
发布于 2013-10-24 17:17:17
我在发这篇文章后不久就发现了这个问题。如果有人想知道,我所要做的就是从Chrome的扩展页面中重新加载扩展。我想,除非重新加载扩展名,否则清单文件中的更改不适用。
发布于 2017-10-08 14:09:41
重新加载manifests.json文件解决了这个问题。
https://stackoverflow.com/questions/19554487
复制相似问题