In popup.js in my Google Chrome extension, I have:
function sendWebResponse(hash) {
  var xmlhttp = new XMLHttpRequest(); 
  xmlhttp.open("POST", "http://localhost:3000/tasks/4123434/from_chrome");
  xmlhttp.setRequestHeader("Content-Type", "application/json");
  xmlhttp.setRequestHeader("Accept", "application/json");
  xmlhttp.setRequestHeader('Authorization', 'Token token=463c121664d98a6dafd1086e8d0ecca0');
  xmlhttp.send(JSON.stringify(hash));  
}
function grabCurrentUrl(url) {
  chrome.tabs.query(
    {'active': true, 'lastFocusedWindow': true}, 
      function (tabs) {
        var url = tabs[0].url;
        return url;
      }
)};
The following works:
function submitTrue(id) {
  sendWebResponse({"survey": id,"result": "true");
}
But the following does not:
function submitTrue(id) {
  var url = grabCurrentUrl();
  sendWebResponse({"survey": id,"result": "true", "url": url});
}
In this case, url is null. There definitely is an active tab when I do this.
Why is grabCurrentURL() not grabbing the active tab's current URL?
 
    