title: Function returns {} on the first run and then works correctly
body: <p>I have a function which is ment to provide a content script some json data. The problem it works correctly only at 2nd+ run. Have no idea how to solve it :(</p>
  
  <pre><code>let links = {};
  
  chrome.runtime.onMessage.addListener(
  function (request, sender, sendResponse) {
  
      if (request.get == "links") {
          chrome.tabs.getAllInWindow(null, function (tabs_) {
  
              for (var i = 0; i &lt; tabs_.length; i++) {
                  if ((tabs_[i]['url'].match(some_var))) {
                      links[i] = [tabs_[i]['title'],
                          tabs_[i]['index']
                      ];
                  }
              }
              console.log(links);              
          });
  
          console.log(JSON.stringify(links));
          sendResponse({reply: JSON.stringify(links)});
      }
  });
  </code></pre>
  
  <p>The first time i run the function it returns an empty object {}, and then works fine.</p>