The UserActivation
interface provides information about whether a user is currently interacting with the page, or has completed an interaction since page load.
This API is only available in the window context and not exposed to workers.
Since November 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
The UserActivation
interface provides information about whether a user is currently interacting with the page, or has completed an interaction since page load.
This API is only available in the window context and not exposed to workers.
UserActivation.hasBeenActive
Read only
Indicates whether the current window has sticky user activation.
UserActivation.isActive
Read only
Indicates whether the current window has transient user activation.
An object of this type is accessed via the navigator.userActivation
property, and can be used to query information about a window's user activation state.
A user activation either implies that the user is currently interacting with the page, or has completed an interaction since page load. User activation can be triggered by a button click, pointer touch, or some other user interaction with the page.
There are two kinds of window user activation states:
See Features gated by user activation for more information and a list of APIs that require either sticky or transient user activation.
Use navigator.userActivation
to access the UserActivation
object, and then UserActivation.isActive
to check whether the user is currently interacting with the page (Transient activation).
if (navigator.userActivation.isActive) { // proceed to request playing media, for example }
Use UserActivation.hasBeenActive
to check whether the user has ever interacted with the page (Sticky activation).
if (navigator.userActivation.hasBeenActive) { // proceed with auto-playing an animation, for example }
Specification |
---|
HTML Standard # the-useractivation-interface |
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | ||
UserActivation |
72 | 79 | 120 | 60 | 16.4 | 72 | 120 | 51 | 16.4 | 11.0 | 72 | |
hasBeenActive |
72 | 79 | 120 | 60 | 16.4 | 72 | 120 | 51 | 16.4 | 11.0 | 72 | |
isActive |
72 | 79 | 120 | 60 | 16.4 | 72 | 120 | 51 | 16.4 | 11.0 | 72 |
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/UserActivation