gpt4 book ai didi

javascript - chrome.storage.sync 调用结果为 : TypeError: Cannot read property 'sync' of undefined

转载 作者:行者123 更新时间:2023-11-28 04:30:54 26 4
gpt4 key购买 nike

我有一个编码为在模糊时运行 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已经包含了该行。我想知道我是否缺少其他一些必要的权限,或者代码本身是否存在不相关的问题。

ma​​nifest.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"
]
}

最佳答案

当您更改manifest.json 文件时,您必须重新加载扩展列表。

转到chrome://extensions/然后按 CTRL+R。

关于javascript - chrome.storage.sync 调用结果为 : TypeError: Cannot read property 'sync' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44619555/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com