chrome.storage.local.set "undefined" error but storage set in manifest.json

3,773 views
Skip to first unread message

Spencer Shaw

unread,
Oct 13, 2015, 6:27:54 AM10/13/15
to Chromium Apps
The following code is taken from https://groups.google.com/a/chromium.org/forum/#!topic/chromium-extensions/SN4Zv7PC_ZI but generates an error in Chrome App and Chrome Browser: 

Cannot read property 'local' of undefined.

Does anyone have any ideas what I am doing wrong? storage permission is set in the manifest.json file.

manifest.json:
{
"name":"XXXX",
"version":"0.17.0",
"manifest_version":2,
"minimum_chrome_version":"37.0.0.0",
"permissions":
[
"webview",
"power",
"storage",
"videoCapture",
"geolocation",
"pointerLock",
"system.display",
{
"fileSystem":["write","retainEntries","directory"]
},
"accessibilityFeatures.read",
"accessibilityFeatures.modify"
],
"app":{"background":{"scripts":["js/foam.js","js/cab.js","config.js","background_main.js"]}},
"kiosk_enabled":true,
  "kiosk_only": true,
"default_locale":"en",
"icons":{"128":"img/128.png"}}

Code
<script>
chrome.storage.local.set({
'key1': 'first',
'key2': 'second',
'key3': 'third',
'key4': 'fourth',
'key5': 'fifth'
}, function() {
// Notify that we saved.
console.debug('Settings saved');
alert('Settings saved');
});

var getItems = [];
for (var i = 1, end = 5; i <= end; i++) {
getItems.push('key' + i);
}

chrome.storage.local.get(getItems, function(items) {
var keys = Object.keys(items);
for (var i = 0, end = keys.length; i < end; i++) {
var key = keys[i];
console.debug(key + ' = ' + items[key]);
alert(key + ' = ' + items[key]);
}
})

</script>






Paul Canning

unread,
Oct 13, 2015, 12:50:08 PM10/13/15
to Chromium Apps
Works fine when running in a chrome App console. You'll get this error if you try running your app as a simple HTML page i.e just opening the HTML file in Chrome.

Add the app in Chrome properly (as an Extension) then run it.

Should definitely work!
Reply all
Reply to author
Forward
0 new messages