I have an Angular app that opens a link to an external site in a new tab when I click a button and then checks in an interval, if the tab is closed and when it is closed do stuff.
This works sometimes, but sometimes this doesn't work. When I check if the tab is closed with window.closed it is sometimes true, although the tab is not closed.
This issue appeared about a week or two ago and hasn't happened before then. I made no changes at all (the app is running for 2 months on a server without any code changes or anything). I also tried an old version of Chrome and another PC and the issue is still there.
The code looks like this
webUrl = "https://www.google.com"
this.otherWindow = window.open(webUrl, 'otherWindowCtx');
const interval = setInterval(async () => {
if (this.otherWindow.closed) {
doStuff();
clearInterval(interval );
}
}, 5000);
The thing is, when webUrl is the link to Google (or almost any other site) it works as expected, but when I open the correct site that I need to open, it doesn't work. Is there anything a site could do to interfere somehow? Or is there an alternative way that I could try to open an external site in a new window and check when it is closed?