0

I am trying to set an object variable to data from storage (if exists).

If data doesn't exist in storage, setting some initial values then sync them to storage.

I think there is something that I'm missing in the way I pass the object to storage.

I'm currently getting error:

Uncaught TypeError: Cannot read property 'sync' of undefined
at window.onload

Here is my code:

window.onload = function() {
if (!chrome.storage.sync.get('seData', function() {
    console.log('Data does not exist in storage.');
})) {
    var seData = {
        "google": {
            "class": "search-btn-google",
            "url": "http://www.google.com/search",
            "logo": "google.png"
        },
        "duckduckgo": {
            "class": "search-btn-duckduckgo",
            "url": "http://www.duckduckgo.com",
            "logo": "duckduckgo.png"
        }
    }

    chrome.storage.sync.set(seData, function() {
        console.log('Data saved to storage.');
    });
} else {
    console.log('seData exists in storage');
    seData = chrome.storage.sync.get(seData, function() {
        console.log('Set seData var from storage data');
    });
}
Yonatan Shippin
  • 161
  • 1
  • 9

0 Answers0