Building a Gmail Forwarder Browser Extension with Flask and JavaScript

I have an idea for a browser extension that will add a context menu to the forwarding button in Gmail that will allow a user to select a language to translate an entire thread inside Gmail for forwarding to a foreign-language-speaking correspondent.

Time to learn how to do it.

My first Google search, “building Chrome extension with Python” yielded:

This user says that he used a minimal amount of JavaScript when writing his plugin in, which is great because I would prefer to use Python. He also links to a git repo with the source code from his Chrome extension, which I have also never built before, so I clone the repository and take a look.

Hmm I can see where there’s a POST request being sent to a server running on localhost which will be the Flask hook in my project.

So that’s an interesting thought. Let’s do another google search: “gmail browser extension forward email github” and see what other existing projects have been undertaken that might be similar and easier to work from & combine.

The purple links are the ones that seem most interesting to me. I am going to take a look at each of them in turn.

The first one looks very promising. It provides JavaScript classes to Gmail API.

He provides an extension to install to mess around with the API.

It looks like it gives us a very easy way to grab the email data for the currently open email thread.

So far in my mind that leaves two things left we need to do. Inject some DOM and JavaScript into the page for “Translate and Forward Thread” from a Chrome Extension, have it grab the email data, and somehow reconstruct it after translating and forwarding the email.