DEV Community

Cover image for Building a Chrome Extension using DEV API
Sunil Aleti
Sunil Aleti

Posted on • Updated on

Building a Chrome Extension using DEV API

Chrome extensions are small HTML, CSS and JavaScript apps that we can install in the chrome browser.

In this tutorial, We are going to build an extension that allows users to get articles based on tags from by simply selecting it.

As we are using get requests method we don't need an API key from
Check out DEV API docs and get your hands dirty

Alt Text

You can find all the necessary code and files from my GitHub Repository

Step 1: Create a new directory "dist" and create files under that directory as shown in the picture

Alt Text

Step 2: Create an HTML file

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <link rel="stylesheet" href="./style.css" />
    <script src=""></script>
    <script type="text/javascript" src="index.js" defer></script>
    <p>An Extension which pulls out articles based on tags</p>
    <div class="container">
    <form  id="form-data">
      <label for="tags">Select a tag:</label><br><br>
        <select name="tags" id="tags">
          <option disabled selected value> -- select an option -- </option>
          <option value="python">Python</option>
          <option value="javascript">Javascript</option>
          <option value="tutorial">Tutorial</option>
          <option value="productivity">Productivity</option>
          <option value="discuss">Discuss</option>
          <option value="beginners">Beginners</option>
          <option value="archlinux">archlinux</option>
          <option value="webdev">Webdev</option>
          <option value="android">Android</option>
          <option value="react">React</option>
      <button type="submit" class="seach-btn">Submit</button>
    <div class="result">
Enter fullscreen mode Exit fullscreen mode

Step 3: Create a js file to handle API calls

const results = document.querySelector(".result");
const api = "";
const search = document.getElementById("form-data");

const getposts = async (Tag) => {
    try {
      const tag = await document.getElementById("tags").value;
      const response = await axios.get(`${api}${tag}`+"&per_page=5");

      var articles="";
            for(var i=0;i<;i++){
                articles+='<li><a href='[i].url+'>'[i].title+'</a></li>';
        articles+='<br><center><a href='+link+'>Checkout blog</a><center>';
      catch (error) {
  // declare a function to handle form submission
  const handleSubmit = async e => {

  search.addEventListener("submit", e => handleSubmit(e));
Enter fullscreen mode Exit fullscreen mode

We have an asynchronous function called getposts and within that function, we can use async-await. Async await allows us to stop executing code that is dependent, while we wait for the response from a server. By using the await keyword in front of a piece of code we can get the rest of our code to stop executing while that piece of code executes.

In this example, we await a response from our GET request before setting that response to our articles variable.

Axios is a very popular JavaScript library you can use to perform HTTP requests, that works in both Browser and Node.js platforms. It supports all modern browsers, including support for IE8 and higher. It is promise-based, and this lets us write async/await code to perform XHR requests very easily.

Here are some endpoints to access articles, users and other resources via API

Step 4: You can also add css to your HTML file

Alt Text

Step 5: Create manifest.json and add following code. This is the file that contains information on how Chrome should handle the extension.

    "manifest_version": 2,
    "name": "DEV",
    "version": "0.1.0",

    "permissions": ["<all_urls>"],

    "browser_action": {
      "default_popup": "index.html"
    "content_security_policy": "script-src 'self' ; object-src 'self'"
Enter fullscreen mode Exit fullscreen mode

manifest_version, name and version are important and MUST be declared. The extension must have a manifest_version of 2 to work with the latest Chrome browsers, you can give it whatever name/version you wish.

We set permissions to all_urls so that our extension can run on any page. browser action instructs chrome to show our index.html file as a popup when the icon is clicked.


Adding Extension to Chrome:

Go the Chrome Extensions or you can click on this link to navigate to the extension page.
Once the page is opened, follow the video to add it

If you like my content, please consider supporting me

Buy Me A Coffee

My level of happiness rose to ecstatic, as I recently crossed 1000 followers and 25000 post views on DEV.
Thanks to DEV Team and Everyone who supported me

Hope it's useful

A ❤️ would be Awesome 😊

Top comments (2)

yellow1912 profile image

Put real code instead of image would be much better I think.

sunilaleti profile image
Sunil Aleti

You can check my github repo :)