Search code examples
javascriptgoogle-chromechrome-plugins

chrome.storage.local.get failing within chrome.storage.sync.get callback


It worked a moment ago and now I'm unable to get into the callback of chrome.storage.local.get().

I have data in the local store and I've written it correctly.

Why does it fail? Do I missunderstand something or am I missing something?

chrome.storage.sync.get("wortlisteOptionId", function(result){
    if(result["wortlisteOptionId"] != "" && result["wortlisteOptionId"] !== undefined){
        var prevSelection = result["wortlisteOptionId"];
    }
    var item = document.getElementById('wortlisten');
    // works till here
    chrome.storage.local.get("wortlisten", function(result)
    {
        let val;
        let optioncollection = "";
        if(result["wortlisten"] != null){
            for(val of result["wortlisten"]){
                optioncollection += '<option value="' + val.id + '">' + val.name + '</option>';                
            }
            item.innerHTML = optioncollection;

            if(prevSelection != null){
                item.selectedIndex = prevSelection;
            }
            restoreLocalData();                
        }
    });
});

Solution

  • I'm not sure what caused this problem. My best guess is, that I testet it with xampp on my local machine and the performance was horrible. After I tested it with my productive envirement, I haven't got that issue....

    On my way I found also this page with some explenation: Returning Chrome storage API value without function