useUserActivation

A React hook that tracks the browser's User Activation state to determine if a user has interacted with the page.

Warning

This API is not fully standardized across all browsers. Always check the isSupported flag before using its state in your logic.

Note

This is particularly useful for verifying if a "transient activation" (a recent click/tap) exists before calling restricted APIs like requestFullscreen.

Installation

bash

Description

The useUserActivation hook provides access to the navigator.userActivation API, which allows developers to check for "sticky" activation (has the user ever interacted?) and "transient" activation (is there a current interaction window?). This is critical for triggering restricted browser features like playing audio, opening popups, or accessing the clipboard, which often require a fresh user gesture.

Return values

NameTypeDescription
hasBeenActivebooleanIndicates if the user has performed at least one interaction (sticky activation) since the page loaded.
isActivebooleanIndicates if the user has interacted with the page recently enough to allow 'gated' APIs (transient activation).
isSupportedbooleanIndicates whether the UserActivation API is supported in the current browser.
refresh() => voidManually triggers a re-read of the navigator.userActivation state.

Demo

This component is loading.

Source code

tsx