1
votes

I need to know, if it´s possible in any way to store data from an chrome extension, which I can use on every website. I use the data in JS conent_scripts.

I tried cookies and iframe for localStorage workaround as desribed here: http://www.nczonline.net/blog/2010/09/07/learning-from-xauth-cross-domain-localstorage/

But nothing really worked. Please help me.

Edit: As written below in comments, it works now with chrome.storage. Thanks!

Edit2: This doesn´t work for me:

chrome.storage.sync.set({key: "test", value: "test Test 1234"},
                        function ()
                        {
                             console.log("had saved!");
                             chrome.storage.sync.get("test",
                                                     function (value)
                                                     {
                                                          console.log("read value: ", value);
                                                     }
                                                 );
                         }
                     );

The console output:

read value: Object {}

1
How long do you want the data to last? Until the browser is closed? Forever? - Qantas 94 Heavy
forever would be nice. - alpham8
chrome.storage doesn´t exist in content_scripts - alpham8
Since when ??? According to the docs: Your extension's content scripts can directly access user data without the need for a background page. - gkalpak

1 Answers

1
votes

The problem with your new code is the following:

chrome.storage.sync.set({test: "test Test 1234"}, function () {
    console.log("had saved!");
    chrome.storage.sync.get("test", function (value) { console.log("read value: ", value.test); } );
});

All objects are key-value pairs, you shouldn't add the key and value properties.