Create a Password Safe Chrome Extension
In this article
A password safe Chrome extension helps users store, generate, and autofill passwords securely within the browser. By building your own extension, you control how data is stored and accessed, ensuring greater transparency and privacy than some third-party tools. This guide walks you through creating a basic but functional password safe extension using HTML, JavaScript, and the Chrome Extension API. The extension will allow users to save login credentials, retrieve them, and autofill forms—all within the browser's secure environment.
What You'll Need
- A computer with Chrome browser installed
- Basic knowledge of HTML, CSS, and JavaScript
- A text editor (e.g., VS Code, Sublime Text)
- Understanding of Chrome's extension security model
Step-by-Step
- Create a new project folder on your computer. Name it
password-safe-extension. This will hold all your extension files. - Inside the folder, create a file named
manifest.json. This file tells Chrome about your extension. Add the following content:
This sets up the extension with storage access and a popup interface.{ "manifest_version": 3, "name": "Password Safe", "version": "1.0", "description": "A simple password manager extension", "permissions": [ "storage" ], "action": { "default_popup": "popup.html", "default_title": "Password Safe" }, "host_permissions": [ "<all_urls>" ] } - Create
popup.htmlin the same folder. This is the UI users see when clicking the extension icon. Add:
This creates a clean, functional popup with input fields and buttons.<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Password Safe</title> <style> body { width: 300px; padding: 10px; font-family: sans-serif; } input, button { width: 100%; margin: 5px 0; padding: 8px; } </style> </head> <body> <h3>Save Password</h3> <input type="text" id="site" placeholder="Website"> <input type="text" id="username" placeholder="Username"> <input type="password" id="password" placeholder="Password"> <button id="saveBtn">Save</button> <button id="generateBtn">Generate Password</button> <script src="popup.js"></script> </body> </html> - Create
popup.jsto handle saving and generating passwords. Add:
This script saves credentials using Chrome'sdocument.getElementById('saveBtn').addEventListener('click', () => { const site = document.getElementById('site').value; const username = document.getElementById('username').value; const password = document.getElementById('password').value; if (!site || !username || !password) { alert('Please fill all fields'); return; } chrome.storage.sync.set({ [site]: { username, password } }, () => { alert('Password saved!'); }); }); document.getElementById('generateBtn').addEventListener('click', () => { const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%&'; let pass = ''; for (let i = 0; i < 12; i++) { pass += chars.charAt(Math.floor(Math.random() * chars.length)); } document.getElementById('password').value = pass; });storage.syncAPI and generates a random 12-character password. - To enable autofill on web forms, create
content.jsin the project folder. Add:
This runs when a page loads and checks if credentials exist for the current site.chrome.storage.sync.get(null, (items) => { const currentUrl = window.location.origin; if (items[currentUrl]) { const { username, password } = items[currentUrl]; // Try to autofill common login fields const userFields = document.querySelectorAll('input[type="text"], input[type="email"]'); const passFields = document.querySelectorAll('input[type="password"]'); userFields.forEach(field => { if (!field.value) field.value = username; }); passFields.forEach(field => { if (!field.value) field.value = password; }); } }); - Add the content script to
manifest.jsonunder a new key:
This ensures the script runs on all websites."content_scripts": [ { "matches": ["<all_urls>"], "js": ["content.js"] } ] - Open Chrome and go to
chrome://extensions/. Enable Developer mode using the toggle in the top right. - Click "Load unpacked" and select your
password-safe-extensionfolder. Chrome will load your extension. - Click the puzzle icon in the toolbar, pin your extension, and test it by entering a site, username, and password. Click Save, then visit a login page to see if credentials autofill.
Common Mistakes
- Forgetting to include
"storage"in the permissions array—this prevents saving data. - Using
manifest_version2 instead of 3, which is now required for new extensions. - Not loading the unpacked extension correctly—ensure the folder path is correct and all files are present.
- Assuming passwords are encrypted—Chrome storage is synced but not encrypted by default; this extension stores passwords in plain text.
- Overlooking cross-origin permissions—without
host_permissions, content scripts may not run on all sites.
Tips
- Use
chrome.storage.localinstead ofsyncif you don’t want passwords synced across devices. - Add a master password feature by encrypting stored data with a user-defined key using Web Crypto API.
- Improve the UI with CSS frameworks like Tailwind or Bootstrap for responsiveness.
- Include a password strength meter in the generation tool to guide users.
- Test on multiple sites to verify autofill works with different form structures.
Troubleshooting
If the extension doesn’t load, check the console in chrome://extensions for error messages. Common issues include syntax errors in manifest.json or missing files. If passwords aren’t saving, verify that the site key in storage matches the URL exactly (including http vs https). If autofill doesn’t work, ensure content.js is running by adding a console.log statement and checking the page’s developer console. If the popup closes immediately, avoid using alert() in production—replace with DOM-based messages. Finally, reload the extension after every code change to reflect updates.
Frequently Asked Questions
Is this extension secure?
It stores passwords using Chrome's sync storage, which is protected by your Google account, but not encrypted locally. For better security, add encryption in the code.
Can I use this on other browsers?
Yes, most of the code works in Firefox and Edge, but you may need to adjust the manifest for compatibility.
Why isn’t my password saving?
Check that all fields are filled and that storage permission is in the manifest. Reload the extension after changes.
How do I delete saved passwords?
Add a 'Delete' button in popup.js that uses chrome.storage.sync.remove() with the site URL as the key.
Does this work on mobile Chrome?
No, Chrome extensions are not supported on iOS or Android Chrome browsers.
Can it autofill complex login forms?
Basic forms work well, but complex or dynamically loaded forms may require advanced DOM detection or user interaction.