SpyreStudios

Web Design and Development Magazine

  • Design
  • Showcase
  • Inspirational
  • Tutorials
  • CSS
  • Resources
  • Tools
  • UX
  • More
    • Mobile
    • Usability
    • HTML5
    • Business
    • Freebies
    • Giveaway
    • About SpyreStudios
    • Advertise On SpyreStudios
    • Get In Touch With Us

How to Build a Chrome Extension

December 27, 2017 by Alex Fox

build a chrome extension hero

Google Chrome is the most popular browser on the planet. You use it, your mom uses it, your cat uses it. Sure, it’s got quirks and problems. But if you want to reach a large audience, designing a Google Chrome extension isn’t a bad way to do it. Fortunately, it’s pretty easy to build a Chrome extension.

Chrome extensions are basically web pages. Primarily, they’re Javascript, with some HTML and CSS thrown in and a teaspoonful of JSON. We’ll go through the basic steps to build a Chrome extension, but you can extend this knowledge to just about any of the many powerful functions Google offers. We’ll review the bones that build an extension, and you can flesh it out from there. If you want to check out the documentation to build a Chrome extension, you can find it at Chrome’s Developer Extension Guide.

Build a Chrome Extension: Hello World

A Chrome extension is made of up a couple of files. For our extension, you’ll need a JSON file to tell the extension what to do (manifest.json), an HTML file that shows what the extension loads (popup.html), and an icon to represent the extension in the toolbar (icon.png).

manifest.json is the heart of any Chrome extension. It tells the extension what resources to load and what kinds of actions it can take. Our simple manifest.json looks like so:

{
    "manifest_version": 2,

    "name": "Hello World!", 
    "version": "0.1",
    "description": "My first Chrome extension.",
    "browser_action": {
        "default_icon": "icon.png",
        "default_popup": "popup.html"
    },
    "permissions": [
        "activeTab"
     ]
}

Some fields are fairly self-descriptive. Let’s review the others:

  • manifest_version is required by Google’s extension framework. It must be set to 2 to indicate the current manifest framework.
  • browser action identifies the type of extension you’re building. A browser action extension places a clickable icon in Chrome’s menu bar, allowing the user to interact with your extension and run its contents.
  • default_icon shows the path to the icon. It starts from the extensions directory.
  • default_popup shows the path to the file that will run when the extension is clicked. It will be shown beneath the extension in a popup box.
  • permissions tells the extension where it’s allowed to operate. activeTab is the most common, allowing the extension to access information about the front-most tab.

For our extension, we’ll need to drop that manifest into a folder alongside a file named andicon.png an HTML file named popup.html. If your extension’s HTML file calls any scripts, you’ll need to include a script file in your extension’s directory. Google’s security rules won’t allow you to embed Javascript (or any other script) in the HTML file itself.

Doing the Bare Minimum

We’ll focus on making the most basic possible extension here. Once you’ve got a handle on the basic structure of a Chrome extension, you can use your web developer chops to code up something awesome.

We’ll use the following for our popup.html file:

<!doctype html>
<html>
    <head>
         <title>Hello World</title>
    </head>
    <style type="text/css">
        body {
            margin: 10px;
        }
        h1 {
            font-size: 15px;
            text-align: center;
        }
    </style>
    <body>
        <h1>Hello World!</h1>
    </body>
</html>

All this does is say hello to the user, nothing more. If you want to do anything more complicated involving user interaction, you’ll need to get your Javascript out. Thanks to Google’s extension security rules, if you want to load some Javascript alongside your HTML, you’ll need to present that in a separate file. You can load it in head with the script src tag.

Load Your Extension

Once you’ve finished writing your extension, you can load it into Chrome.

Navigate to chrome://extensions and turn on Developer Mode by ticking the checkbox in the upper right.

Then click the “Load unpacked extension…” button and select the extension’s directory. Chrome will run a basic debug on your manifest.json file to make sure it’s up to snuff. If you make a syntax error or leave out important information, you’ll need to fix it before you can successfully load the extension.

Once the extension is loaded, you’ll see its icon in the menu bar. Now we’re getting places!

