Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

chrome.storage.sync undefined?

I'm trying to use chrome storage in an extension, via a content_script, but I keep failing on

Uncaught TypeError: Cannot read property 'sync' of undefined  

This is my code:

testChromeStorage();  function testChromeStorage() {       console.log("Saving");     chrome.storage.sync.set({'value': theValue}, function() {         message('Settings saved');     });     chrome.storage.sync.get("value", function (retVal) {             console.log("Got it? " + retVal.value);     }); } 
like image 449
Yossale Avatar asked Aug 01 '13 15:08

Yossale


2 Answers

You have to add the "storage" permission in your manifest.json file, i.e.:

...   "permissions": [     "storage"   ], ... 

For more information, see: https://developer.chrome.com/extensions/storage

like image 137
sfarbota Avatar answered Sep 24 '22 00:09

sfarbota


RELOAD THE EXTENSION

I had the "permissions" key added in my manifest file but still I struggled to get this fixed.

After adding the permission:-

"permissions": [     "storage"  ] 

Goto your extension using: chrome://extensions/ & click the Reload button:-

enter image description here

like image 33
Rahul Singh Avatar answered Sep 22 '22 00:09

Rahul Singh