0

I saved a state inside the local storage and trying to use it inside if statement

    function start(){
    chrome.storage.sync.get("data", function(items) {
    if (!chrome.runtime.error) {
      console.log(items.data); //true or false 
      return items.data;
    }
 
   return items.data;
  });
    }
    
    console.log(start()); //undifinde
    
    if(start()){ // undifinde 
    
    }

how to get around this

I am trying to make part of the code inside the content script enabled or disabled

  • 2
    chrome.storage.sync.get invokes the callback asynchronously so there is no immediate return value. Rework the code, see [How do I return the response from an asynchronous call?](//stackoverflow.com/q/14220321) – wOxxOm Jul 24 '17 at 08:01
  • thanks, i was able to do it with "Promises with" – mohammad aljammali Jul 24 '17 at 10:25

0 Answers0