gmail.js icon indicating copy to clipboard operation
gmail.js copied to clipboard

Load on click only?

Open vtexperts opened this issue 5 years ago • 5 comments

Question - can I load gmail.js on a click in my extension? instead of loading it on every email i open?

Thanks

vtexperts avatar Dec 14 '18 18:12 vtexperts

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.

josteink avatar Dec 17 '18 07:12 josteink

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.

vtexperts avatar Dec 17 '18 18:12 vtexperts

Sorry. I'm a paid full time developer, and I don't take freelance jobs.

josteink avatar Dec 18 '18 09:12 josteink

Here's what I have:

Step 1: Check the gmail request and bind the "open_email" event: step1

Step 2: Handle "open_email" event and notify corrensa that the event is triggered : step2

Step 3: Get the email data from the email content : step3


Any ideas what could be causing the lag?

vtexperts avatar Dec 27 '18 15:12 vtexperts

From what I can tell, you do things mostly by the book.

  1. You register the event (hopefully only once!)
  2. You intercept the event.
  3. You defer the expensive parts of the your event-handling logic until after Gmail.js has completed its event-cycle (via setTimeout())
  4. 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.

josteink avatar Jan 03 '19 09:01 josteink

Old issue is old. Closing.

josteink avatar Oct 11 '23 08:10 josteink