I spent the last three days trying to get this work, so please do not respond with a link to the chrome API or something like that.
I am developing a Chrome extension that integrates with the mySql database to get the user's favorite websites, as well as the username / password for each of these sites (say fbooker facebook fbus, google gguser ggpass ...)
Thus, the purpose of the expansion is to open a new tab for each website and login.
I have established a connection with the database and I can successfully open new tabs with websites, but they put me on the insertion of the username and password on each website. My problem is that I cannot use document.getElementsById ('input') ... because it returns the elements to me in a popup, not a web page.
So, I read about chrome.tabs.executeScript () and I'm trying to use it (it seems like this is what I need to use to access the DOM of the web page).
So, I'm using something like:
chrome.tabs.create({"url": web[i],"selected":false},function(tab) { chrome.tabs.executeScript(tab.id, {file:"write.js"}, function(){ }); });
And "write.js" should do autocomplete.
So here are my problems:
I have a โwarningโ (โI amโ); the message is inside write.js and it is never displayed (so the rest of the function is never called). (I found this "write.js" function on the Internet).
And here I will post parts of my popup html, manifest and js, maybe I need to change something because I tried what I saw in most examples and it does not work for me.
manifest.json:
{ "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://*/*" ] }
consulta_empleados.html (popup):
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Consulta Registro con AJAX</title> <script src="ajax.js"></script> </head> <body> <form name="form1" method="post" > <label> <div align="center">Email<br> <input type="text" name="email" id="email"> </div> </label> <p align="center"> <label> <input type="submit" name="open" id="open" value="Log In" onClick="runScript()"> </label> </p> </form> <div id="resultado"></div> <div id="prova"></div> </body> </html>
file ajax.js:
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<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();
Thanks in advance.