Daniel Vinay
Daniel Vinay

Reputation: 1

How can I observe a google translate DOM change?

I´m working around the google translate react bug, I've deactivated the translation in the HTML so it doesnt crash but I want to let know the user that Google Translate is not available on this page.

I´m setting this observer: ` useEffect(() => { const targetNode = document.documentElement; const config = { childList: true, subtree: true };

const callback = mutationList => {
  for (const mutation of mutationList) {
    if (mutation.type === 'childList') {
      toast.warning('Google Translate cannot be used in this page');
    }
  }
};
const observer = new MutationObserver(callback);
observer.observe(targetNode, config);
observer.disconnect();

});`

But its triggering with al the changes in the DOM, how can I only get the google translate change if its at all possible?

Upvotes: 0

Views: 46

Answers (0)

Related Questions