Click on the extension to see its (admittedly meager) effect.

As you debug and develop your extension, you can click the “Reload” link below the extension (or press Command-R on Mac and Control-R on Windows) to update its files.

Publish Your Extension to the Chrome Store

Once you’ve finished your extension, you’ll need to upload the finished version to the Chrome store. You’ll need to zip all your files together and then process it through your Chrome developer account. Unfortunately, that can be a little complicated. Google has quite a bit of security on their end. Check out the full instructions for publishing your Google extension here.

Conclusion

Remeber, this is only a very basic guide to creating a Chrome extension. As the Chrome Store shows, you can get far more creative with your content. Once you’ve digested all of this, learn more about Chrome extensions at Google’s Chrome’s Developer Extension Guide.

You might be interested in the following posts as well:

10 Chrome Addons Every Dev Should Have

Useful Chrome Extensions For Designers and Creatives

Web Design Tools for Beginners 2017

Filed Under: Tutorial Tagged With: chrome addons, extension, Google Chrome, tutorials

Recent Posts

  • 31 Fresh Design Elements for Spring and Easter
  • 10 Templates for Music Concert Flyers
  • How to Build a Web Scraper Using Node.js
  • Best PHP Books, Courses and Tutorials in 2022
  • How to Get Your First Web Design Client

Archives

  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • July 2019
  • June 2019
  • May 2019
  • April 2019
  • March 2019
  • February 2019
  • January 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • June 2018
  • May 2018
  • April 2018
  • March 2018
  • February 2018
  • January 2018
  • December 2017
  • November 2017
  • October 2017
  • September 2017
  • August 2017
  • July 2017
  • June 2017
  • May 2017
  • April 2017
  • March 2017
  • February 2017
  • January 2017
  • December 2016
  • November 2016
  • October 2016
  • September 2016
  • August 2016
  • July 2016
  • June 2016
  • May 2016
  • April 2016
  • March 2016
  • February 2016
  • January 2016
  • December 2015
  • November 2015
  • October 2015
  • September 2015
  • August 2015
  • July 2015
  • June 2015
  • May 2015
  • April 2015
  • March 2015
  • February 2015
  • January 2015
  • December 2014
  • November 2014
  • October 2014
  • September 2014
  • August 2014
  • July 2014
  • June 2014
  • May 2014
  • April 2014
  • March 2014
  • February 2014
  • January 2014
  • December 2013
  • November 2013
  • October 2013
  • September 2013
  • August 2013
  • July 2013
  • June 2013
  • May 2013
  • April 2013
  • March 2013
  • February 2013
  • January 2013
  • December 2012
  • November 2012
  • October 2012
  • September 2012
  • August 2012
  • July 2012
  • June 2012
  • May 2012
  • April 2012
  • March 2012
  • February 2012
  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • September 2011
  • August 2011
  • July 2011
  • June 2011
  • May 2011
  • April 2011
  • March 2011
  • February 2011
  • January 2011
  • December 2010
  • November 2010
  • October 2010
  • September 2010
  • August 2010
  • July 2010
  • June 2010
  • May 2010
  • April 2010
  • March 2010
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • September 2009
  • August 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • October 2008
  • May 2008
  • April 2008

Categories

  • Accessibility
  • Android
  • Apps
  • Art
  • Article
  • Blogging
  • Books
  • Bootstrap
  • Business
  • CSS
  • Design
  • Development
  • Ecommerce
  • Fireworks
  • Flash
  • Freebies
  • Freelance
  • General
  • Giveaway
  • Graphic Design
  • HTML5
  • Icons
  • Illustrator
  • InDesign
  • Infographics
  • Inspirational
  • Interview
  • Jobs
  • jQuery
  • Learning
  • Logos
  • Matrix
  • Minimalism
  • Mobile
  • Motion Graphics
  • Music
  • News
  • Photoshop
  • PHP
  • Promoted
  • Rails
  • Resources
  • Showcase
  • Tools
  • Tutorial
  • Twitter
  • Typography
  • Uncategorized
  • Usability
  • UX
  • Wallpapers
  • Wireframing
  • WordPress
  • Work

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

SpyreStudios © 2022