I have very simple code to log some message on window focus and blur events. It works fine on edge, firefox and brave browser and is not working consistently in the chrome browser. Is there any workaround to overcome this? as i couldn’t see any one mentioning this issue on internet. Below is my code.
Few times, i noticed it works and when the same page is opened in the new tab, the events are not fired
<!DOCTYPE html>
<html>
<head>
<title>Window Focus/Blur Logger</title>
<script>
window.addEventListener('focus', function() {
console.log('Window gained focus');
});
window.addEventListener('blur', function() {
console.log('Window lost focus');
});
</script>
</head>
<body>
</body>
</html>