Angularjs Plugin For Chrome

We have compiled a list of cool plugins for your chrome, here is the list:

I’ve been working with Angularjs for many months and have seen a lot of questions about the Chrome plugin when interacting with it in other web apps. In this article I will go over some tips that will help you get started with the Angularjs Chrome extension.

You can use Angularjs Plugins for Chrome to make your application more useful.

Angularjs Plugin For Chrome

Chrome extensions are like dragons of Game Of Thrones in web world. You won’t see them much, but when you do… Oh boy! They takes your breath away.

I was using many chrome extensions like Ads Block PlusEverNoteAngular watchersMotivate etc. from so long and being a web developer was always amazed by the power these small software packages possess.

So I tried to give it a spin myself and to my surprise I didn’t have to learn much to create something of my own.

Just learned some basic concepts of how chrome extension works and mixed it with my prior knowledge of basic HTML, CSS, Javascript and AngularJS. And what I got is this -> Text Sentiment Analysis chrome extension.

An amazing(silly! actually :D) chrome extension which can analyze sentiment of selected text on any web page using Google’s Natural Language(NL) API. See below screenshots to understand how it works.

Select some text on any web page
Click the extension button in browser bar

Fetch the code of the above extension from this Github repo and follow along.

For above code to work, you have to insert your project’s API_KEY in popup.js file. Don’t worry, we will discuss how to create your own project key later in this post.

If I am not wrong, You all might be screaming this by now…

Hey! We got that chrome extensions are fun and powerful but we still don’t know how to build chrome extension with AngularJS and NL API.

Please bear with me for few more minutes and I promise you won’t regret it.

So, let’s take it step by step(4 to be precise)…

1. What is a Chrome Extension?

Some basics are needed at this point. Chrome extensions are tiny web applications(consists of HTML, CSS and Javascript) which when added to chrome lives in your browser and uses some special chrome API’s to enhance your browsing experience or solves any particular use case.

The resources I mentioned at the end of this post, answers this question in a much better way.

2. How does it work?

This is a simple yet powerful question. Once understood properly will open doors for multiple opportunities.

Someone told me : “A picture is worth a thousand words”

So, here is my version for understanding how chrome extension works(these are just rough sketches)…

Overview Of Chrome Extension Entities

Key Points

  • Main Entities of chrome Extensions are manifest.jsoncontent.jsbackground.js and Popup.
  • Each one of these entities :- content.js, background.js and popup have their own isolated scopes and dev tool windows for debugging.
  • Only content.js have access to the DOM of the current web page directly.
  • All these elements interact with each other by sending and listening to events provided by chrome API.

Refer to blogs and tutorials at the end of this post for further details.

Now lets see how our Text Sentiment Analysis extension works with respect to above mentioned components.

Text Sentiment Analysis Chrome Extension Overview

3. How to include AngularJS?

It is same as you include AngularJS in any other web project.

Download the minified version of the framework from here and link it from popup.html file as you would do it in index.html for any other AngularJS project(Refer code).

4. How to include Natural Language API?

It is as simple as using any other third party API in your web project.

(i) First create a Google Cloud Project to generate your own API key . Follow instructions given on this official page.

(ii) Next enable Natural Language API to use in your project from here.

(iii) Start making POST calls as follows from your custom javascript code(popup.js in our case).

$http({
          url: 'https://language.googleapis.com/v1/documents:analyzeSentiment?key=YOUR_API_KEY',
          method: "POST",
          data: {
            "encodingType": "UTF8",
            "document": {
              "type": "PLAIN_TEXT",
              "content": "The text for analysis comes here."
            }
          }
      })

Refer the official Google docs to understand how this API works and overall structure of the response.

We are using top level ‘score’ property as a parameter to display overall sentiment of the selected text. -ve value means negative sentiment, +ve for positive and 0 for neutral sentiment.

Hurray! You have learned how to create your own chrome extension and include an advanced Machine Learning API.

Check out Google’s official document page for more Machine Learning API’s.

Thank you for reading this far. I hope this new combined skill set of Chrome extension and Google’s machine learning API’s will open some new doors of creativity for you.

Leave a Comment