<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ankit Verma</title>
    <description>The latest articles on DEV Community by Ankit Verma (@ankitverma31).</description>
    <link>https://dev.to/ankitverma31</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F80515%2F024295e7-6f4b-4ff2-a537-cba104a828a7.jpeg</url>
      <title>DEV Community: Ankit Verma</title>
      <link>https://dev.to/ankitverma31</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ankitverma31"/>
    <language>en</language>
    <item>
      <title>Building your first chrome extension: A beginner's guide</title>
      <dc:creator>Ankit Verma</dc:creator>
      <pubDate>Wed, 11 Sep 2019 20:04:11 +0000</pubDate>
      <link>https://dev.to/ankitverma31/building-your-first-chrome-extension-a-beginner-s-guide-40a9</link>
      <guid>https://dev.to/ankitverma31/building-your-first-chrome-extension-a-beginner-s-guide-40a9</guid>
      <description>&lt;p&gt;Recently I wrote my first chrome extension. In this post, I will walk through the main components of a chrome extension and my experience in building it and how you can build yours too.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table Of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;What are Chrome extensions&lt;/li&gt;
&lt;li&gt;Quick Launcher Extension&lt;/li&gt;
&lt;li&gt;Main components of extension&lt;/li&gt;
&lt;li&gt;Load your extension&lt;/li&gt;
&lt;li&gt;Debug your extension&lt;/li&gt;
&lt;li&gt;Important APIs of Chrome&lt;/li&gt;
&lt;li&gt;Publish to webstore&lt;/li&gt;
&lt;li&gt;Resources - Kick-start &lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What are Chrome extensions? &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Google Chrome Extensions are browser extensions that modify Google Chrome. These extensions are written using web technologies like HTML, JavaScript, and CSS. They are distributed through Chrome Web Store. So if you are a front-end web developer, building an extension would be easier for you. &lt;/p&gt;

&lt;h2&gt;
  
  
  Quick Launcher Extension(My extension) &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fz0qus7ww74rvwqkb4jec.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fz0qus7ww74rvwqkb4jec.png" alt="Quick Launcher chrome extension"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;How I got the idea of building &lt;a href="http://bit.ly/2NWtboe" rel="noopener noreferrer"&gt;Quick Launcher&lt;/a&gt;?&lt;/strong&gt; Actually I work at a startup and there are around 10-15 internal/external tools or sites or projects and each site has a different URL for different environments like for uat, staging, production, etc. It was a real pain to access a particular environment of a site from 30-40 URLs. Of course, I have the URL list saved in notes but to go there and get a particular URL from it was time-consuming. One solution was to bookmark the URLs. But already I have tons of links bookmarked. I wanted to separate the projects/tools links from the rest of my bookmarks and wanted to bundle or organize the links related to a particular project. And yeah, that's how the idea of building a chrome extension came to my mind.&lt;/p&gt;
&lt;h3&gt;
  
  
  What is Quick Launcher?
&lt;/h3&gt;

&lt;p&gt;&lt;a href="http://bit.ly/2NWtboe" rel="noopener noreferrer"&gt;Quick Launcher&lt;/a&gt; is a smart URL organizer. A chrome extension especially for developers(can be used by non-developers too) to create collections of various related useful links. You can also add various apps deployed in different environments like uat, staging, production for quick access. Quick launcher also has a &lt;strong&gt;Most Visited Sites&lt;/strong&gt; tab to quickly access sites that matter to you the most. &lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Quick Launcher Features:&lt;/strong&gt;
&lt;/h3&gt;
&lt;h3&gt;
  
  
  Collections:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fzhch55nh3tgn6bthvraq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fzhch55nh3tgn6bthvraq.png" alt="Quick Launcher chrome extension Collections"&gt;&lt;/a&gt;&lt;br&gt;
Organize your various related links under a particular collection. You can add as well as delete a collection. After creating a collection, you can either add an item under it manually or right click on any website and choose collection name in the menu, you will be prompted to add a title after which you can save that link under that collection.&lt;/p&gt;
&lt;h3&gt;
  
  
  Deployed Apps:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F4mc93883rzmnaw4bt2d5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F4mc93883rzmnaw4bt2d5.png" alt="Quick launcher chrome extension deployed apps"&gt;&lt;/a&gt;&lt;br&gt;
Quickly access sites/products/tools deployed in different environments like uat, staging, production. You can add deployment URLs of various sites/tools in JSON format to quickly access them. Currently supports 3 environments per site.&lt;/p&gt;
&lt;h3&gt;
  
  
  Most Visited Sites:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F56c7jef1yyxihwujase0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F56c7jef1yyxihwujase0.png" alt="Quick Launcher chrome extension Most Visited tab"&gt;&lt;/a&gt;&lt;br&gt;
