This guide walks you through the process of creating a simple Chrome extension. You'll learn how to set up your development environment, write the necessary code, and test your extension in the Chrome browser.
Before you start, make sure you have the following:
- Basic knowledge of HTML, CSS, and JavaScript
- A code editor (e.g., VS Code, Sublime Text)
- Google Chrome browser installed
Your project directory should look like this:
my-chrome-extension/
│
├── manifest.json
├── popup.html
├── popup.js
├── icon16.png
├── icon48.png
└── icon128.png
Create a new directory for your Chrome extension:
mkdir my-chrome-extension
cd my-chrome-extension
The manifest.json
file contains metadata about your extension. Create a manifest.json
file in your project directory with the following content:
{
"manifest_version": 3,
"name": "My Chrome Extension",
"version": "1.0",
"description": "A basic example Chrome extension.",
"action": {
"default_popup": "popup.html",
"default_icon": {
"16": "icon16.png",
"48": "icon48.png",
"128": "icon128.png"
}
},
"permissions": [
"storage",
"activeTab"
]
}
Create a popup.html
file with the following content:
<!DOCTYPE html>
<html>
<head>
<title>My Chrome Extension</title>
<style>
body { font-family: Arial, sans-serif; }
#content { padding: 20px; }
</style>
</head>
<body>
<div id="content">
<h1>Hello, world!</h1>
<button id="myButton">Click me</button>
</div>
<script src="popup.js"></script>
</body>
</html>
Create a popup.js
file with the following content:
document.getElementById('myButton').addEventListener('click', () => {
alert('Button clicked!');
});
Add icons for your extension in the following sizes: 16x16, 48x48, and 128x128 pixels. Name them icon16.png
, icon48.png
, and icon128.png
respectively, and place them in the project directory.
- Open Chrome and navigate to
chrome://extensions/
. - Enable "Developer mode" using the toggle switch in the top right.
- Click "Load unpacked" and select your extension's root directory.
Your extension should now be loaded in Chrome. Click on the extension icon in the toolbar to open the popup and test the functionality.
- Chrome Extension Documentation
- Chrome Extensions Samples
- MDN Web Docs: Getting started with Chrome Extensions
0 Comments