KartikTalwar / gmail.js

Gmail JavaScript API
MIT License
3.74k stars 455 forks source link

Uncaught TypeError: Cannot read properties of undefined (reading 'dom') #705

Closed cancan101 closed 2 years ago

cancan101 commented 2 years ago

It looks like this line is sometimes hit with api.tracker.watchdog not having been setup: https://github.com/KartikTalwar/gmail.js/blob/fe51f121362441ff17cea8a8008b309692f50895/src/gmail.js#L2658

from: https://github.com/KartikTalwar/gmail.js/blob/fe51f121362441ff17cea8a8008b309692f50895/src/gmail.js#L2179-L2190

josteink commented 2 years ago

So if you bind events before our insertion-observer had time to do anything at all (which would be very early), we have a race condition and things fail.

I guess manually calling out to insertion_observer() from api.observe.bind() to ensure it's always initialized could be an option?

What do you think?

cancan101 commented 2 years ago

I guess manually calling out to insertion_observer() from api.observe.bind() to ensure it's always initialized could be an option?

That sounds reasonable. I guess an alternative would be to change the predicate to:

observer && api.tracker.watchdog && api.tracker.watchdog.dom[observer]

So if you bind events before our insertion-observer had time to do anything at all (which would be very early), we have a race condition and things fail.

I am not seeing this regularly but when I looked over my extensions's error logs, I did see at least once instance of this.

josteink commented 2 years ago

That sounds reasonable. I guess an alternative would be to change the predicate to:

observer && api.tracker.watchdog && api.tracker.watchdog.dom[observer]

I guess that might be simpler and since insertion_observer() will only need to be called after we’ve registered an event, fixing it locally there is probably a better idea.

josteink commented 2 years ago

I went for the simpler approach. This should now be fixed in git master.

Let me know if helps :)

josteink commented 2 years ago

Updated on npmjs in version 1.0.23.