KartikTalwar / gmail.js

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

Synchronous 'DOMNodeInserted' DOM Mutation Event is deprecated #766

Closed cancan101 closed 11 months ago

cancan101 commented 12 months ago

Seeing this warning from Chrome:

Listener added for a synchronous 'DOMNodeInserted' DOM Mutation Event. This event type is deprecated (https://w3c.github.io/uievents/#legacy-event-types) and work is underway to remove it from this browser. Usage of this event listener will cause performance issues today, and represents a risk of future incompatibility. Consider using MutationObserver instead.

which I think is coming from this line: https://github.com/KartikTalwar/gmail.js/blob/080b39455acba8620efbb50a7caf984af8fbdc86/src/gmail.js#L2678

there was some discussion about the implementation:

but it may be the case that this needs to be changed sooner than later.

josteink commented 12 months ago

Thats probably very likely yes. Thanks for the heads up.

I'm going to assume we can fix this somehow by making a non-synchronous handler instead (from the browsers POV). For my extension that's probably fine. I'm going to assume most people using our view_email events (and friends) don't have a hard-dependency on it being synchronous either.

Does anyone have time to look into what the alternate implementation looks like?

Kravimir commented 12 months ago

The alternative is to use a MutationObserver.

cancan101 commented 12 months ago

See https://developer.chrome.com/blog/mutation-events-deprecation/#use-mutationobserver-instead for migration suggestion.

I would think these might be able to be merged unless there is a reason one uses body and one uses document: https://github.com/KartikTalwar/gmail.js/blob/080b39455acba8620efbb50a7caf984af8fbdc86/src/gmail.js#L2678C33-L2702