The extension works in 3 simple steps:
- Detect - Checks the website URL to identify which login portal you're on
- Find - Searches the page HTML to find the username, password, and submit button fields
- Fill - Puts your credentials into those fields and clicks submit
If any of these steps fail, the auto-login won't work.
Every login form has HTML elements. For example:
<input type="text" id="username" placeholder="Enter username">
<input type="password" id="password" placeholder="Enter password">
<button id="loginBtn">Login</button>Each element has attributes that identify it:
id- Unique identifier (like an ID card)name- Field nameplaceholder- Hint text shown in the fieldclass- CSS class for stylingtype- What kind of input (text, password, checkbox, etc.)
The extension uses these attributes as a "search address" to locate fields on the page:
// "Find an input with id='username'"
document.querySelector('#username')
// "Find an input with name='pwd'"
document.querySelector('input[name="pwd"]')
// "Find the first password input"
document.querySelector('input[type="password"]')Reason 1: Wrong Selector
- The extension is looking for
#usernamebut the actual field is#loginId - The field exists, but the extension can't find it
Reason 2: Fields Don't Exist Yet
- The page is still loading
- JavaScript on the page hasn't created the fields yet
- The extension tries to fill fields that aren't there
Reason 3: Wrong Website
- The extension only works on websites it's configured for
- You need to add the website to the manifest first
- Inspect the page - Look at the HTML to find field selectors
- Write a detector - Add code to check if you're on that website
- Write a filler - Add code to fill the fields with your credentials
- Register the website - Tell the extension it can access that domain
Every login portal needs this pattern in content-script.js:
// Step 1: Detect (check the URL)
if (window.location.href.includes('example-site.com')) {
// Step 2: Find (locate the fields)
let username = document.querySelector('#YOUR_USERNAME_SELECTOR');
let password = document.querySelector('#YOUR_PASSWORD_SELECTOR');
let button = document.querySelector('#YOUR_BUTTON_SELECTOR');
// Step 3: Fill and Submit
if (username && password && button) {
username.value = 'YOUR_USERNAME_VALUE';
password.value = 'YOUR_PASSWORD_VALUE';
button.click();
}
return;
}- Visit the website you want to add
- Right-click on the username field
- Select "Inspect" (or press F12)
Look at the HTML code in the Inspector window. Find:
- Username field - What are its
id,name,placeholder, orclass? - Password field - Same as above
- Submit button - What is its
id,name, or text content?
Use what you found to create a selector:
If the HTML is: <input id="user" type="text">
Write: document.querySelector('#user')
If the HTML is: <input name="email" type="text">
Write: document.querySelector('input[name="email"]')
If the HTML is: <button>Sign In</button>
Write: document.querySelector('button')
// By ID (most reliable)
document.querySelector('#elementId')
document.getElementById('elementId')
// By Name
document.querySelector('input[name="fieldName"]')
// By Type
document.querySelector('input[type="password"]')
// By Class
document.querySelector('.className')
// By Placeholder Text
document.querySelector('input[placeholder*="word"]')
// Any Button
document.querySelector('button')
// First Input
document.querySelector('input')After adding a new website:
- Go to
chrome://extensions/ - Find the extension
- Click the Reload button ↻
- Visit the login page
- Open DevTools (F12) → Console
- Look for error messages or success logs
Problem: Fields are found but not filled
- Solution: Check if the website uses JavaScript to validate inputs. You might need to dispatch more events like 'blur' or 'change'
Problem: Form doesn't submit
- Solution: The button selector might be wrong. Try clicking it manually to verify it's the right button
Problem: Extension runs but shows "Failed to find fields"
- Solution: Your selectors don't match the actual HTML. Use Inspect again and verify the
id,name, etc.
Problem: Nothing happens at all
- Solution: The website URL might not be in
manifest.jsonhost_permissions. Add it.
| Concept | Meaning |
|---|---|
| DOM | The HTML structure of a webpage |
| Selector | A way to find an element in the HTML |
| querySelector | A function to find an element using a selector |
| Event | Something that happens (user types, clicks, form submits) |
| dispatchEvent | Simulating an event to trigger validation/changes |
If you:
- Can't find the right selectors after inspecting
- Understand the concept but unsure about syntax
- Need support for a new website
Share:
- The website URL
- Screenshot of the HTML (from Inspect)
- What you've tried so far