I want to develop a chrome extension for auto form fill up here I decribe the scnerio…
- User
I want to develop a chrome extension for auto form fill up here I decribe the scnerio what I want Example: at first I save data like personal information of 10 people, when I go to my deceie page then I click on extention (which is pin is chrome) then show the all info list and I choose one and it fill the all input field or date field etc.
how can do it, give me process and code
Assistant
To create a Chrome extension for auto-form filling with saved personal data, follow these steps:
Step 1: Project Structure
form-filler/ │ ├── manifest.json ├── popup.html ├── popup.js ├── background.js ├── content.js └── styles.css (optional)
Step 2:
manifest.json{ "manifest_version": 3, "name": "Auto Form Filler", "version": "1.0", "description": "Auto-fill forms with saved personal data.", "permissions": ["activeTab", "scripting", "storage"], "background": { "service_worker": "background.js" }, "action": { "default_popup": "popup.html", "default_icon": "icon.png" }, "icons": { "128": "icon.png" } }
Step 3:
popup.html(UI for Saving/Selecting Data)<!DOCTYPE html> <html> <head> <style> body { width: 300px; padding: 10px; font-family: sans-serif; } input { width: 100%; margin: 5px 0; } button { margin-top: 10px; } ul { list-style: none; padding-left: 0; cursor: pointer; } li:hover { background: #f0f0f0; } </style> </head> <body> <h3>Save Profile</h3> <input type="text" id="name" placeholder="Name"> <input type="text" id="email" placeholder="Email"> <input type="text" id="address" placeholder="Address"> <input type="date" id="dob" placeholder="DOB"> <button id="save">Save</button> <h3>Saved Profiles</h3> <ul id="profiles"></ul> <script src="popup.js"></script> </body> </html>
Step 4:
popup.js(Handle Saving and Selecting Data)document.getElementById("save").addEventListener("click", () => { const profile = { name: document.getElementById("name").value, email: document.getElementById("email").value, address: document.getElementById("address").value, dob: document.getElementById("dob").value }; chrome.storage.local.get({ profiles: [] }, (result) => { result.profiles.push(profile); chrome.storage.local.set({ profiles: result.profiles }); renderProfiles(result.profiles); }); }); function renderProfiles(profiles) { const container = document.getElementById("profiles"); container.innerHTML = ""; profiles.forEach((profile, index) => { const li = document.createElement("li"); li.textContent = `${profile.name} - ${profile.email}`; li.addEventListener("click", () => { chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => { chrome.scripting.executeScript({ target: { tabId: tabs[0].id }, func: fillForm, args: [profile] }); }); }); container.appendChild(li); }); } // Load saved profiles chrome.storage.local.get({ profiles: [] }, (result) => { renderProfiles(result.profiles); });
Step 5:
background.js(Manage Storage)// Not required for basic functionality, but useful for advanced logic. // You can leave this file empty or remove it if not needed.
Step 6:
content.js(Auto-Fill Logic)function fillForm(profile) { const fillInput = (selector, value) => { const input = document.querySelector(selector); if (input && value) input.value = value; }; // Match input fields by common attributes fillInput("input[name='name'], input[id='name']", profile.name); fillInput("input[name='email'], input[id='email']", profile.email); fillInput("input[name='address'], input[id='address']", profile.address); fillInput("input[name='dob'], input[id='dob']", profile.dob); // Trigger events to update frameworks like React ["input", "change"].forEach(eventType => { const event = new Event(eventType, { bubbles: true }); Object.values(document.querySelectorAll("input")).forEach(input => { input.dispatchEvent(event); }); }); }
Step 7: Add an Icon (
icon.png)Use any 128x128 PNG image (e.g., a simple pencil icon).
How to Use
-
Load the extension in Chrome:
- Go to
chrome://extensions/, enable "Developer mode". - Click "Load unpacked" and select the
form-fillerfolder.
- Go to
-
Save profiles:
- Click the extension icon → Enter personal data → Click "Save".
-
Auto-fill forms:
- Open a webpage with a form → Click the extension icon → Select a saved profile.
Optional Improvements
- Add edit/delete functionality for profiles.
- Support more field types (e.g., phone, city).
- Use
chrome.identityfor secure storage. - Add fuzzy matching for form fields.
Let me know if you need help with advanced features!
-