Search code examples
javascriptajaxgoogle-chrome-extensiongmaildom-events

Alternative to DOMSubTreeModified event in JavaScript


I am developing a custom translation extension for GMail in chrome and need to trigger the content script when the user clicks on an email in his inbox.

Since GMail uses AJAX, I decided to use the DOMSubTreeModified event. My extension works, but it seems via console logging that the function that sits the translate keeps getting executed constantly, even though the email text remains the same.

DOMContentLoaded does not trigger. Can anyone suggest any alternative I can use? I guess a timer or something in GMail constantly updates the page and makes minor adjustments. I had even narrowed the element on which the event is generated.


Solution

  • It appears that you should be using gmail-specific events to know when a new email is loaded, not generic DOM events. This add-on is not official Google code, but if you look at how it works, you could probably discover how to observe all sorts of gmail events or you could just use it to solve your problems.