This tutorial walks you through creating a simple extension. To complete this tutorial, you must have Windows. (Linux and Mac don't yet support extensions.)
Get your browser ready
To develop extensions for Google Chrome, you'll need to subscribe to the dev channel of Google Chrome for Windows.
Note: This tutorial requires Windows. You can try it on Linux and OS X, and it may work, but in general the extensions support is quite a bit less stable on those platforms. We're working hard to bring them up to speed.
Create and load an extension
In this section, you'll write a toolstrip — an extension that puts a bit of UI into the toolbar at the bottom of the Google Chrome window.
-
Create a folder somewhere on your computer to contain your extension's code.
We'll assume the folder is located at
c:\myext
, but it can be anywhere. -
Inside your extension's folder,
create a text file called
manifest.json
, and put this in it:{ "name": "My First Extension", "version": "1.0", "description": "The first extension that I made.", "toolstrips": [ "my_toolstrip.html" ] }
-
In the same folder, create a text file called
my_toolstrip.html
, and put this in it:<div class="toolstrip-button"> <span>Hello, World!</span> </div>
- Load the extension.
-
Bring up the Extensions management page by going to this URL:
chrome://extensions
- Click the Load unpacked extension button. A file dialog appears.
-
In the file dialog,
navigate to your extension's directory
(
c:\myext
, for example) and click the OK button.
-
Bring up the Extensions management page by going to this URL:
If your extension is valid, information about it appears in the Installed extensions part of the Extensions page, as the following screenshot shows.
You should see the UI for your extension at the bottom left of the browser, looking something like this:
default appearance | initial onhover appearance | final onhover appearance |
Your extension's button is automatically styled to look like it belongs in the browser. If you put the cursor over the button, the button gets a nice, rounded edge, just like the buttons in the bookmark bar. After a while, a tooltip comes up, identifying the extension.
[PENDING: troubleshooting info should go here. what are symptoms of common typos, including misnamed files? what are the symptoms if you don't have the dev channel?]
Add code to the extension
In this step, you'll make your extension do something besides just look good.
-
Inside your extension's folder, create a text file called
hello_world.html
, and add the following code to it:CSS and JavaScript code for hello_world
-
Edit
my_toolstrip.html
, so that it has the following code:<div class="toolstrip-button" onclick="window.open('hello_world.html')"> <span>Hello, World!</span> </div>
- Restart the browser to load the new version of the extension.
- Click the button.
A window should come up that displays
hello_world.html
.
It should look something like this:
If you don't see that page, try the instructions again, following them exactly. Don't try loading an HTML file that isn't in the extension's folder — it won't work!
Now what?
[PENDING: Summarize what we did, what it means, what else we would've done if this were a real extension (e.g. package it), and where to find more information.]
- Subscribe to chromium-extensions to keep up to date with the latest news
- Learn how to debug your extension by following the debugging tutorial
- Look at some sample extensions
- Learn more about toolstrips
-
Package
your extension into a
.crx
file so you can share it with your friends