I've written a couple of articles on the proper Gmail API, why doesn't this just use that instead of scraping the DOM?
https://www.sitepoint.com/mastering-your-inbox-with-gmail-ja... https://www.sitepoint.com/sending-emails-gmail-javascript-ap...
https://www.sitepoint.com/mastering-your-inbox-with-gmail-ja... https://www.sitepoint.com/sending-emails-gmail-javascript-ap...
The big selling point for me is the observation of events like compose window. You can then write code that plugs into the gmail interface.