getDocumentVisibility
Category Elements
Returns the visibility of the document.
It can be used to check whether the document is in the background or in a minimized window, or is otherwise not visible to the user.
Demo
💡 Minimize the page or switch tab then return
Usage
Type definitions
import { type ConfigurableDocument } from '../../__internal__/configurable.js';
import type { CleanupFunction } from '../../__internal__/types.js';
interface GetDocumentVisibilityOptions extends ConfigurableDocument {
/**
* Whether to auto-cleanup the event listener or not.
*
* If set to `true`, it must run in the component initialization lifecycle.
* @default true
*/
autoCleanup?: boolean;
}
type GetDocumentVisibilityReturn = {
readonly current: DocumentVisibilityState;
/**
* Cleans up the event listener.
* @note Is called automatically if `options.autoCleanup` is `true`.
*/
cleanup: CleanupFunction;
};
/**
* Whether the document is visible or not.
* @see https://svelte-librarian.github.io/sv-use/docs/core/elements/get-document-visibility
*/
export declare function getDocumentVisibility(options?: GetDocumentVisibilityOptions): GetDocumentVisibilityReturn;
export {};