Most visited sites tab to quickly access your most visited sites.&lt;/p&gt;
&lt;h2&gt;
  
  
  Main components of extension: &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Extensions are made of different, but cohesive, components. Components can include &lt;a href="https://developer.chrome.com/extensions/background_pages" rel="noopener noreferrer"&gt;background scripts&lt;/a&gt;, &lt;a href="https://developer.chrome.com/extensions/content_scripts" rel="noopener noreferrer"&gt;content scripts&lt;/a&gt;, an &lt;a href="https://developer.chrome.com/extensions/options" rel="noopener noreferrer"&gt;options page&lt;/a&gt;, &lt;a href="https://developer.chrome.com/extensions/user_interface" rel="noopener noreferrer"&gt;UI elements&lt;/a&gt; and various logic files. Extension components are created with web development technologies: HTML, CSS, and JavaScript.&lt;/p&gt;
&lt;h3&gt;
  
  
  Manifest:
&lt;/h3&gt;

&lt;p&gt;Extensions start with their &lt;a href="https://developer.chrome.com/extensions/manifest" rel="noopener noreferrer"&gt;manifest&lt;/a&gt;. It is a JSON file which provides information about your extension like name, version, description, etc.&lt;br&gt;
Here is the example of manifest.json file:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
 

&lt;p&gt;&lt;strong&gt;Let's have a look of some important fields in manifest.json:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;name&lt;/code&gt;: Name of your extension&lt;br&gt;
&lt;code&gt;description&lt;/code&gt;: A short summary of your extension&lt;br&gt;
&lt;code&gt;browser_action&lt;/code&gt;: Used to put icons in the main Google Chrome toolbar, to the right of the address bar. In addition to its icon, a browser action can have a tooltip, a badge, and a popup. &lt;a href="https://developer.chrome.com/extensions/browserAction" rel="noopener noreferrer"&gt;Read more..&lt;/a&gt;&lt;br&gt;
&lt;code&gt;default_popup&lt;/code&gt;: The HTML file which pop-ups when the user clicks on your chrome extension in the toolbar.&lt;br&gt;
&lt;code&gt;background&lt;/code&gt;: Used to manage events. It contains the scripts of your extension. &lt;a href="https://developer.chrome.com/extensions/background_pages" rel="noopener noreferrer"&gt;More..&lt;/a&gt;&lt;br&gt;
There are other fields too in the manifest. To learn in detail about each field, check out the &lt;a href="https://developer.chrome.com/extensions/manifest" rel="noopener noreferrer"&gt;documentation&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  HTML file(popup.html):
&lt;/h3&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
 &lt;br&gt;
&lt;code&gt;popup.html&lt;/code&gt; as mentioned above, pops-up when the user clicks on your extension's icon in the toolbar.
&lt;h3&gt;
  
  
  Popup Javascript file(popup.js):
&lt;/h3&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
 
&lt;h3&gt;
  
  
  CSS file(style.css):
&lt;/h3&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  Icons/Images:
&lt;/h3&gt;

&lt;p&gt;You need to supply several kinds of images to be used in the Chrome Web Store and the Google Chrome browser:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;App icon&lt;/li&gt;
&lt;li&gt;Promotional images&lt;/li&gt;
&lt;li&gt;Screenshots&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Refer to the &lt;a href="https://developer.chrome.com/webstore/images" rel="noopener noreferrer"&gt;official documentation&lt;/a&gt; to know more about images/icons requirements.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So our final directory structure looks like:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my-extension folder/
├── manifest.json
├── background.js
├── popup.js
├── popup.html
├── style.css
├── img
│   ├── icon_16x16.png
│   ├── icon_48x48.png
│   ├── icon_128x128.png
│   ├── icon_19x19.png
│   ├── icon_38x38.png
│   
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Load your extension &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Once you are ready with the above folder structure, you need to test if everything is fine by loading it in the browser. To load your extension: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open Chrome browser and navigate to &lt;code&gt;chrome://extensions&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Enable Developer Mode by clicking the toggle switch next to &lt;strong&gt;Developer mode&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Click the &lt;strong&gt;LOAD UNPACKED&lt;/strong&gt; button and select the extension directory.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Debugging your extension &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;You can debug a chrome extension the same way you debug a normal website using chrome dev tools/inspect elements. To debug your extension:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open Chrome browser and navigate to &lt;code&gt;chrome://extensions&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Locate your extension and copy the extension &lt;strong&gt;ID&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Open the URL &lt;code&gt;chrome-extension://ID/popup.html&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Use the dev-tools(Ctrl+Shift+I) to debug it. &lt;a href="https://developer.chrome.com/extensions/tut_debugging" rel="noopener noreferrer"&gt;Read more..&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Some useful APIs of Chrome &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Let's check out some important APIs I have used for building quick-launcher extension:&lt;/p&gt;

