Skip to content

onVisibilityChange ​

The onVisibilityChange function adds a listener for changes in the browser tab's visibility.

Syntax ​

typescript
onVisibilityChange(listener: () => void): void;

Parameters ​

NameTypeDescription
listener() => voidFunction called when visibility changes

Returns ​

NameTypeDescription
–voidDoes not return a value

Examples ​

typescript
onVisibilityChange(() => {
  if (document.visibilityState === "hidden") {
    console.log("The tab became hidden");
  }
});

Notes ​

  • Useful for pausing or resuming tasks based on tab visibility.

References ​

Released under the MIT License.