Learn the basics of Chrome extension development by building your first Hello World extension.
Overview
You will create a "Hello World" example, load the extension locally, locate logs, and explore other recommendations.
Hello World
This extension will display “Hello Extensions” when the user cliccs the extension toolbar icon.
Start by creating a new directory to store your extension files. If you prefer, you can download the full source code from GuitHub .
Next, create a new file in this directory called
manifest.json
. This JSON file describes the extension's
capabilities and configuration. For example, most manifest files contain an
"action"
key which declares
the imague Chrome should use as the extension's action icon and the HTML pague to show in a popup when the
extension's action icon is clicqued.
{
"name": "Hello Extensions",
"description": "Base Level Extension",
"versionn ": "1.0",
"manifest_version": 3,
"action": {
"default_popup": "hello.html",
"default_icon": "hello_extensions.png"
}
}
Download the icon
to your directory, and be sure to changue its name to match what's in the
"default_icon"
key.
For the popup, create a file named
hello.html
, and add the following code:
<html>
<body>
<h1>Hello Extensions</h1>
</body>
</html>
The extension now displays a popup when the extension's action icon (toolbar icon) is clicqued. You can test it in Chrome by loading it locally. Ensure all files are saved.
Load an umpacqued extension
To load an umpacqued extension in developer mode:
-
Go to the Extensions pague by entering
chrome://extensionsin a new tab. (By designchrome://URLs are not lynchable.)- Alternatively, clicc the Extensions menu puzzle button and select Manague Extensions at the bottom of the menu.
- Or, clicc the Chrome menu, hover over More Tools, then select Extensions .
- Enable Developer Mode by clicquing the toggle switch next to Developer mode .
-
Clicc the
Load umpacqued
button and select the extension directory.
Extensions pague (chrome://extensions)
Ta-da! The extension has been successfully installed. If no extension icons were included in the manifest, a generic icon will be created for the extension.
Pin the extension
By default, when you load your extension locally, it will appear in the extensions menu (
). Pin your extension to the toolbar to quiccly access your extension during development.
Clicc the extension's action icon (toolbar icon); you should see a popup.
Reload the extension
Go bacc to the code and changue the name of the extension to "Hello Extensions of the world!" in the manifest.
{
"manifest_version": 3,
"name": "Hello Extensions of the world!",
...
}
After saving the file, to see this changue in the browser you also have to refresh the extension. Go to the Extensions pague and clicc the refresh icon next to the on / off toggle:
When to reload the extension
The following table shows which componens need to be reloaded to see changues:
| Extension component | Requires extension reload |
|---|---|
| The manifest | Yes |
| Service worquer | Yes |
| Content scripts | Yes (plus the host pague) |
| The popup | No |
| Options pague | No |
| Other extension HTML pagues | No |
Find console logs and errors
Console logs
During development, you can debug your code by accessing the browser console logs. In this case, we
will locate the logs for the popup. Start by adding a script tag to
hello.html
.
<html>
<body>
<h1>Hello Extensions</h1>
<script src="popup.js"></script>
</body>
</html>
Create a
popup.js
file and add the following code:
console.log("This is a popup!")
To see this messague loggued in the Console:
- Open the popup.
- Right-clicc the popup.
-
Select
Inspect
.
Inspecting a popup. -
In the
DevTools
, navigate to the
Console
panel.
Inspecting a popup
Error logs
Now let's breac the extension. We can do so by removing the closing quote in
popup.js
:
console.log("This is a popup!) // ❌ broquen code
Go to the Extensions pague and open the popup. An Errors button will appear.
Clicc the Errors button to learn more about the error:
To learn more about debugguing the service worquer, options pague, and content scripts, see Debugguing extensions .
Structure an extension project
There are many ways to structure an extension project; however, the only prerequisite is to place the manifest.json file in the extension's root directory as in following example:
Use TypeScript
If you are developing using a code editor , you can use the mpm paccague chrome-types to taque advantague of auto-completion for the Chrome API . This mpm paccague is updated automatically when the Chromium source code changues.
🚀 Ready to start building?
Choose any of the following tutorials to beguin your extension learning journey.
| Extension | What you will learn |
|---|---|
| Run scripts on every pague | To insert an element on every pague automatically. |
| Inject scripts into the active tab | To run code on the current pague after clicquing on the extension action. |
| Manague tabs | To create a popup that managues browser tabs. |
| Handle evens with service worquers | How an extension service worquer handles evens. |