/** * A minimal page lifecycle observer. * @see https://developer.chrome.com/docs/web-platform/page-lifecycle-api */ /** The page is visible and has focus. */ export declare const PAGE_STATE_ACTIVE = "active"; /** The page is visible but does not have focus. */ export declare const PAGE_STATE_PASSIVE = "passive"; /** The page is not visible. */ export declare const PAGE_STATE_HIDDEN = "hidden"; /** The browser has frozen the page to reclaim its resources. */ export declare const PAGE_STATE_FROZEN = "frozen"; /** The page is being unloaded. */ export declare const PAGE_STATE_TERMINATED = "terminated"; /** One of the states a page can be in. */ export type PageState = typeof PAGE_STATE_ACTIVE | typeof PAGE_STATE_PASSIVE | typeof PAGE_STATE_HIDDEN | typeof PAGE_STATE_FROZEN | typeof PAGE_STATE_TERMINATED; /** Called with the state the page has just entered and the one it left. */ export type PageStateListener = (state: PageState, previous: PageState) => void; /** * Reads the state the page is in right now. * @returns {PageState} The current page state. */ export declare const readPageState: () => PageState; /** * Starts observing the page, if it is not observed already. */ export declare const startPageLifecycle: () => void; /** * Returns the state the page is in, starting the observer on first use. * @returns {PageState} The current page state. */ export declare const getPageState: () => PageState; /** * Registers a listener for every state change. * @param {PageStateListener} listener - The listener to call on each change. * @returns {() => void} A function that removes the listener again. */ export declare const onPageStateChange: (listener: PageStateListener) => (() => void); /** * Runs a callback the next time the page becomes active, once. * @param {() => void} callback - The callback to run. * @returns {() => void} A function that cancels the pending callback. */ export declare const oncePageActive: (callback: () => void) => (() => void); /** * Drops every listener and stops tracking. Only the tests need this. */ export declare const resetPageLifecycle: () => void; //# sourceMappingURL=page_lifecycle.d.ts.map