Skip to content

useWakeLock

Category
Export Size
1.04 kB
Last Changed
2 months ago

Reactive Screen Wake Lock API. Provides a way to prevent devices from dimming or locking the screen when an application needs to keep running.

Demo

Is Supported: true
Is Active: false

Usage

ts
import { 
useWakeLock
} from '@vueuse/core'
const {
isSupported
,
isActive
,
forceRequest
,
request
,
release
} =
useWakeLock
()

When request is called, the wake lock will be requested if the document is visible. Otherwise, the request will be queued until the document becomes visible. If the request is successful, isActive will be true. Whenever the document is hidden, the isActive will be false.

When release is called, the wake lock will be released. If there is a queued request, it will be canceled.

To request a wake lock immediately, even if the document is hidden, use forceRequest. Note that this may throw an error if the document is hidden.

Type Declarations

ts
type 
WakeLockType
= "screen"
export interface WakeLockSentinel extends EventTarget {
type
:
WakeLockType
released
: boolean
release
: () =>
Promise
<void>
} export type
UseWakeLockOptions
=
ConfigurableNavigator
&
ConfigurableDocument
/** * Reactive Screen Wake Lock API. * * @see https://vueuse.org/useWakeLock * @param options * * @__NO_SIDE_EFFECTS__ */ export declare function
useWakeLock
(
options
?:
UseWakeLockOptions
): {
sentinel
:
ShallowRef
<WakeLockSentinel | null, WakeLockSentinel | null>
isSupported
:
ComputedRef
<boolean>
isActive
:
ComputedRef
<boolean>
request
: (
type
:
WakeLockType
) =>
Promise
<void>
forceRequest
: (
type
:
WakeLockType
) =>
Promise
<void>
release
: () =>
Promise
<void>
} export type
UseWakeLockReturn
=
ReturnType
<typeof
useWakeLock
>

Source

SourceDemoDocs

Contributors

Anthony Fu
SerKo
Anthony Fu
Jelf
IlyaL
Fernando Fernández
OrbisK
_Kerman
vuff
HannesOberreiter
wheat
koheing

Changelog

v13.6.0 on
d32f8 - refactor: add @__NO_SIDE_EFFECTS__ annotations to all pure functions (#4907)
v12.4.0 on
dd316 - feat: use passive event handlers everywhere is possible (#4477)
v12.0.0-beta.1 on
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)
v11.0.0-beta.2 on
5ca57 - fix: should delay wake lock request if document is hidden (#4055)

Released under the MIT License.

Build faster with AI
New Masterclass to help you leverage AI in your Vue workflow
Get Early Access