显示chrome.storage中的所有内容

Show everything in chrome.storage

本文关键字:chrome storage 显示      更新时间:2023-09-26

我尝试使用console.log(chrome.storage),但它没有返回任何帮助。我已经使用chrome.storage.sync.set在我的扩展中设置了一些值,并希望看到它们。

我可以键入console.log(localStorage)并查看其中的所有内容。如何使用chrome.storage做到这一点?

您必须等待chrome.storage.sync.set()操作完成。其中一种方法是回调函数。使用chrome.storage.sync.set()传递的值在回调中可用:

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