There are two mistakes:
A key browser_action does not have the script, only browser_style, default_icon, default_title, default_popup, theme_icons.
The file is calling the onload method, after the page is already loaded.
To execute a code by clicking on the extension icon, you need to call an html pop.
Manifest.json
{
"name": "SGIR - Extensão",
"manifest_version": 2,
"version": "1.0",
"description": "Preencher formulários",
"browser_action": {
"default_popup": "popup.html"
},
"permissions": [
"tabs",
"https://www.google.com/"
],
"content_scripts": [{
"js": ["funcao.js"],
"matches": ["https://www.google.com/"]
}]
}
function.js
var ni = document.getElementById("lst-ib");
ni.value = "Alguma coisa!";
popup.html
<!doctype html>
<html>
<head>
<script src="funcao2.js"></script>
</head>
<body></body>
</html>
function 2.js
chrome.tabs.query({active:true,windowType:"normal", currentWindow: true},function(tab){
chrome.tabs.executeScript(tab[0].id, {
"file": "funcao.js"
});
})
Add permission to the URL you want to modify. It can be regex.
I understood his explanation, but even so, when I click on the extension icon nothing happens on the page I’m on, it does not complete the form, in case the text field with id="NI", which may be wrong?
– neto schneider
In the case of inputs, the correct is
ni.value = "Alguma coisa!";.– Valdeir Psr
I tried with "value" too, but nothing happens on the page, it just opens the extension popup...
– neto schneider
@netoschneider I edited my answer. This way it will work either automatically, or by clicking on the extension icon.
– Valdeir Psr
Thank you very much, cleared my doubt!
– neto schneider