我的扩展弹出页面从沙盒页面和脚本的消息中获取数据。我需要将它存储在 chrome.storage 中,最好使用 storage.sync 方法。我收到此错误: 未捕获的类型错误:无法读取未定义的属性“同步”
我已经在 manifest.json 中添加了存储权限。
...“权限”:[“存储”],... chrome.storage.sync 未定义?
谷歌还声明不需要背景脚本: https ://developer.chrome.com/extensions/storage
引用:您的扩展程序的内容脚本可以直接访问用户数据,而无需后台页面。
我在看什么?提前致谢!
function receiveMessage(event) {
var data = event.data;
saveToStorage(data);
};
window.addEventListener("message", receiveMessage, false);
function saveToStorage(data)
{
if (!data) {
console.log('Error: No value specified. Nothing saved to storage.');
return;
}
chrome.storage.sync.set({'data': data}, function() {
console.log('Data saved to storage.');
});
};