Skip to main content
Despia fires global window.focusin() and window.focusout() callbacks whenever the app moves between foreground and background. Define these functions in your web code to react to lifecycle changes such as resuming sessions, refreshing data, or pausing media.

Installation


How it works

The native runtime invokes window.focusin() when the app returns to the foreground and window.focusout() when it leaves. Attach handlers directly to the window object to receive these events.
The focusout callback fires once per background transition. The focusin callback fires every time the app returns to the foreground, including the first launch resume.

Refresh data on resume

Use focusin to revalidate session state or pull fresh content when the user returns to the app.

Pause activity on background

Use focusout to stop timers, pause video playback, or persist unsaved state before the app is suspended.

Track session duration

Combine both events to measure how long the user stays inside the app per session.

Resources

NPM Package

despia-native