概述Idle Detection 允许站点在用户与屏幕空闲时进行任务安排。需要权限请求并可设定阈值(毫秒)。用法/示例await IdleDetector.requestPermission() const detector = new IdleDetector() await detector.start({ threshold: 60000 }) detector.onchange = () => { console.log(detector.userState, detector.screenState) if (detector.userState === 'idle') scheduleBackgroundSync() } 工程建议将大体量的同步与清理任务延后至空闲时执行;限制单次任务时长避免突发卡顿。清晰告知用户后台处理逻辑并提供设置入口;遵守权限与隐私政策。在不支持环境基于 `visibilitychange` 与交互事件统计实现近似判断。参考与验证MDN:Idle Detection — https://developer.mozilla.org/docs/Web/API/Idle_Detection_APIweb.dev:Idle Detection — https://web.dev/articles/idle-detection

发表评论 取消回复