&lt;h3&gt;
  
  
  Storage:
&lt;/h3&gt;

&lt;p&gt;In Quick Launcher extension, I have used sync storage to save the &lt;code&gt;collections JSON object&lt;/code&gt; and &lt;code&gt;deployed apps environments&lt;/code&gt; which is added by the user.&lt;br&gt;
Chrome Apps can’t use &lt;code&gt;localStorage&lt;/code&gt;. Instead, there’s a Chrome API, &lt;code&gt;chrome.storage.local&lt;/code&gt;, that’s better: it can store JavaScript objects (localStorage is limited to strings) and, like most Chrome APIs, it operates asynchronously, allowing the app to be more responsive. What’s more, there’s a variant, &lt;code&gt;chrome.storage.sync&lt;/code&gt;, with the same API, which is automatically synchronized between computers running the same app, similar to the way that Sync Files are synchronized. Learn more about &lt;a href="https://developer.chrome.com/apps/storage" rel="noopener noreferrer"&gt;storage&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Context Menus:
&lt;/h3&gt;

&lt;p&gt;When you right-click(or control-click on a Mac) with the mouse pointer inside a Chrome App window, you get a menu with some debugging options, such as &lt;code&gt;Reload&lt;/code&gt; App or &lt;code&gt;Inspect Element&lt;/code&gt;. That is called the context menu. You can have your own menu option on that menu along with click listener. In Quick Launcher, I have added &lt;code&gt;Add to collections&lt;/code&gt; menu which can be used by the user to add a URL under a particular collection. &lt;a href="https://developer.chrome.com/apps/contextMenus" rel="noopener noreferrer"&gt;Read more..&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;There are other dozens of API Chrome offers which you can use. Visit the &lt;a href="https://developer.chrome.com/extensions/devguide" rel="noopener noreferrer"&gt;official developer guide&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Publish to webstore: &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Ftg9g4zougldcuhmzxni4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Ftg9g4zougldcuhmzxni4.png" alt="Chrome extension developer dashboard"&gt;&lt;/a&gt;&lt;br&gt;
Once you are done with the development part, its time to publish your chrome extension to the webstore. To publish your extension:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Visit &lt;a href="https://chrome.google.com/webstore/developer/dashboard" rel="noopener noreferrer"&gt;Developers Dashboard&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Sign in(if asked)&lt;/li&gt;
&lt;li&gt;Click on &lt;code&gt;Add new item&lt;/code&gt;, accept the TnC&lt;/li&gt;
&lt;li&gt;Compress your folder to &lt;code&gt;my-extension.zip&lt;/code&gt; and upload the zip file&lt;/li&gt;
&lt;li&gt;If it is your first app, you will be asked to pay a one-time fee which is &lt;strong&gt;$5&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;After completing the above steps, you will have to fill the form with description, add promotional images, screenshots, etc. Make sure you upload all the necessary images so your extension gets listed well in webstore. Check the &lt;a href="https://developer.chrome.com/webstore/images" rel="noopener noreferrer"&gt;official documentation&lt;/a&gt; about image/promotional images requirements. Hit the &lt;strong&gt;PUBLISH&lt;/strong&gt; button once you are done. It takes some times for your item to get visible on webstore.&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources - Kick-start: &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://developer.chrome.com/extensions/overview" rel="noopener noreferrer"&gt;Overview of extensions&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.chrome.com/extensions/getstarted" rel="noopener noreferrer"&gt;Getting started tutorial&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.chrome.com/extensions/devguide" rel="noopener noreferrer"&gt;Developers guide&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://bit.ly/2NWtboe" rel="noopener noreferrer"&gt;Quick Launcher Extension&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Conclusion: &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;So, its pretty simple to build a basic chrome extension as a developer. But it is definitely a challenge to build something creative among lakhs of existing chrome extensions. So, what are you waiting for? go build your chrome extension. If you are stuck, you can always visit the excellent &lt;a href="https://dev.toDevelopers%20guide"&gt;documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Don't forget to share your work in the comment. Please spare a moment and try &lt;a href="http://bit.ly/2NWtboe" rel="noopener noreferrer"&gt;my extension&lt;/a&gt;. I would highly appreciate your positive &lt;a href="https://chrome.google.com/webstore/detail/quick-launcher/ejfnjjfimjllfmeohacobipgepnilapm/reviews" rel="noopener noreferrer"&gt;reviews&lt;/a&gt;. Also like/share the article if you really found it useful.&lt;/p&gt;

&lt;p&gt;Got questions or feedback? Let me know in the comments!&lt;/p&gt;

</description>
      <category>extension</category>
      <category>chrome</category>
      <category>browser</category>
      <category>webstore</category>
    </item>
  </channel>
</rss>
