0

I'm somewhat new to javascript and long story short, I'm trying to build my own autofill for my school login page using a chrome extension.

After looking through the source code and creating an html file copy of the webpage I figured out the username box ID was 'Username' and the password box ID was 'Password' (who would've guessed?) I ran a a test on the fake html page and I got it to put in my saved password and username. However, when I go to try in the chrome extension it won't work.

Here's how my manifest and content script looks:

Manifest:

`content_scripts": [
    {
        "run_at": "document_idle",
        "matches": ["*://elearn.apsu.edu/*"],
        "js": ["content.js"]
    }
    ],
   "permissions": [
   "activeTab", "tabs", "http://elearn.apsu.edu/", "https://elearn.apsu.edu/"
   ]`

My content.js file has this:

`window.onload = function(){ 
document.getElementById("Username").value = "*username*";
document.getElementById("Password").value = "*password*"; };`

I've also tried setting up my content.js like this, but it hasn't worked either:

`document.addEventListener('DOMContentLoaded', info, false);
info = function(){
  document.getElementById("Username").value = "*username*";
  document.getElementById("Password").value = "*password*"; 
};
`

Anyone have some advice that might help?

  • 2
    Your content script is injected at `document_idle` which happens after DOM `onload` event (and after `DOMContentLoaded`). Simply remove the event listener. Another problem is dynamically constructed AJAX-sites which can be solved with a MutationObserver or setInterval check. – wOxxOm Apr 04 '17 at 16:01
  • What *exactly* is shown in the [various appropriate consoles for your extension](http://stackoverflow.com/a/38920982/3773011) when you load and execute your extension? – Makyen Apr 04 '17 at 17:54
  • I looked at the console and the only useful thing I noticed was this error which was directed at my content.js on the document.getElementById("Username").value line: "Uncaught TypeError: Cannot set property 'value' of null at window.onload (content.js:2)" – Samuel Bliss Apr 05 '17 at 12:56

0 Answers0