[英]chrome.storage not working
我有一個谷歌瀏覽器應用程序,嘗試使用chrome.storage.sync.get,它說“無法讀取未定義的屬性同步”。 有人可以告訴我發生了什么嗎? 我嘗試從chrome開發人員網站復制並粘貼確切的行。
該代碼從字面上是:
$(".thing").click(function() {chrome.storage.sync.set(stuff)}
據我所知,錯誤只是我正在嘗試在Google Chrome中使用Chrome存儲API,而不是作為應用程序使用。
事實證明,我試圖在Google chrome(瀏覽器)中運行此程序,而不是在chrome應用程序中運行。 Chrome瀏覽器不知道應將代碼解析為應用程序,並且忽略有關chrome.storage
。 值得一提的是chrome開發人員!
使用chrome.storage.sync
時,請按照以下步驟chrome.storage.sync
的manifest.json
{
"manifest_version": 2,
"name": "Storage",
"description": "This extension shows a Google Image search result for the current page",
"version": "1.0",
"icons":{
"256":"img/icon.png"
},
"permissions": [
"storage"
],
"app": {
"launch": {
"local_path": "options.html"
}
},
"background": {
"scripts": ["js/app/background.js"]
}
}
在chrome://extensions
重新加載您的應用,以使manifest.json在瀏覽器中得到更新。
遵循chrome.storage.sync
的確切語法及其回調函數。
Sample.js
$(".thing").click(function() {
chrome.storage.sync.set({"myKey": "testPrefs"},function(){
alert("object stored");
})
chrome.storage.sync.get("myKey",function(obj){
alert(obj.myKey);
})
});
這將為您工作。 我在Chrome應用中測試了此代碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.