Add isBrowserTabFocused, fixed is tests
This commit is contained in:
13
snippets/isBrowserTabFocused.md
Normal file
13
snippets/isBrowserTabFocused.md
Normal file
@ -0,0 +1,13 @@
|
||||
### isBrowserTabFocused
|
||||
|
||||
Returns `true` if the browser tab of the page is focused, `false` otherwise.
|
||||
|
||||
Use the `Document.hidden` property, introduced by the Page Visibility API to check if the browser tab of the page is visible or hidden.
|
||||
|
||||
```js
|
||||
const isBrowserTabFocused = () => !document.hidden;
|
||||
```
|
||||
|
||||
```js
|
||||
isBrowserTabFocused(); // true
|
||||
```
|
||||
Reference in New Issue
Block a user