Retrieves one or more items from the storage area.
Syntax
chrome.storage.[storageType].get(keys,callback);
[storageType
] will be one of the writable storage types — storage.sync
or storage.local
.
Parameters
keys
- A key (string) or keys (an array of strings or objects) to identify the item(s) to be retrieved from storage. If you pass an empty string or array here, an empty object will be retrieved. If you pass
null
here the entire storage contents will be retrieved. callback Optional
- A callback function that is run when the operation completes. If the operation is successful, the function is passed a
results
object containing every object inkeys
that was found in the storage area. If the operation fails,runtime.lastError
is set.
Browser compatibility
Examples
// callback for get() function gotItem(item) { if (chrome.runtime.lastError) { console.log(chrome.runtime.lastError); } else { console.log(item); } } // storage contains two items, // "kittens" and "monsters" chrome.storage.local.set({ kitten: {name:"Mog", eats:"mice"}, monster:{name:"Kraken", eats:"people"} }); // with no `keys` argument, retrieve everything chrome.storage.local.get(gotItem); // -> Object { kitten: Object, monster: Object } // with an empty array, retrieve nothing chrome.storage.local.get([], gotItem); // -> Object { } // with the name of an object, retrieve the match chrome.storage.local.get("kitten", gotItem); // -> Object { kitten: Object } // with an array of object names, retrieve all matches chrome.storage.local.get(["kitten", "monster", "grapefruit"], gotItem); // -> Object { kitten: Object, monster: Object }
Example add-ons
Document Tags and Contributors
Tags:
Contributors to this page:
wbamberg,
chrisdavidmills
Last updated by:
wbamberg,