How to Create Your First Google Chrome Extension

This time I have created my first Google Chrome Extension – ‘TwitFinder’. TwitFinder is a simple extension that allows you to retrieve the twitter profile information and all tweets posted by your friends just by typing in their username. So you need not open each time you want to check out the new tweets of your friends. The main objective is to learn basics of How to create your first Chrome extension. And believe me, its really easy. Now I will tell you step by step how to create your first Google Chrome extension.
Extensions in Google Chrome are basically webpages. You have JavaScript files, stylesheets and images. You can even use JavaScript libraries like jQuery.
Download zip file Download Extension

The extensions are, however, treated a bit differently than your regular webpage, which is displayed in the browser. You can have access to all the opened tabs, to the user’s browsing history, you can manipulate all the pages that are opened, send AJAX requests to any website and much more.
You also have the benefit (or the limitation) that your extension runs only on one browser. You can forget all compatibility issues and embrace Google Chrome’s hot new HTML5 features.

Developing extensions

Extension are packed in a .crx file (are named zip file) but during development, you can map your working folder as an extension. This way you can quickly change and deploy code without the need of repackaging.
This is done by opening the extension page (type chrome://extensions/ in the address bar, or click Wrench icon > Extensions), and clicking Developer mode > Load unpacked extension.. on the page. After you make a change to the extension, just hit the Reload link below it.
After you’re done developing, click Pack extension.. and a crx file will be created for you. You can serve this file from your site and enable your site’s visitors to install it.
Google Chrome is by far the easiest browser to make extensions for, as you will see from the steps below.

Create and load an extension

In this section, you’ll write an extension that adds a browser action to the toolbar of Google Chrome.
1. Create a folder somewhere on your computer to contain your extension’s code.
2. Inside your extension’s folder, create a text file called manifest.json, and put this in it:

"name": "TwitFinder",
"version": "1.0",
"description": "Find all tweets of your friends just by typing in their username.",
"default_icon": "twitter.png",
"default_title":"TwitFinder by",
"popup": "tweet.html" //Tell chrome that our extension is going to show a popup
"128":"twitter-128.png" //The icon to be shown in the list of extensions.
"permissions": [

3. Copy the icons (twitter.png and twitter-128.png) to the same folder.
4.Load the extension.

  • Bring up the extensions management page by clicking the wrench icon and choosing Tools > Extensions.
  • If Developer mode has a + by it, click the + to add developer information to the page. The + changes to a -, and more buttons and information appear.
  • Click the Load unpacked extension button. A file dialog appears.
  • In the file dialog, navigate to your extension’s folder and click OK.

If your extension is valid, its icon appears next to the address bar, and information about the extension appears in the extensions page, as the following screenshot shows.

5. Now create a file tweet.html in the same directory with following contents (keep all the contents in tweet.html):

HTML Markup:

<div class="main">
<form id="twitform" onsubmit="return false;">Enter your Twitter Username : <input type="text" name="user" id="uname"><input type="button" value="Get Profile" id="tweet_btn" /></form>
<div id="timeline"></div>
<div id="infodiv">
<h2>Additional Info:</h2>
<ul id="info">
<li>Name : <span id="twit_name"></span></li>
<li>Location : <span id="twit_loc"></span></li>
<li>Total Friends : <span id="twit_frnd"></span></li>
<li>URL : <span id="twit_url"></span></li>
<li>Account Created at : <span id="twit_created"></span></li>
<li>Followers : <span id="twit_flwr"></span></li>

jQuery Code:

<script type="text/javascript" src=""></script>
<script type="text/javascript">

/**The Twit jQuery plugin by Yusuke Horie to show the recent tweets**/
(function(jQuery){var _i=0;jQuery.fn.twit=function(user,options){if(typeof user!='string')return this;var
opts=jQuery.extend({},jQuery.fn.twit.defaults,options),c=jQuery.isFunction(opts.callback)?opts.callback:_callback,url=''+user+'.json',params={};opts.user=user;params.count=opts.count;return this.each(function(i,e){var $e=$(e);if(!$e.hasClass('twit'))$e.addClass('twit');jQuery.ajax({url:url,data:params,dataType:'jsonp',success:function(o){c.apply(this,[(o.results)?o.results:o,e,opts]);}});});};jQuery.fn.twit.defaults={user:null,callback:null,icon:true,username:true,text:true,count:200,limit:7,label:'Twitter',title:''};var _callback=function(o,e,opts){var $this=$(e);if(!o||o.length==0||$this.length==0)return false;$'_inc',1);_i++;var username=o[0].user.screen_name,icon=o[0].user.profile_image_url;var h='<div class="twitHeader">'+' <span class="twitLabel">'+opts.label+'</span>  '+' <span class="twitTitle">'+opts.title+'</span>'+'</div>';if(opts.icon||opts.username){h+='<div class="twitUser">';if(opts.icon)
h+=' <a href="'+username+'/">'+' <img src="'+icon+'" alt="'+username+'" title="'+username+'" style="vertical-align:middle;" />'+' </a>  ';if(opts.username)
h+='<a href="'+username+'/">'+username+'</a>';h+='</div>';}
h+='<ul class="twitBody" id="twitList'+_i+'">'+_build(o,$this,opts)+'</ul>';$this.html(h);$('a.twitEntryShow','#twitList'+_i).live('click',function(e){e.preventDefault();var $t=$(this);$t.parent().fadeOut(400,function(){var i=$'_inc');i++;$'_inc',i);if($t.hasClass('twitEntryAll')){$t.die('click');var start=(i*opts.limit)-opts.limit;$(this).after(_build(o,$this,opts,start,o.length)).remove();}else{$(this).after(_build(o,$this,opts)).remove();}});});};var _build=function(o,$t,opts,s,e){var
h='',inc=$'_inc'),start=s||(inc*opts.limit)-opts.limit,end=e||((o.length>start+opts.limit)?start+opts.limit:o.length);for(var i=start;i<end;i++){var
t=o[i],username=t.user.screen_name,icon=t.user.profile_image_url;h+='<li class="twitEntry">';if(opts.text){var text=t.text.replace(/(https?://[-_.!~*'()a-zA-Z0-9;/?:@&=+$,%#]+)/,function(u){var shortUrl=(u.length>30)?u.substr(0,30)+'...':u;return'<a href="'+u+'">'+shortUrl+'</a>';}).replace(/@([a-zA-Z0-9_]+)/g,'@<a href="$1">$1</a>').replace(/(?:^|s)#([^s.+:!]+)/g,function(a,u){return' <a href="'+encodeURIComponent(u)+'">#'+u+'</a>';});h+=' <span>'+text+'</span>';}
if(o.length>end){h+='<li class="twitNavi">'+'<a href="#" class="twitEntryShow">more</a>  / ';if(o.length>opts.limit)
h+='<a href="#" class="twitEntryShow twitEntryAll">all</a>';h+='</li>';}
return h;};})(jQuery);

<script type="text/javascript">

/**Code to fetch and display the tweets and profile information on the page**/

function populate(){
twitterusername = $('#uname').val();
if(twitterusername != ''){
$('#tweet_btn').attr('value','Please wait...');
$('#timeline').twit(twitterusername); //Call the Twit plugin to fetch recent tweets
$.getJSON(''+twitterusername+'.json?callback=?', //Retrieve user data from Twitter using the JSON
/**Display the user data**/
$('#tweet_btn').attr('value','Get Profile');

CSS Code:

/**CSS Code to beautify our extension**/
background:-webkit-gradient(linear, 0% 0%, 0% 100%, from(#EEE), to(#DDD));
text-shadow:1px 1px 0 white;
ul#info li{
border-bottom:1px dashed #666666;
border:1px solid #CC0;
font-family:Verdana, Geneva, sans-serif;
font:italic 1em Georgia, Times, serif;
background-color: #FFFFFF;
padding:5px 0 5px 5px;
border:1px solid #33CCFF;
border:1px solid #33CCFF;

/** Twit **/
background-color: #cbf2ff;
padding: 7px;
.twitHeader {
background-color: #fff;
margin: 0;
padding: 7px 7px 0 7px;
.twitLabel {
font-weight: bold;
font-size: 22px;
color: #33ccff;
.twitTitle {
font-weight: bold;
.twitUser {
background-color: #fff;
border-bottom: none;
padding: 7px;
.twitUser a{
text-decoration: none;
.twitBody {
background-color: #ffffff;
padding: 0 7px 7px 7px;
margin: 0;
list-style: none;
.twitEntry {
padding: 6px 8px;
margin: 0;
border-bottom: dashed 1px #ccc;
height: auto !important;
.twitNavi {
clear: both;
text-align: center;
margin-top: 0;
padding: 5px;
background-color: #ffffff;

And now we are done with our first Google Chrome extension!

Written by Arvind Bhardwaj

Arvind is a certified Magento 2 expert with more than 10 years of industry-wide experience.


One thought on “How to Create Your First Google Chrome Extension

Comments are closed.