我有一个textarea编码来运行模糊的save_notes函数。当save_notes调用时,我在控制台中得到它:
TypeError: Cannot read property 'sync' of undefined
at HTMLTextAreaElement.save_notes
Javascript代码:
var note_area = document.getElementById('notetext')
//// todo Create a function to save the textarea to local storage
// todo First check & load any previously saved notes
;(function load_notes() {
if (note_area === "") {
chrome.storage.sync.get("stored_obj", function(resultObj) {
note_area.value = resultObj.stored_obj
})
}
})()
function save_notes () {
chrome.storage.sync.set({
stored_obj: note_area.value
}, function () {
// console.log("Saved into Chrome Storage")
})
}
note_area.addEventListener('blur', save_notes)
根据this topic海报需要向manifest.json添加存储权限。
我的manifest.json已经包含了该行。我想知道我是否缺少其他必要的许可,或者代码本身是否存在无关的问题。
的manifest.json
{
"manifest_version": 2,
"name": "Mindless Blocker",
"description": "Block mindless distractions and have a place to take notes for followup during free time",
"version": "0.1",
"browser_action": {
"default_icon": "cloud-icon.png",
"default_popup": "index.html"
},
"permissions": [
"storage"
]
}