title: Chrome extension: Execute some code if a specific tab is not found
body: <p>I am developing a chrome extension and after it is installed it iterates through opened tabs and if the required Tab is not found then I open a new tab. Following is my code:</p>
  
  <pre><code>var found = false;
  chrome.tabs.getAllInWindow(null, function(tabs){
      for (var i = 0; i &lt; tabs.length; i++) {
          var tabUrl = tabs[i].url;
          if (tabUrl == 'http://www.youtube.com') {
             chrome.tabs.update(tabs[i].id,{url:someUrl,selected:true});
             found = true;  
          }
      }
  });
  if (!found) {
      window.open('https://www.youtube.com/watch?v=somevideid');
  }
  </code></pre>
  
  <p>The problem is that whether the <strong>youtube</strong> is found or not the NOT FOUND if condition always return true and the default video URL is opened where as it should only open if youtube tab is not found. I think the Last if condition is not at the right place, any idea?</p>