Make A Chrome Extension In 5 Minutes

Before making a Chrome Extension, we must have a basic idea what actually an extension is. It is nothing but a plugin or add-on made to enhance the features of your browser .

In this post, we will make a chrome extension that will show awesome backgrounds every time you click new tab and will show the quote of the day. This extension will work in Google Chrome as well as all other chromium based browsers.

Prerequisites

You need to know the basics of the following,

  • HTML
  • CSS
  • JavaScript

If you are already familiar with the above technology, then you would already know about the respective technologies. We will make a simple website with HTML, CSS and JavaScript and host it inside the Google Chrome. We can add our business logic with the help of JavaScript. To make a Chrome Extension, there are some best practices or format that we should follow.

How to make a Chrome Extension with JavaScript (Step by Step guide)

Let’s get started. Building an Extension is very easy just follow the steps below.

Step 1: Open your Google Chrome & go to chrome://extensions/ and enable developer mode.

How to make a chrome extension in javascript developer mode

Step 2: Go to extensionizr.com and select (Read more about what do these do by hovering over the ‘?’ at each option)

  • Hidden Extension
  • No Background
  • No fancy options
  • Override New Tab
  • Add jQuery

How to make a chrome extension in javascript hidden extension

After you have done these things download the zip file .

Step 3: Once you extract the zip file , go to manifest.json file in the main folder and edit the manifest.json . Manifest.json contains all the metadata that your Chrome Extension will need, it is the entry point of the extension. This is nothing but a JavaScript Object with the following properties like name, version, description etc. You may not have the permissions property, so simply copy paste from here to get it later.

  1. {  
  2.     "name""Beautiful New Tab",  
  3.     "version""0.0.1",  
  4.     "manifest_version": 2,  
  5.     "description""Get beautiful images with quotes whenever you open a new tab.",  
  6.     "homepage_url""http://codesparta.com",  
  7.     "icons":  
  8.     {  
  9.         "16""icons/icon16.png",  
  10.         "48""icons/icon48.png",  
  11.         "128""icons/icon128.png"  
  12.     },  
  13.     "default_locale""en",  
  14.     "chrome_url_overrides":  
  15.     {  
  16.         "newtab""src/override/override.html"  
  17.     },  
  18.     "permissions": ["https://source.unsplash.com/""http://quotes.rest/"]  
  19. }  
Step 4: Create a .css file and a .js file in CSS and js folders respectively. 

Step 5: Making the basic HTML document. Go to src/override/ you will find override.html file.

Add both .js and .css files in the override.html

  1. <!DOCTYPE html>  
  2. <html>  
  3.   
  4. <head>  
  5.     <title>Make a Chrome Extension | Beautiful New Tab</title>  
  6.     <link href="../../css/custom.css" rel="stylesheet" />  
  7. </head>  
  8.   
  9. <body>  
  10.     <h1>Quote of the day</h1>  
  11.     <div class="quote">  
  12.         <h1 id="quoteblock"></h1>  
  13.         <h3 id="author"></h3>  
  14.     </div>  
  15.     <script src="../../js/jquery/jquery-1.12.3.min.js"></script>  
  16.     <script src="../../js/jquery/app.js"></script>  
  17. </body>  
  18.   
  19. </html>  
Step 6: We are going to use two websites, one of them will provide us with some awesome images and the second one will provide us with the daily quote. 

To make a request to external links we have to add URL’s in permissions in manifest.json .

Add the following CSS in the custom.css (We have used PT serif Google font).

  1.       @import url(https: //fonts.googleapis.com/css?family=PT+Serif:400italic);  
  2. body  
  3. {  
  4.     background - image: url("https://source.unsplash.com/category/nature/1600x900");  
  5.     background - repeat: no - repeat;  
  6.     height: 100 % ;  
  7.     width: auto;  
  8. }  
  9. h1  
  10. {  
  11.     font - family: 'PT Serif', serif;  
  12.     font - size: 2.5e m;  
  13.     text - align: center;  
  14.     color: #fff;  
  15.     text - shadow: 2 px 2 px 3 px rgba(150, 150, 150, 0.75);  
  16. }  
  17. .quote  
  18. {  
  19.     color: #ffffff;  
  20.     text - align: center;  
  21.     vertical - align: middle;  
  22.     padding: 19 % 15 % 0 15 % ;  
  23. }#quoteblock  
  24. {  
  25.     font - family: 'PT Serif', serif;  
  26.     text - shadow: 2 px 2 px 3 px rgba(150, 150, 150, 0.75);  
  27.     font - size: 2e m;  
  28. }#author  
  29. {  
  30.     font - family: 'PT Serif', serif;  
  31.     text - align: center;  
  32.     color: #fff;  
  33.     text - shadow: 2 px 2 px 3 px rgba(150, 150, 150, 0.75);  
  34. }  
Step 7: Getting quote from theysaidso API. 

We have to request the to get the JSON data from API and get the Quote from that we are doing this by using AJAX .

How to make a chrome extension in javascript use json data

Add the following code to the JavaScript file you made.

  1. $(function()  
  2. {  
  3.     var url = "http://quotes.rest/qod.json";  
  4.     var quote = $("#quoteblock"); // the id of the heading  
  5.     $.get(url, function(data)  
  6.     {  
  7.         var the_quote = data;  
  8.         quote.text(the_quote.contents.quotes[0].quote);  
  9.         var author = $("#author"); // id of author  
  10.         author.text(the_quote.contents.quotes[0].author);  
  11.     });  
  12. });  
Step 8: Making the Chrome Extension (.crx) file. Load your folder to test first, and then go to pack extension that will make a .crx file that you can share with your friends. Simply drag and drop the .crx file on chrome://extensions/ and it will install the extension. 

How to make a chrome extension in javascript make .crx file

How to make a chrome extension in javascript 5

Final Result

Every time you click new tab a new image with quote will show, you can use a single image per day by using the background property of JSON data from the API.

How to make a chrome extension in javascript new tab override

Up Next
    Ebook Download
    View all
    Learn
    View all