User Activation API
User Activation API 用于检测当前网页的用户激活状态
该 API 通过 UserActivation 提供相关功能,并通过 navigator.userActivation 暴露实例使用
一些 API 的调用受用户激活行为的限制,在不满足条件时会抛出异常,可以使用该 API 检测是否已满足调用的条件
用户激活状态
用户激活状态的改变受如下事件的影响:
事件的 isTrusted 属性被设置为 true
事件的 type 属性为 keydown(需要不为 Esc 键或用户代理保留的快捷键)、mousedown、pointerdown(需要 pointerType 为 mouse)、pointerup(需要 pointerType 不为 mouse)、touchend
粘性激活
表示用户已经进行了交互行为
可通过 UserActivation 接口的 hasBeenActive 属性检测
瞬时激活
表示用户最近进行了交互行为
可通过 UserActivation 接口的 isActive 属性检测
示例
| 粘性激活 | 瞬时激活 |
|---|---|
| false | false |
类型
1 | interface UserActivation { |
链接
User Activation API
https://skyclouds2001.github.io/2023/11/15/User-Activation-API/

