【问题标题】:Get all keys from Chrome Storage从 Chrome 存储中获取所有密钥
【发布时间】:2013-08-11 15:02:35
【问题描述】:

我可以使用 Chrome 扩展 API 获取存储密钥的值:

chrome.storage.sync.get("someKey", function() {});

如何获取 Chrome 存储中存在的所有键名?

【问题讨论】:

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


    【解决方案1】:

    来自documentation(强调我的):

    空列表或对象将返回空结果对象。 传入null 以获取存储的全部内容。如果您使用本地存储,请不要忘记将“storage.sync”更改为 storage.local。

    一些示例代码:

    chrome.storage.sync.get(null, function(items) {
        var allKeys = Object.keys(items);
        console.log(allKeys);
    });
    

    【讨论】:

    • 警告:chrome.storage 不像 Chrome 那样遵循 ES6/ES2015 规范——如果你通过这个接口存储对象,它会对你的对象键进行排序(不像最新版本的 Chrome,它保留了顺序键)。我已经报告了这个here
    猜你喜欢
    • 1970-01-01
    • 2016-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多