我正在編寫Chrome擴展,並且不斷收到chrome.alarms未定義的錯誤消息。chrome.alarms.onAlarm引發Uncaught TypeError,無法讀取undefined屬性'onAlarm'
我的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'});
});
我把它裝上我的電腦作爲解壓後的擴展名,所以periodInMinutes
和when
約1分鐘的約束Chrome API文檔不適用於此處。
不太可能,但你使用Chrome <22嗎? [自Chrome 22以來穩定](http://developer.chrome.com/extensions/alarms.html)是我問的原因。 – Trojan
@trojansdestroy我正在運行的版本30.0.1599.101 –