我正在撰写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 API文档指定的periodInMinutes
和when
1分钟限制不适用于此处。
答案 0 :(得分:2)
我发布此消息后不久就发现了问题。如果有人想知道,我所要做的就是从Chrome中的扩展程序页面重新加载扩展程序。我想清除文件中的更改不适用,除非重新加载扩展名。
答案 1 :(得分:0)
重新加载manifests.json文件解决了这个问题。