Yaron Vazana

NLP, Algorithms, Machine Learning, Data Science, tutorials, tips and more

  • About
  • Blog
  • Projects
  • Medium

Contact Me

yaronv99 [at] gmail.com

Powered by Genesis

You are here: Home / Web Development / How to Develop Chrome Extensions

How to Develop Chrome Extensions

January 19, 2015 by Yaron Leave a Comment

In this tutorial, I will show how to write a chrome extension all the way. Writing chrome extensions is really not that hard and I think we all (developers) should know how to create them. Especially when 99% of the time we have a chrome browser open in front of us.

chrome dev editor

For those of you (like me) who can’t wait and want to get the code, Here it is on Github

What Do We Need?

  • Chrome dev editor – this is not a must, but really helps to run the extension
  • Chrome browser – no need to ask
  • An idea for a new extension you’d like to have

How Chrome Extensions Work?

Basically, chrome extensions have two parts which you must be familiar with:

  1. Background code which runs behind the scenes and executes a piece of code usually on a predefined interval
  2. A code which runs when the extension is activated, usually runs once.

I’ll Explain:

A background process can be a code where you check the weather (or any other API) every fixed time and when something changes you notify the user about it. Not all extensions must have this section and in my example I didn’t use a background script.
The second script is in charge of the extension initialization. Usually, this will be a script which initializes the UI components and makes sure all the buttons, links, images etc are ready.

This example shows a basic chrome extension which opens a popup with a search input, searching this input leads to a new chrome tab with the relevant Google search results.

This is how the files tree looks like

Chrome dev editor

We separate the styling, JavaScripts and images to different folders just to keep everything organized. It is recommended to include all sizes for the icons so it will look professional.

popup.html – this is the actual extension UI popup

background.html – this file loads the background script (which is empty in our case)

popup.js – initialization of the extension popup

Finally

After setting all the files, we need  one more file to give google some information about our new extension.

manifest.json

Running Your Chrome Extension

After you have the extension ready, running it is pretty straight forward. If you’re using the chrome dev editor, just click the play button. After modifying the extension, in order to relaunch it, I had to right click and ‘remove from Chrome’ before starting it again. If you’re using your own editor, just go to chrome://extensions/ and drag and drop your extension folder there (make sure you’re in developer mode).

Google search extension

Get the full code from my Github

Filed Under: Web Development Tagged With: Chrome, Javascript, Programming

I am a data science team lead at Darrow and NLP enthusiastic. My interests range from machine learning modeling to solving challenging data related problems. I believe sharing ideas is where we all become better in what we do. If you’d like to get in touch, feel free to say hello through any of the social platforms. More About Yaron…

SUBSCRIBE TO BLOG

Subscribe to Blog

Subscribe to get the latest posts to your inbox

Recent Posts

  • Training an AutoEncoder to Generate Text Embeddings
  • Using Dockers for your Data Science Dev Environment
  • Identifying Real Estate Opportunities using Machine Learning
  • How to Create a Simple WhatsApp Chatbot in Python using Doc2vec
  • Average Word Vectors – Generate Document / Paragraph / Sentence Embeddings
  • Visualizing Vectors using TensorBoard
  • Training a Doc2Vec Model with Gensim
 

Loading Comments...