How to Build a Chrome Extension From Scratch
In this article
To build a Chrome extension from scratch, create a folder with a manifest.json file, add your HTML, CSS, and JavaScript files, then load the folder as an unpacked extension in Chrome. This guide walks you through each step, from setting up the manifest to testing and packaging your extension for the Chrome Web Store.
What You'll Need
- A computer with Google Chrome installed (any recent version).
- A plain text editor or code editor (e.g., Visual Studio Code, Sublime Text, or even Notepad).
- Basic knowledge of HTML, CSS, and JavaScript.
- A folder on your computer to hold your extension files.
Step-by-Step
- Create a project folder. Make a new folder anywhere on your computer (e.g.,
my-extension). This will contain all your extension files. - Create the manifest file. Inside the folder, create a file named
manifest.json. This JSON file tells Chrome about your extension. A minimal manifest looks like this:
Note: Manifest V3 is the current standard; older V2 is deprecated. Labels and fields can differ slightly by Chrome version, but the core structure is stable.{ "manifest_version": 3, "name": "My Extension", "version": "1.0", "description": "A simple Chrome extension.", "action": { "default_popup": "popup.html" } } - Add a popup HTML file. Create
popup.htmlin the same folder. This is the small window that appears when users click your extension's icon. Example:<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <style> body { width: 200px; padding: 10px; font-family: sans-serif; } </style> </head> <body> <h3>Hello, Extension!</h3> <button id="myButton">Click me</button> <script src="popup.js"></script> </body> </html> - Add JavaScript for interactivity. Create
popup.jsin the folder. For example, to show an alert when the button is clicked:document.getElementById('myButton').addEventListener('click', () => { alert('Button clicked!'); }); - Load the extension in Chrome. Open Chrome and go to
chrome://extensions. Enable "Developer mode" (toggle in the top right). Click "Load unpacked" and select your project folder. Your extension should now appear in the list and its icon in the toolbar. - Test your extension. Click the extension icon to see the popup. If you make changes to the files, return to
chrome://extensionsand click the reload icon on your extension card to apply updates. - Add more features (optional). You can add background scripts, content scripts, or permissions by editing
manifest.json. For example, to run a script on web pages, add acontent_scriptssection. Always test after each change. - Package your extension. When ready, zip the contents of your project folder (not the folder itself). You can also use Chrome's "Pack extension" button in
chrome://extensionsto generate a.crxfile and a private key. For the Chrome Web Store, you need to upload the zip file and pay a one-time developer registration fee.
Common Mistakes
- Incorrect manifest.json syntax. JSON is strict: missing commas, trailing commas, or unquoted keys will break loading. Validate your JSON with an online tool or your editor's linter.
- Forgetting to reload the extension. After editing files, you must reload the extension in
chrome://extensionsto see changes. Simply refreshing the popup won't pick up manifest changes. - Using Manifest V2. Chrome no longer accepts new Manifest V2 extensions in the Web Store. Always start with
"manifest_version": 3. - Missing files or wrong paths. Ensure all files referenced in the manifest (like
popup.html) exist in the folder and paths are correct (case-sensitive). - Overlooking permissions. If your extension needs to access certain APIs or websites, you must declare permissions in the manifest. Request only what you need.
Tips
- Keep your code organized: separate HTML, CSS, and JS into different files.
- Use Chrome's Developer Tools (right-click the popup and select "Inspect") to debug your popup and background scripts.
- Test your extension in different scenarios (e.g., with and without internet) to catch issues early.
- Read the official Chrome extension documentation for up-to-date APIs and best practices.
- Before publishing, write a clear description and provide screenshots to help users understand your extension.
Troubleshooting
If your extension does not load or work as expected, try these steps in order:
- Check for errors in
chrome://extensions. Click the "Errors" button on your extension card to see detailed messages. Fix any syntax errors or missing files. - Reload the extension. Click the reload icon on the extension card. Also, close and reopen the popup.
- Inspect the popup. Right-click the extension icon and choose "Inspect popup" to open DevTools and check for JavaScript errors.
- Verify manifest fields. Ensure
manifest_versionis 3, and all required fields (name, version) are present. Use a JSON validator. - Check permissions. If your extension needs to access a website or API, make sure the necessary permissions are listed in the manifest.
- Restart Chrome. Sometimes a full restart resolves loading issues.
- Reinstall the extension. Remove it from
chrome://extensionsand load it again. This won't delete your files.
If you still have problems, consult the Chrome extension documentation or developer forums for specific error messages.
Frequently Asked Questions
Do I need to know programming to build a Chrome extension?
Yes, basic knowledge of HTML, CSS, and JavaScript is required. The manifest is JSON, which is simple to learn.
Can I build an extension without publishing it to the Chrome Web Store?
Yes, you can load it as an unpacked extension for personal use. However, sharing it with others requires packaging and possibly publishing.
What is the difference between Manifest V2 and V3?
Manifest V3 is the current standard with improved security and performance. V2 is deprecated and no longer accepted for new extensions in the Web Store.
How do I update my extension after publishing?
Increase the version number in manifest.json, re-zip the files, and upload the new package to the Chrome Web Store developer dashboard.
Can I make money from my Chrome extension?
Yes, you can charge for your extension or include ads, but you must comply with Chrome Web Store policies. Payment processing is handled through the store.
Why does my extension icon not appear in the toolbar?
Check that the extension is enabled and pinned. Click the puzzle piece icon in the toolbar and pin your extension.