WakeLockSentinel

Experimental: 这是一个实验中的功能
此功能某些浏览器尚在开发中,请参考浏览器兼容性表格以得到在不同浏览器中适合使用的前缀。由于该功能对应的标准文档可能被重新修订,所以在未来版本的浏览器中该功能的语法和行为可能随之改变。

安全上下文: 此项功能仅在一些支持的浏览器安全上下文(HTTPS)中可用。

The WakeLockSentinel interface of Screen Wake Lock API provides a handle to a platform wake lock used to prevent screen from turning off, dimming, or displaying a screen saver.

属性

WakeLockSentinel.type (en-US) 只读

Wake lock type. Currently it is always "screen".

方法

WakeLockSentinel.release() (en-US)

Returns a Promise that resolves without a value after requesting the underlying wake lock is released.

事件处理程序

WakeLockSentinel.onrelease (en-US)

Event handler for release event type which occurs when WakeLockSentinel object's handle has been releases due to either a release() method being called or because User Agent releases the lock.

示例

The following example acquires a screen wake lock and then releases it in 10 minutes:

function tryKeepScreenAlive(minutes) {
  navigator.wakeLock.request("screen").then(lock => {
    setTimeout(() => lock.release(), minutes * 60 * 1000);
  });
}

tryKeepScreenAlive(10);

规范

Specification
Screen Wake Lock API
# the-wakelocksentinel-interface

浏览器兼容性

BCD tables only load in the browser

相关链接