Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

chrome extension storage: set/get value

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".

like image 404
user984003 Avatar asked Apr 30 '13 15:04

user984003


People also ask

How do I find local storage value in Chrome?

# View localStorage keys and valuesClick the Application tab to open the Application panel. Expand the Local Storage menu. Click a domain to view its key-value pairs. Click a row of the table to view the value in the viewer below the table.

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.

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.

Can content scripts access Chrome storage?

User data can be automatically synced with Chrome sync (using storage. sync ). Your extension's content scripts can directly access user data without the need for a background page.


1 Answers

Doh, I figured it out. It should be:

alert(result.userid);

(reverse userid and result)

like image 107
user984003 Avatar answered Nov 10 '22 08:11

user984003