Storage

  • local:本地存储,限制为 5 MB,但可以通过添加 unlimitedStorage 权限取消大小限制
  • sync:同步存储,总大小 100KB,单个 item 大小 8KB。 The quota limitation is 100 KB approx, 8 KB per item.
  • session:in-memory,不保存在硬盘中

Storage 只能通过键值对存取,没有检索功能:

chrome.storage.local.set({ key: value }).then(() => {
  console.log("Value is set to " + value);
});

chrome.storage.local.get(["key"]).then((result) => {
  console.log("Value currently is " + result.key);
});


chrome.storage.sync.set({ key: value }).then(() => {
  console.log("Value is set to " + value);
});

chrome.storage.session.set({ key: value }).then(() => {
  console.log("Value is set to " + value);
});

但是有回调函数,可以在值更改时接到通知:

chrome.storage.onChanged.addListener(
  callback: function,
)

Reference