KartikTalwar / gmail.js

Gmail JavaScript API
MIT License
3.76k stars 457 forks source link

Open email observer is only firing once #649

Open rukshn opened 3 years ago

rukshn commented 3 years ago

The open email observer is only fired once.

gmail.observe.on("open_email", function(id, url, body, xhr) {
  console.log("id:", id, "url:", url, 'body', body, 'xhr', xhr);
  console.log(gmail.get.email_data(id));
})

When running the following observer, it is only fired once when an email is opened, and will not fire again on subsequent openings of the same email. Any reason why and how to fix it?

Thanks

josteink commented 3 years ago

Hey there and thanks for reporting!

I'm honestly not sure, but it might be the same phenomena we're seeing with the view_email event, which is documented:

https://github.com/KartikTalwar/gmail.js#gmailobserveonaction-callback

If that's how open_email works too now (gmail keeps changing, after all), it might be a good idea to update the documentation with that information too.

If you want to look into why this happens and try to create a fix, I'm open to reviewing that, but I won't be investigating that myself, as I don't rely on that event for any of my production-extensions.

rukshn commented 3 years ago

Yes I'll try to see if there is a possible fix, but since both are not working (open and view email) it's really hard to catch an email open

josteink commented 3 years ago

In my extension I've relied on detecting hash-changes in the URL, with check for current-email as a more reliable check for "view email" kind of events.

It's clearly a work-around, but maybe it can work for you too?

rukshn commented 3 years ago

Yes that feels like a better and a reliable way than the current implementation

How are you looking for the hash change? by using an event listener? or does GmailJs provide a function for that?

josteink commented 3 years ago

MDN has the answer :)

https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onhashchange