Chrome.storage.sync.get()似乎是重复键?

时间:2017-11-01 03:36:12

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

我使用以下序列保存一些设置

var getSettings = async function() {

    var settings;
    try {
        settings = await authenticatedGET(server_url + SETTINGS_ENDPOINT);
        return settings;
    } catch (error) {
        console.log("Settings Fetch Failed: " + error);
        throw new Error(error);
    }
}

const setLocalSettings = function(settings) {
    chrome.storage.sync.set({ 'LML_Settings': JSON.parse(settings) }, function() {
        console.log("Settings saved locally");
    });
}

setLocalSettings函数定义之后的行右侧,'settings'对象注销为 {"email_format":"individual","close_tab":true,"frequency":"DAILY"}(按预期正确)。当我使用此序列获取设置时:

chrome.storage.sync.get('LML_Settings', function(LMLSettingsContainer) {
                console.log(LMLSettingsContainer);
                if (LMLSettingsContainer.LML_settings.close_tab == "true") {
                    closeCurrentTab();
                }
            })

LMLSettingsContainer注销为

{
  "LML_Settings": {
    "close_tab": true,
    "email_format": "individual",
    "frequency": "DAILY"
  }
}

使用LMLSettingsContainer.LML_Settings["<setting>"]访问我的设置有点烦人(这就是我将顶部变量命名为LMLSettingsContainer的全部原因。)

有没有人知道是否有办法让Chrome保存/获取这些值?

1 个答案:

答案 0 :(得分:0)

chrome.storage.sync.get('LML_Settings',({LML_settings})=&gt; {...})适用于@wOxxOm