title: Returning Chrome storage API value without function
body: <p>For the past two days I have been working with chrome asynchronous storage. It works "fine" if you have a function. (Like Below):</p>
  
  <pre><code>chrome.storage.sync.get({"disableautoplay": true}, function(e){
  console.log(e.disableautoplay);
  });
  </code></pre>
  
  <p>My problem is that I can't use a function with what I'm doing. I want to just return it, like LocalStorage can. Something like:</p>
  
  <pre><code>var a = chrome.storage.sync.get({"disableautoplay": true});
  </code></pre>
  
  <p>or</p>
  
  <pre><code>var a = chrome.storage.sync.get({"disableautoplay": true}, function(e){
      return e.disableautoplay;
  });
  </code></pre>
  
  <p>I've tried a million combinations, even setting a public variable and setting that: </p>
  
  <pre><code>var a;
  window.onload = function(){
      chrome.storage.sync.get({"disableautoplay": true}, function(e){
      a = e.disableautoplay;
  });
  }
  </code></pre>
  
  <p>Nothing works. It all returns undefined unless the code referencing it is inside the function of the get, and that's useless to me. I just want to be able to return a value as a variable. </p>
  
  <p>Is this even possible?</p>
  
  <p>EDIT: This question is not a duplicate, please allow me to explain why:</p>
  
  <p>1: There are no other posts asking this specifically (I spent two days looking first, just in case).</p>
  
  <p>2: My question is still not answered. Yes, Chrome Storage is asynchronous, and yes, it does not return a value. That's the problem. I'll elaborate below...</p>
  
  <p>I need to be able to get a stored value outside of the chrome.storage.sync.get function. I -cannot- use localStorage, as it is url specific, and the same values cannot be accessed from both the browser_action page of the chrome extension, and the background.js. I cannot store a value with one script and access it with another. They're treated separately.</p>
  
  <p>So my only solution is to use Chrome Storage. There must be some way to get the value of a stored item and reference it outside the get function. I need to check it in an if statement.</p>
  
  <p>Just like how localStorage can do</p>
  
  <pre><code>if(localStorage.getItem("disableautoplay") == true);
  </code></pre>
  
  <p>There has to be some way to do something along the lines of</p>
  
  <pre><code>if(chrome.storage.sync.get("disableautoplay") == true);
  </code></pre>
  
  <p>I realize it's not going to be THAT simple, but that's the best way I can explain it.</p>
  
  <p>Every post I see says to do it this way:</p>
  
  <pre><code>chrome.storage.sync.get({"disableautoplay": true, function(i){
      console.log(i.disableautoplay);
      //But the info is worthless to me inside this function.
  });
  //I need it outside this function.
  </code></pre>