Chrome extension storage: set/get value

google-chrome-extensionlocal-storage

Trying to set and get values in my Chrome extension using local storage. Don't know what I did, but it's no longer working.¨

In manifest I have:

   "permissions": [
      "tabs", "http://*/*", "https://*/*", "storage"
    ],

This is the complete js, which sets a value and then tries to read it:

 chrome.storage.local.set({'userid': "foo"}, function (result) {
    chrome.storage.local.get('userid', function (result) {
        alert(userid.result);
   });
});

The alert says "undefined", not "foo" as expected.

The js is executed when i go to a certain page, specified in manifest for "content_scripts".

Best Answer

Doh, I figured it out. It should be:

alert(result.userid);

(reverse userid and result)

Related Topic