Check if the browser tab of the page is focused Use the Document.hidden property, introduced by the Page Visibility API to check if the browser tab of the page is visible or hidden. const isBrowserTabFocused = () => !document.hidden; // Example isBrowserTabFocused(); // true Source https://www.30secondsofcode.org/js/s/is-browser-tab-focused