title: Chrome Extension: create a new tab, wait for it to complete loading, execute a script
body: <p>I have been able to load a new tab but script executes before page load.</p>
  
  <p><strong>manifest.json :</strong></p>
  
  <pre><code>{
    "manifest_version": 2,
    "name": "cpClips",
    "version": "1.0",
    "description": "cpClips extension to download videos from streaming sites.",
    "browser_action": {
      "default_icon": "icon.png"
    },
    "background": {
      "scripts": ["bg.js"],
      "persistent": false
    },
    "permissions": [
      "tabs"
    ]
  }
  </code></pre>
  
  <p><strong>bg.js :</strong></p>
  
  <pre><code>chrome.browserAction.onClicked.addListener(function(activeTab)
  {
      chrome.tabs.create({ url: 'http://127.0.0.1:8000' },function(tab) {
          alert('hi');
  
     });
  
  });
  </code></pre>
  
  <p>I tried using <code>chrome.tabs.executeScript</code> along with <code>chrome.tabs.onUpdated.addListener</code>, but then even the new tab won't open.</p>
  
  <p>An example would be nice.</p>