let counter = 0;
const openInterval = setInterval(() => {
setTimeout(() => {
console.log("setTimeout", counter);
newWindow.close();
}, 9000);
newWindow = window.open("https://google.com");
counter++;
console.log("setInterval", counter);
if (counter === 5) {
console.log("END", counter);
clearInterval(openInterval);
}
}, 10000);
The set interval function opens a new window every 10 seconds, the setTimeout function runs 9 seconds after a window is opened, but it fails to close the window, and there wasn't an error in the console, how can this be fixed?