chrome.storage set\\get clarification

元气小坏坏 提交于 2019-12-01 05:11:59
Pascal Belloncle

The returning value from the function you pass to chrome.storage.sync does not do what you expect. The value is only available within the callback. It does not end up in dbdata.

In addition:

chrome.storage.sync is an asynchronous API.

You have to wait for it to complete before you can retrieve the data.

chrome.storage.sync.set({'value': 12}, function() {
    chrome.storage.sync.get("value", function(data) {
      console.log("data", data);
    });
  });

and the output is:

data Object {value: 12} 

manifest.json must contain:

"permissions": [ "storage" ],

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!