title: Getting cookies in a google chrome extension
body: <p>I am trying to get a cookie specifically from a domain using this code:</p>
  
  <pre><code>&lt;script language="javascript" type="text/javascript"&gt;
  
  var ID;
  
  function getCookies(domain, name) {
      chrome.cookies.get({"url": domain, "name": name}, function(cookie) {
          ID = cookie.value;
      });
  }
  
  getCookies("http://www.example.com", "id")
  alert(ID);
  
  &lt;/script&gt;
  </code></pre>
  
  <p>The problem is that the alert always says undefined. However, if I change</p>
  
  <pre><code>ID = cookie.value;
  </code></pre>
  
  <p>to</p>
  
  <pre><code>alert(cookie.value);
  </code></pre>
  
  <p>it works properly. How do I save the value to use later?</p>
  
  <p>Update: It appears that if I call alert(ID) from the chrome console after the script runs, it works. How can I set my code to wait until chrome.cookies.get finishes running?</p>