title: Chrome Extension Message passing: response not sent
body: <p>I am trying to pass messages between content script and the extension</p>
  
  <p>Here is what I have in content-script</p>
  
  <pre><code>chrome.runtime.sendMessage({type: "getUrls"}, function(response) {
    console.log(response)
  });
  </code></pre>
  
  <p>And in the background script I have</p>
  
  <pre><code>chrome.runtime.onMessage.addListener(
    function(request, sender, sendResponse) {
      if (request.type == "getUrls"){
        getUrls(request, sender, sendResponse)
      }
  });
  
  function getUrls(request, sender, sendResponse){
    var resp = sendResponse;
    $.ajax({
      url: "http://localhost:3000/urls",
      method: 'GET',
      success: function(d){
        resp({urls: d})
      }
    });
  
  }
  </code></pre>
  
  <p>Now if I send the response before the ajax call in the <code>getUrls</code> function, the response is sent successfully, but in the success method of the ajax call when I send the response it doesn't send it, when I go into debugging I can see that the port is null inside the code for <code>sendResponse</code> function.</p>