This is a very general question. Sadly I cannot provide you with any code sample that could help to shed some light on this particular issue.
I have quite a complex script that works with window objects (main window or window from iframes). I store them to variables and work with them later.
This script has an error logging mechanism. It tries to catch all possible errors (unhandledrejection and error events) and sends them via beacon API to the backend service.
It works just fine for most of the users but I can see sometimes these types of logs.
currentWindow.removeListener is not a function
element instanceof currentWindow.HTMLElement - the right-hand side of 'instanceof' is not an object
currentWindow is just a variable I store when script loads. (const currentWindow = window). I am pretty sure the window object doesn't get altered from the user in any way and the window variable I store is not overwritten.
To me, it seems that window properties are getting cleared. I suspect it happens when the tab is (force) closed. I tried many things to replicate -- CPU throttling, force closing chrome etc.) I have literally no clue why it happens and cannot find any related info here or on google.
I should also note that it is not some issue with old browsers. It happens in the newest version of chrome as well as firefox.