gmail.js
gmail.js copied to clipboard
Load on click only?
Question - can I load gmail.js on a click in my extension? instead of loading it on every email i open?
Thanks
You can load gmail.js at any time you want, but I'm not sure I understand the question.
You typically only load gmail.js once, and keep a reference to that object which you keep using again and again. You certainly should not load it for every email opened.
To help eliminate some confusion, it might help if you provided a code-example for your use-case, and I can provide feedback on that.
Instead, I would like to privately share the solution that we have and possibly get some input. Someone experienced, like you, I hope should be able to point out the problem. Our team is stuck with this, we have no idea what the problem is and from what I know, gmail.js should not add 3-5 lag to my gmail.
I'm looking someone "for hire" to do a quick analysis to help us understand the issue.
Let me know if @josteink you could assist. You will be compensated for you time.
Sorry. I'm a paid full time developer, and I don't take freelance jobs.
Here's what I have:
Step 1: Check the gmail request and bind the "open_email" event:
Step 2: Handle "open_email" event and notify corrensa that the event is triggered :
Step 3: Get the email data from the email content :
Any ideas what could be causing the lag?
From what I can tell, you do things mostly by the book.
- You register the event (hopefully only once!)
- You intercept the event.
- You defer the expensive parts of the your event-handling logic until after Gmail.js has completed its event-cycle (via
setTimeout()
) - You try to fetch email-data about the currently open email (
adapter.gmail.get.displayed_email_data()
) via GmailJS XHR.
Unless you are registering the event multiple times, or gmail is somehow throttling your XHR-requests, there's nothing about this code which looks fundamentally wrong.
That said I have the following remarks:
-
adapter.gmail.get.email_data()
should be sufficient, and possibly cheaper. - GmailJS XHR is going to be a source of complete breakage in 2019 when Google obsoletes old gmail, so if you rely on that, your extension will break and we can't fix it.
- I recommend migrating to
gmail.new.get.email_data()
which doesn't rely on XHR, returns data instantly and should be future proof once Google obsoletes old gmail.
Please note the following things about gmail.new.get.email_data()
:
- It requires new-style GMail IDs.
- The data-format returned is different from
gmail.get.email_data()
. You will need to adapt your code. - It is not backwards compatible with old Gmail.
This may not have been the answer you wanted, but hopefully it's still helpful.
Old issue is old. Closing.