Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 363
Jamie Avatar asked Mar 24 '15 00:03

Jamie


People also ask

Where do Chrome extensions save data?

When extensions are installed into Chrome they are extracted into the C:\Users\[login_name]\AppData\Local\Google\Chrome\User Data\Default\Extensions folder. Each extension will be stored in its own folder named after the ID of the extension.

Do Chrome extensions take up storage?

Even if you're not actively using them, every open tab and enabled extension consumes disk space. It is easy to examine Chrome tabs and extensions that might be consuming too many resources in Chrome Task Manager.

Can content scripts access Chrome storage?

Therefore, if you're accessing localStorage from your contentscript, it will be the storage from that webpage, not the extension page storage. Now, to let your content script to read your extension storage (where you set them from your options page), you need to use extension message passing. chrome.


Video Answer


1 Answers

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 []

like image 86
Zig Mandel Avatar answered Oct 16 '22 05:10

Zig Mandel