2013-10-23 60 views
2

我正在編寫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'}); 
}); 

我把它裝上我的電腦作爲解壓後的擴展名,所以periodInMinuteswhen約1分鐘的約束Chrome API文檔不適用於此處。

+0

不太可能,但你使用Chrome <22嗎? [自Chrome 22以來穩定](http://developer.chrome.com/extensions/alarms.html)是我問的原因。 – Trojan

+0

@trojansdestroy我正在運行的版本30.0.1599.101 –

回答

2

發佈此消息後不久我就發現了這個問題。如果有人想知道,我所要做的就是在Chrome中的擴展頁面重新加載擴展程序。我想清單文件中的更改不適用,除非重新加載擴展。

+1

謝謝你。我正在使用Chrome Apps&Extensions開發工具進行測試,並且重新加載擴展程序也無法正常工作。卸載並重新安裝(在向清單中的權限添加警報之後)解決了該問題。 –

0

重新加載manifests.json文件解決了這個問題。

+0

你能澄清你的答案嗎? –

相關問題