I recently started learning a little javascript and made a basic chrome extension, but the problem is that it only sometimes works. What I want it to do is replace the text in any input box to be that of the variable specified in the code, and it works, but not all the time. When I load a site, for example google.com, it might work as I type in the search box, but then doesn't if I refresh the page, and then it might works if I refresh again.
here is my code:
manifest.json
{
"manifest_version": 2,
"name": "My Cool Extension",
"version": "0.1",
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": ["jQuery.js", "content.js"]
}
],
"browser_action": {
"default_icon": "icon.png"
}
}
content.js
window.onload = function () {
var inputs = document.getElementsByTagName('input');
for (i = 0; i < inputs.length; i++) {
inputs[i].onkeyup = function () {
var text = "Text to fill in";
this.value = text.substring(0, this.value.length);
};
}
};
I am waiting for the window to fully load before typing. I have also run it on another computer, same problem. Anyone have any ideas?