概述Idle Detection API 提供检测用户与屏幕空闲的能力(如用户离开或屏幕锁定),需要权限与策略允许。适合自动保存、同步与后台任务调度等场景。示例(实验性)const detector = new IdleDetector() await detector.start({ threshold: 60_000 }) detector.addEventListener('change', () => { console.log(detector.userState, detector.screenState) if (detector.userState === 'idle') scheduleBackgroundSync() }) 工程建议权限与最小化:仅在必要场景启用;向用户透明说明用途。调度策略:在空闲时进行非关键任务;避免打扰与资源浪费。兼容:不支持时回退到基于交互超时的推断;记录效果。参考与验证Chrome 平台文档(Idle Detection):https://developer.chrome.com/docs/web-platform/idle-detection/web.dev Idle Detection 指南:https://web.dev/articles/idle-detection

发表评论 取消回复