--- title: WakeLock.request() slug: Web/API/WakeLock/request translation_of: Web/API/WakeLock/request ---
{{APIRef("Screen Wake Lock API")}}{{SeeCompatTable}}{{securecontext_header}}
WakeLock.request()
方法用来获取屏幕唤醒锁定权限,防止屏幕变暗、关闭或展示屏幕保护程序。
WakeLock.request(wakeLockType)
wakeLockType
"screen"
。决议为 {{DOMxRef("WakeLockSentinel")}} 的 {{JSxRef("Promise")}}。
NotAllowedError
以下示例获取屏幕唤醒锁定并在 10 分钟后释放它:
function tryKeepScreenAlive(minutes) { navigator.wakeLock.request("screen").then(lock => { setTimeout(() => lock.release(), minutes * 60 * 1000); }); } tryKeepScreenAlive(10);
规范 | 状态 | Comment |
---|---|---|
Screen Wake Lock API | Editor's Draft | Initial specification. |
{{Compat("api.WakeLock.request")}}