Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to develop Chrome extension for Gmail?

I'm thinking about developing Chrome extension for Gmail and I want to know what are the current best practices.

For instance:

  • attaching a GPG signature by default to every email
  • adding an extra button that does something (I have it already)
  • hijacking action of sending email and prompting me to do complete something
  • ...
  • (just them examples helping me to discover what is possible)

There are quite a few notable extensions that significantly augment gmail functionality:

  • http://www.boomeranggmail.com/
  • http://toolbox.mxhero.com/
  • http://www.wisestamp.com/
  • ...
  • (I'm not affiliated with any of them, I just named a few)

One option would be to peek into their source which is located here ~/Library/Application Support/Google/Chrome/Default

But maybe there is (wishful thinking) a good tutorial / set of practises on how to fiddle with gmail UI and functionality?

Gmail extension/gadget API - how to add a button to the compose toolbar?

You will have to create and inject the button programmatically. This will involve quite a bit of scouring the Gmail source code (spoiler: it's ugly).

How to build a chrome extension to add panel to gmail windows?

The greatest long-term challenge you will face is that gmail's layout will change unexpectedly and break email discovery or the modified UI. Both issues either require some cleverness to solve, or will require you to stay up at night wondering whether Google will suddenly break your extension.

http://www.jamesyu.org/2011/02/05/introducing-gmailr-an-unofficial-javscript-api-for-gmail/

They're all building out complex APIs with similar functionality, that can all break independently if Gmail decides to significantly change their app structure (which they inevitably will).

Gmail runs its code through the closure compiler, thereby obfuscating everything. On top of that, Gmail is probably one of the most sophisticated javascript apps out there.

Library by the founder of Parse - https://github.com/jamesyu/gmailr - but haven't updated in 1.5 years.


I can show you what I got so far, and just so know I don't particularly like selectors like .oh.J-Z-I.J-J5-Ji.T-I-ax7

Note: http://anurag-maher.blogspot.co.uk/2012/12/developing-google-chrome-extension-for.html (he also does it, he also uses such an obfuscated selectors)

manifest.json

"content_scripts": [   {     "matches": ["https://mail.google.com/*"],     "css": ["mystyles.css"],     "js": ["jquery-2.1.0.js", "myscript.js"]   } ] 

myscript.js

var icon = jQuery(".oh.J-Z-I.J-J5-Ji.T-I-ax7") var clone = icon.clone(); clone.attr("data-tooltip", "my tooltip"); clone.on("click", function() {     jQuery(".aDg").append("<p class='popup'>... sample content ...</p>"); }); icon.before(clone); 

(reusing existing UI elements so my functionality looks natively)


https://developers.google.com/gmail/gadgets_overview

There are Sidebar Gadgets and Contextual Gadgets but they don not offer what I want to achieve.

Gmail Labs is a testing ground for experimental features that aren't quite ready for primetime. They may change, break or disappear at any time.

https://groups.google.com/forum/#!forum/gmail-labs-suggest-a-labs-feature It seems like the ability to develop Gmail Labs is locked to Google employees.

https://developers.google.com/gmail/

Need help? Find us on Stack Overflow under the gmail tag.


So yes, I would really like to know if there are any tutorials / reference materials out there?

(I reviewed many of the 'Similar Questions' and I'm afraid that my options here are limited, but I would be extremely happy if I shrine your enlightenment upon me)

like image 262
Mars Robertson Avatar asked Apr 19 '14 19:04

Mars Robertson


People also ask

How do I create a Gmail extension?

How Do I Add a Gmail Extension? Adding a Gmail extension is as simple as finding the extension you want in the web store and clicking the “Add to Chrome” button. And then confirm it by clicking the “Add extension” button when prompted. You've now successfully added a Gmail focused extension to your Chrome browser.

How do I add a Chrome extension to Gmail?

Enable extension Go to chrome://extensions and on the right side it will say “Developer mode”. Turn that on. Now click “Load unpacked” and find and select the folder where you have this code. The extension only works on mail.google.com domain because we specify that in the manifest.

Can I make my own Chrome extension?

A chrome extension is a program that is installed in the Chrome browser that enhances the functionality of the browser. You can build one easily using web technologies like HTML, CSS, and JavaScript. Creating a chrome extension is similar to creating a web application, but it requires a manifest.

How much does it cost to publish a Chrome extension?

The Chrome Web Store charges a $5.00 fee to register as a Chrome Web Store developer. This fee was previously required only before publishing an item to the public, but is now required for all Chrome Web Store developers.


2 Answers

It looks like you haven't stumbled upon the gmail.js project. It provides a rich API allowing to work with Gmail. However, please note that this project isn't maintained by Google. This means that any changes in the Gmail may break your extension and there is no guarantee that anyone will care to update gmail.js to address these changes.

like image 102
Konrad Dzwinel Avatar answered Sep 22 '22 06:09

Konrad Dzwinel


There is a nice API for interacting with the Gmail DOM here:

https://www.inboxsdk.com/docs/

The getting started example helps you add a button to the compose toolbar.

// Compose Button InboxSDK.load('1.0', 'Your App Id Here').then((sdk) => {     sdk.Compose.registerComposeViewHandler((composeView) => {         composeView.addButton({             title: 'Your Title Here',             iconUrl: 'Your Icon URL Here',             onClick: (event) => {                 event.composeView.insertTextIntoBodyAtCursor('This was added to the message body!')             }         })     }) }) 
like image 43
Danny Sullivan Avatar answered Sep 21 '22 06:09

Danny Sullivan