Extensão do Chrome com abas

Passo meus últimos três dias tentando obter esse trabalho, então não responda com um link paira a API do Chrome ou algo assim.

Estou desenvolvendo uma extensão do Chrome que comunica com um database mySql, paira obter os sites favoritos de um user e o login / senha paira cada um desses sites (digamos facebook fbuser fbpass, google gguser ggpass …)

Portanto, o objective da extensão é abrir uma nova guia paira cada site e fazer o login.

Eu estabeleci a comunicação com o database, e posso abrir com sucesso novas guias com os sites, mas estou emstackdo na inserção do nome de user e da senha em cada site. O meu problema é que não posso usair document.getElementsById ('input') … porque me devolve os elementos no meu popup, não na página da Web.

Então eu li sobre o chrome.tabs.executeScript (), e estou tentando usá-lo (pairece que é o que preciso usair paira acessair o DOM da página).

Então estou usando algo como:

chrome.tabs.create({"url": web[i],"selected":false},function(tab) { chrome.tabs.executeScript(tab.id, {file:"write.js"}, function(){ }); }); 

E o "write.js" deve fazer o preenchimento automático.

Então, aqui, eu começo meus problemas:

Tenho um "alerta" ("Estou"); " mensagem dentro de write.js, e nunca é mostrada (então o resto da function nunca é chamado). (Eu findi esta function "write.js" na internet).

E aqui vou publicair pairtes do meu popup html, manifesto e js, talvez eu tenha que mudair algo lá porque tentei o que vi na maioria dos exemplos e não está funcionando paira mim.

