Top 10 Chrome API Solutions for Enhancing Your Browser Experience

Jennie Lee
4 min readMar 28, 2024

--

Looking for a Postman alternative?

Try APIDog, the Most Customizable Postman Alternative, where you can connect to thousands of APIs right now!

Introduction

The Chrome API provides a wide range of functionalities that can enhance the browsing experience for users. In this article, we will guide you through the process of building a Chrome extension using the Chrome API. The goal of this extension is to gather up-to-date data on the Coronavirus by making API calls. By following the step-by-step guide presented here, you will be able to create your own Chrome extension and customize it to suit your needs.

Setting up the Development Environment

Before we dive into building the extension, we need to set up our development environment. Here are the steps to get started:

  1. Create a new directory and navigate into it using the command line:
mkdir chrome-extension
cd chrome-extension
  1. Initialize the directory to use npm packages by running the following command:
npm init -y
  1. Install the necessary webpack packages using the command below:
npm i webpack && npm i webpack-cli
  1. Create the necessary folders and files for the extension:
mkdir src dist
cd src
touch index.js

With these steps completed, we now have our development environment set up and we are ready to start building our Chrome extension.

Configuring the Extension

The next step is to configure the extension and specify how Chrome should handle it. This involves creating the “manifest.json” file and setting up webpack to bundle our JavaScript files.

  1. Create the “manifest.json” file in the root of your project and add the following code to it:
{
"manifest_version": 2,
"name": "Coronavirus Data",
"version": "1.0",
"description": "Get up-to-date Coronavirus data by country",
"icons": {
"16": "icon.png",
"48": "icon.png",
"128": "icon.png"
},
"browser_action": {
"default_popup": "index.html"
},
"permissions": [
"https://api.covid19api.com/**"
]
}
  1. Configure webpack by running the following command in the root of your project:
npx webpack
  1. Load the extension into Chrome by going to “chrome://extensions/” in the browser and enabling the “Developer mode” toggle. Then, click on the “Load unpacked” button and select the “dist” folder in your project directory.

With these configurations in place, our extension is now ready to be built.

Building the User Interface

The user interface is a crucial part of our Chrome extension. It allows users to interact with the extension and input the country for which they want to get Coronavirus data. Let’s build the user interface step-by-step:

  1. Connect the “index.js” file to the “index.html” file by adding the following line to the head section of the “index.html” file:
<script src="index.js"></script>
  1. Design a simple form in the “index.html” file to input the country name:
<form id="country-form">
<label for="country-input">Enter a country name:</label>
<input type="text" id="country-input" required>
<button type="submit">Submit</button>
</form>
  1. Make sure the form is accessible to the user and has appropriate styling. You can add CSS styles to the “index.html” file or create a separate CSS file and link it to the HTML file.

By following these steps, we have successfully built the user interface for our Chrome extension.

Making API Calls with Axios

To gather up-to-date data on the Coronavirus, we need to make API calls. In this guide, we will be using Axios, a popular JavaScript library for making HTTP requests. Follow these steps to make API calls using Axios:

  1. Install the Axios package by running the following command:
npm i axios --save
  1. Import the Axios library in the “index.js” file by adding the following line at the beginning of the file:
import axios from 'axios';
  1. Write the JavaScript code in the “index.js” file to make API calls using Axios and display the data in the extension’s popup. Here’s a sample code snippet to get started:
document.getElementById('country-form').addEventListener('submit', async (event) => {
event.preventDefault();
const countryInput = document.getElementById('country-input').value;

try {
const response = await axios.get(`https://api.covid19api.com/dayone/country/${countryInput}`);
const data = response.data;

// Display the data in the extension's popup
console.log(data);
} catch (error) {
console.error(error);
}
});

With these steps completed, we have successfully implemented the functionality to make API calls and display the data in our Chrome extension.

Conclusion

In this article, we have provided a step-by-step guide on how to build a Chrome extension using the Chrome API. By following the instructions outlined above, you should now have a good understanding of how to set up the development environment, configure the extension, build the user interface, and make API calls using Axios.

If you want to further explore the code and see the complete implementation of the Chrome extension described in this article, you can find the source code on GitHub.

By leveraging the powerful features provided by the Chrome API, you can create extensions that enhance your browsing experience and provide valuable functionalities specific to your needs. So go ahead and start building your own Chrome extensions using the Chrome API!

Looking for a Postman alternative?

Try APIDog, the Most Customizable Postman Alternative, where you can connect to thousands of APIs right now!

--

--

Jennie Lee
Jennie Lee

Written by Jennie Lee

Software Testing Blogger, #API Testing

No responses yet