google-chrome-extensiongoogle-chrome-storage

Getting Multiple items from Chrome storage?


I have 4 items which I'd like to get but I'm unsure how to separate the keys. Using comma gives an error. Here is an example of my usage:

chrome.storage.sync.get({
    'customImage',
    'customColor',
    'customRandColor',
    'customRandImage'
  }, function(backgroundCheckedOptions) {
    document.getElementById('optionsCustomImage').checked = backgroundCheckedOptions.customImage;
    document.getElementById('optionsBackgroundColor').checked = backgroundCheckedOptions.customColor;
    document.getElementById('optionsRandomColor').checked = backgroundCheckedOptions.customRandColor;
    document.getElementById('optionsRandomImage').checked = backgroundCheckedOptions.customRandImage;
  });

I would have assumed they would be separated by a comma, but I guess not.


Solution

  • From the Chrome Storage documentation, it says:

    StorageArea.get(string or array of string or object keys, function callback)

    Easiest would be to pass an array by replacing your {} with []