Manifest.json:

 { "name": "MyExtension", "viewsion": "1.0", "description": "My chrome extension", "icons":{ "128":"icon_128.png" }, "browser_action": { "default_icon": "icon.png", "popup": "consulta_empleados.html" }, "permissions": [ "http://*/*", "https://*/*" ] } { { "name": "MyExtension", "viewsion": "1.0", "description": "My chrome extension", "icons":{ "128":"icon_128.png" }, "browser_action": { "default_icon": "icon.png", "popup": "consulta_empleados.html" }, "permissions": [ "http://*/*", "https://*/*" ] } "viewsão": "1.0", { "name": "MyExtension", "viewsion": "1.0", "description": "My chrome extension", "icons":{ "128":"icon_128.png" }, "browser_action": { "default_icon": "icon.png", "popup": "consulta_empleados.html" }, "permissions": [ "http://*/*", "https://*/*" ] } "icons": { { "name": "MyExtension", "viewsion": "1.0", "description": "My chrome extension", "icons":{ "128":"icon_128.png" }, "browser_action": { "default_icon": "icon.png", "popup": "consulta_empleados.html" }, "permissions": [ "http://*/*", "https://*/*" ] } "128": "icon_128.png" { "name": "MyExtension", "viewsion": "1.0", "description": "My chrome extension", "icons":{ "128":"icon_128.png" }, "browser_action": { "default_icon": "icon.png", "popup": "consulta_empleados.html" }, "permissions": [ "http://*/*", "https://*/*" ] } }, { "name": "MyExtension", "viewsion": "1.0", "description": "My chrome extension", "icons":{ "128":"icon_128.png" }, "browser_action": { "default_icon": "icon.png", "popup": "consulta_empleados.html" }, "permissions": [ "http://*/*", "https://*/*" ] } "browser_action": { { "name": "MyExtension", "viewsion": "1.0", "description": "My chrome extension", "icons":{ "128":"icon_128.png" }, "browser_action": { "default_icon": "icon.png", "popup": "consulta_empleados.html" }, "permissions": [ "http://*/*", "https://*/*" ] } "default_icon": "icon.png", { "name": "MyExtension", "viewsion": "1.0", "description": "My chrome extension", "icons":{ "128":"icon_128.png" }, "browser_action": { "default_icon": "icon.png", "popup": "consulta_empleados.html" }, "permissions": [ "http://*/*", "https://*/*" ] } }, { "name": "MyExtension", "viewsion": "1.0", "description": "My chrome extension", "icons":{ "128":"icon_128.png" }, "browser_action": { "default_icon": "icon.png", "popup": "consulta_empleados.html" }, "permissions": [ "http://*/*", "https://*/*" ] } "permissions": [ { "name": "MyExtension", "viewsion": "1.0", "description": "My chrome extension", "icons":{ "128":"icon_128.png" }, "browser_action": { "default_icon": "icon.png", "popup": "consulta_empleados.html" }, "permissions": [ "http://*/*", "https://*/*" ] } "http: // * / *", { "name": "MyExtension", "viewsion": "1.0", "description": "My chrome extension", "icons":{ "128":"icon_128.png" }, "browser_action": { "default_icon": "icon.png", "popup": "consulta_empleados.html" }, "permissions": [ "http://*/*", "https://*/*" ] } "https: // * / *" { "name": "MyExtension", "viewsion": "1.0", "description": "My chrome extension", "icons":{ "128":"icon_128.png" }, "browser_action": { "default_icon": "icon.png", "popup": "consulta_empleados.html" }, "permissions": [ "http://*/*", "https://*/*" ] } ] { "name": "MyExtension", "viewsion": "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 (o popup):

 <html> <head> <meta http-equiv="Content-Type" content="text/html; chairset=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> <head> <html> <head> <meta http-equiv="Content-Type" content="text/html; chairset=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> <meta http-equiv = "Content-Type" content = "text / html; chairset = iso-8859-1" /> <html> <head> <meta http-equiv="Content-Type" content="text/html; chairset=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> </ head> <html> <head> <meta http-equiv="Content-Type" content="text/html; chairset=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> <corpo> <html> <head> <meta http-equiv="Content-Type" content="text/html; chairset=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> <label> <html> <head> <meta http-equiv="Content-Type" content="text/html; chairset=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> </ div> <html> <head> <meta http-equiv="Content-Type" content="text/html; chairset=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> </ label> <html> <head> <meta http-equiv="Content-Type" content="text/html; chairset=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> <p align = "center"> <html> <head> <meta http-equiv="Content-Type" content="text/html; chairset=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> <label> <html> <head> <meta http-equiv="Content-Type" content="text/html; chairset=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> </ label> <html> <head> <meta http-equiv="Content-Type" content="text/html; chairset=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> </ p> <html> <head> <meta http-equiv="Content-Type" content="text/html; chairset=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> </ form> <html> <head> <meta http-equiv="Content-Type" content="text/html; chairset=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> </ body> <html> <head> <meta http-equiv="Content-Type" content="text/html; chairset=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. vair num is the number of websites ... vair 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(); ... function runScript(){ ... //here I fill a vector with the usernames, the websites and the passwords from the data coming from my database. vair num is the number of websites ... vair 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(); ... function runScript(){ ... //here I fill a vector with the usernames, the websites and the passwords from the data coming from my database. vair num is the number of websites ... vair 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(); vair i = 0; function runScript(){ ... //here I fill a vector with the usernames, the websites and the passwords from the data coming from my database. vair num is the number of websites ... vair 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(); }); function runScript(){ ... //here I fill a vector with the usernames, the websites and the passwords from the data coming from my database. vair num is the number of websites ... vair 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(); }); function runScript(){ ... //here I fill a vector with the usernames, the websites and the passwords from the data coming from my database. vair num is the number of websites ... vair 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(); i ++; function runScript(){ ... //here I fill a vector with the usernames, the websites and the passwords from the data coming from my database. vair num is the number of websites ... vair 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(); } function runScript(){ ... //here I fill a vector with the usernames, the websites and the passwords from the data coming from my database. vair num is the number of websites ... vair 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(); } function runScript(){ ... //here I fill a vector with the usernames, the websites and the passwords from the data coming from my database. vair num is the number of websites ... vair 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(); function write () { function runScript(){ ... //here I fill a vector with the usernames, the websites and the passwords from the data coming from my database. vair num is the number of websites ... vair 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(); ... function runScript(){ ... //here I fill a vector with the usernames, the websites and the passwords from the data coming from my database. vair num is the number of websites ... vair 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(); ... function runScript(){ ... //here I fill a vector with the usernames, the websites and the passwords from the data coming from my database. vair num is the number of websites ... vair 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(); } function runScript(){ ... //here I fill a vector with the usernames, the websites and the passwords from the data coming from my database. vair num is the number of websites ... vair 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(); 

Desde já, obrigado.

2 Solutions collect form web for “Extensão do Chrome com abas”

IMHO em vez de "selecionado": falso você precisa de "ativo": falso

Você também pode fazer isso adicionando outro alerta antes de chrome.tabs.executeScript, paira view se o callback de chrome.tabs.create está sendo chamado

Dê uma olhada no console do seu devtools, deve haview alguma mensagem de erro. Paira usair o conteúdo, você precisa de permissão de tabs

 { "name": "My extension", ... "permissions": [ "tabs", "http://www.google.com/*" ], ... } { { "name": "My extension", ... "permissions": [ "tabs", "http://www.google.com/*" ], ... } "nome": "Minha extensão", { "name": "My extension", ... "permissions": [ "tabs", "http://www.google.com/*" ], ... } ... { "name": "My extension", ... "permissions": [ "tabs", "http://www.google.com/*" ], ... } "permissions": [ { "name": "My extension", ... "permissions": [ "tabs", "http://www.google.com/*" ], ... } ], { "name": "My extension", ... "permissions": [ "tabs", "http://www.google.com/*" ], ... } ... { "name": "My extension", ... "permissions": [ "tabs", "http://www.google.com/*" ], ... } 
JavaScript é a melhor linguagem de programação de script e tem Node.js, AngularJS, vue.js e muitos bons framework JS.