我不知道为什么无法在 chrome.storage.sync
中设置值(与 storage.local
存在同样的问题),我尝试了多种解决方案在线,但遗憾的是它们都不起作用
这是我的 popup.js
文件(链接到 popup.html
文件)
window.addEventListener("DOMContentLoaded", () => {
let my_key = "some string";
let value = "some value"
chrome.storage.sync.set({[my_key]: value}, function() {
console.log('Value is set to ' + value);
});
chrome.storage.sync.get([my_key], function(result) {
console.log('Value currently is ' + result.key);
});
});
每次输出都是当前值未定义
。
最佳答案
您应该使用result[my_key]
而不是result.key
chrome.storage.sync.get([my_key], function(result) {
console.log('Value currently is ' + result[my_key]);
});
关于javascript - 无法在 chrome.storage 中设置值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71457446/