chrome.storage.sync无法正常工作,无法保存

时间:2019-07-13 06:31:14

标签: javascript json google-chrome google-chrome-extension google-chrome-storage

我正在尝试使用chrome.storage.sync

保存当前打开的窗口的数据

这是我的代码:

chrome.commands.onCommand.addListener(function(command) {
if (command == "Save And Sleep") {
    let time_ = new Date().toISOString();
    chrome.windows.getAll({
        populate: true
    }, function(windows) {
        //console.log(windows);
        windows.forEach(function(window) {
            let data_ = JSON.stringify(window);
            let key_ = "MUA-Save&Sleep " + time_ + " " + window.id;
            var obj = {};
            obj[key_] = data_;
            console.log(data_);
            chrome.storage.sync.set(obj, function() {
                console.log(data_ + "saved");
            });
        });
    });
} else if (command == "Restore And Breath") {
    //let json_=JSON.parse(JSON.stringify(window));
    chrome.storage.sync.get(null, function(items) {
        var allKeys = Object.keys(items);
        //console.log(allKeys);
        //console.log(allKeys[1]);
        allKeys.forEach(function(key) {
            if (key.startsWith("MUA-Save&Sleep") == true) {
                chrome.storage.sync.get([key], function(result) {
                    console.log('Value currently is --- ' + result);
                    //console.log(key);
                });
            }
        });
    });
}
});

chrome.storage.sync.set内部,它说它已经保存了值,但是当我尝试检索这些值时,它什么也没返回。

这很简单:

chrome.storage.sync problem

这是怎么了?

0 个答案:

没有答案