title: How can I receive data of an external API with Chrome extension?
body: <p>I try to create an chrome extension who works with an another API. So my content script get the data in DOM and ask the API the result (in background.js)</p>
  
  <p>So, I send a message from <code>contentscript.js</code> to <code>background.js</code> and I wait the response of my API since <code>sendResponse</code>. But, I have a problem the response is always <code>undefined</code> because <code>contentscript.js</code> receive the response except I don't yet send the response. </p>
  
  <p>contentscript.js :</p>
  
  <pre><code>chrome.runtime.sendMessage({type: "new", data: {/* ... */}}, function(response) {
      console.log(response);
  });
  </code></pre>
  
  <p>background.js : </p>
  
  <pre><code>chrome.runtime.onMessage.addListener(function(msg, _, sendResponse) {
      if (msg.type == "new") {
  
          execute(msg.data).then(function (response) {
              sendResponse(response);
          });
      }
  });
  
  function execute(data){
      return new Promise( function (resolve, reject){
  
          /* ... */
  
          $.ajax(options).done(function(data) {
              return resolve(data);
          });
      });
  
  }
  </code></pre>
  
  <p>What's the solution ?</p>
  
  <p>I need to add onMessageListener in my contentscript and background, so, I don't use sendResponse ?</p>
  
  <p>Thanks</p>