This article demonstrates how to create and install a Chrome extension. In this article, I am going to show a step by step process for creating a very basic Chrome extension app.
Here I am going to create a folder where I will put the project source code.
After opening the folder create the following folder and files:
- Create Folder with name ‘Images’
- Create ‘manifest.json’ file
- Create ‘popup.html’ file
- Create ‘popup.js’ file
Add an Image file for Extension Icon inside Images Folder
Navigate to project-> Images and paste any image. I am using zi.png
Put the below code to manifest.json file,
- {
- "manifest_version": 2,
- "name": "Zulqadar Idrishi",
- "description": "This extension is designed for Demo Perpose",
- "version": "1.0",
- "browser_action": {
- "default_icon": "images/zi.png",
- "default_popup": "popup.html"
- },
- "permissions": ["activeTab"]
- }
The manifest file contains all extension-related information like web.config file in asp.net projects.
Put the below code for popup.html,
- <!doctype html>
- <html>
- <head>
- <title>Zulqadar Idrishi</title>
- <script src="popup.js"></script>
- <style>
- body{
- min-width: 200px;
- text-align: center;
- font-family: century Gothic;
- }
- .button {
- background-color: #4CAF50;
- border: none;
- color: white;
- padding: 5px 14px;
- text-align: center;
- text-decoration: none;
- display: inline-block;
- font-size: 16px;
- margin: 4px 2px;
- transition-duration: 0.4s;
- cursor: pointer;
- }
- .button2 {
- background-color: white;
- color: black;
- border: 2px solid #008CBA;
- }
- .button2:hover {
- background-color: #008CBA;
- color: white;
- }
- </style>
- </head>
- <body>
- <h2>Hi, I'm <strong>Zulqadar Idrishi</strong></h2>
- <a href="https://www.google.com/search?q=Zulqadar Idrishi" id="checkPage" class="button button2">Find me on Google</a>
- </body>
- </html>
This HTML code is responsible to show popups and the design of our extension.
Put the below code for popup.js,
- document.addEventListener('DOMContentLoaded', function() {
- var checkPageButton = document.getElementById('checkPage');
- checkPageButton.addEventListener('click', function() {
- chrome.tabs.getSelected(null, function(tab) {
- d = document;
- window.open('https://www.google.com/search?q=Zulqadar Idrishi', 'blank');
- });
- }, false);
- }, false);
This file popup.js is responsible to handle events on the extension.
Now open Chrome Browser and go to Extensions,
Here Enable Developer Mode and click on Load Unpacked,
Choose the Project Folder,
Now, the extension is added to Chrome successfully,
Now, we can see Extension is also installed in our browser,
Click on the Extension icon and see the popup,
Summary
In this article, I discussed how we can create and install a Chrome extension. I hope you like the article. This is my first article so let me know how the article is.