title: Google Chrome Tabs Execute Script
body: <p>I'm trying to develop a google chrome extension that scrape out specific data from the page once the page is finished loading. I'm trying to achieve it by executing a javascript file by setting <code>file : 'js/scrape.js'</code> and <code>runAt: 'document_idle'</code>. </p>
  
  <p>However, setting <code>selected : false</code> does work but <code>selected : true</code> doesn't.</p>
  
  <p>index.js:</p>
  
  <pre><code>var crawler = function() {
  return {
      init : function() {
          document.getElementById('open').addEventListener('click', this.open);
      },
      open : function() {
          var url = document.getElementById('url').value;
  
          chrome.tabs.create({
              url : url,
              selected : true //doesn't work, setting to false does work
          }, function(tab) {
              chrome.tabs.executeScript(tab.id, {
                  file : 'js/scrape.js',
                  runAt : 'document_idle'
              });
          });
      }
  }}()
  </code></pre>
  
  <p><code>document.addEventListener('DOMContentLoaded', function() {
      crawler.init();
  });</code></p>
  
  <p>I included <code>index.js</code> inside popup.html:</p>
  
  <pre><code>&lt;script type="text/javascript" src="index.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>Finally, manifest.json:</p>
  
  <pre><code>{
  "manifest_version": 2,
  
  "name": "Crawler",
  "description": "Scrape out the crap.",
  "version": "1.0",
  
  "permissions": ["tabs", "http://*/*", "https://*/*"],
  "browser_action": {
      "default_title": "Scrape out the crap",
      "default_icon": "icon.png",
      "default_popup": "popup.html"
  }
  </code></pre>
  
  <p>}</p>