title: Chrome extension with tabs
body: <p>I have been spending my last three days on trying to get this work, so please don't reply with a link to the chrome API or something like that.</p>
  
  <p>I'm developing a Chrome extension that comunicates with a mySql database, to get the favorite websites of a user, and the login/password for each of this websites (let's say facebook fbuser fbpass, google gguser ggpass...)</p>
  
  <p>So the goal of the extension is to open a new tab for each website, and do the login.</p>
  
  <p>I've stablished the communication with the database, and I can succesfully open new tabs with the websites, but I'm stacked on inserting the username and the password on each website. My problem is that I cannot use document.getElementsById('input')... because it returns me the elements on my popup, not on the webpage.</p>
  
  <p>So I've read about chrome.tabs.executeScript(), and I'm trying to use it (it seems that is what I need to use to access the DOM of the webpage).</p>
  
  <p>So I'm using something like:</p>
  
  <pre><code>chrome.tabs.create({"url": web[i],"selected":false},function(tab) {
          chrome.tabs.executeScript(tab.id, {file:"write.js"}, function(){
          });
          });
  </code></pre>
  
  <p>And the "write.js" must do the autofill.</p>
  
  <p>So here starts my problems:</p>
  
  <p>I have an "alert("I'm in");" message inside write.js, and it is never shown (so the rest of the function is never called). (I found this function "write.js" in internet).</p>
  
  <p>And here I'll post parts of my popup html, manifest and the js, maybe I have to change something there because I've tried what I've seen in most examples and is not working for me.</p>
  
  <p>Manifest.json:</p>
  
  <pre><code>{
    "name": "MyExtension",
    "version": "1.0",
    "description": "My chrome extension",
    "icons":{
        "128":"icon_128.png"
    },
    "browser_action":   {
        "default_icon": "icon.png",
        "popup": "consulta_empleados.html"
    },
    "permissions": [
      "http://*/*",
      "https://*/*"
    ]
  }
  </code></pre>
  
  <p>consulta_empleados.html (the popup):</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;
  &lt;title&gt;Consulta Registro con AJAX&lt;/title&gt;
  &lt;script src="ajax.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;form name="form1" method="post" &gt;
    &lt;label&gt;
    &lt;div align="center"&gt;Email&lt;br&gt;
      &lt;input type="text" name="email" id="email"&gt;
    &lt;/div&gt;
    &lt;/label&gt;
    &lt;p align="center"&gt;
      &lt;label&gt;
      &lt;input type="submit" name="open" id="open" value="Log In" onClick="runScript()"&gt;
      &lt;/label&gt;
    &lt;/p&gt;
  &lt;/form&gt;
  &lt;div id="resultado"&gt;&lt;/div&gt;
  &lt;div id="prova"&gt;&lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>file ajax.js:</p>
  
  <pre><code>function runScript(){
        ...
        //here I fill a vector with the usernames, the websites and the passwords from the data coming from my database. var num is the number of websites
        ...
    var i=0;
    while(i&lt;num){
      chrome.tabs.create({"url": web[i],"selected":false},function(tab) {
          chrome.tabs.executeScript(tab.id, {file: "write.js"}, function(){
  
          });
          });
      i++;
    }
  
  }
  
  write.js:
  function write() {
       ...
        alert("I'm in");
       ...      
  } 
  write();
  </code></pre>
  
  <p>Thanks in advance.</p>