59

I can get the value of a storage key with the Chrome Extension API:

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

How can I get all key names that exist in the Chrome storage?

hichris123
  • 10,145
  • 15
  • 56
  • 70
Ali Esmailian
  • 979
  • 3
  • 9
  • 8

1 Answers1

141

From the documentation (emphasis mine):

An empty list or object will return an empty result object. Pass in null to get the entire contents of storage. Don't forget to change "storage.sync" to storage.local if you're using local storage.

For some example code:

chrome.storage.sync.get(null, function(items) {
    var allKeys = Object.keys(items);
    console.log(allKeys);
});
woutr_be
  • 9,532
  • 24
  • 79
  • 129
Rob W
  • 341,306
  • 83
  • 791
  • 678
  • Warning: `chrome.storage` does NOT adhere to ES6/ES2015 spec like Chrome -- it will sort your object keys if you store the object through this interface (unlike recent versions of Chrome, which preserves the order of the keys). I have reported this [here](https://groups.google.com/a/chromium.org/d/msg/chromium-extensions/frmBSQcIzcs/YaQ1hLSLAgAJ). – thdoan Apr 22 '18 at 10:24