Check if browser tab is focused

OSCC · JavaScript, Browser · Oct 20, 2020

Checks if the browser tab of the page is focused.

const isBrowserTabFocused = () => !document.hidden;
isBrowserTabFocused(); // true

Recommended snippets