Skip to content
On this page

useWakeLock

Category
Export Size
1.27 kB
Last Changed
7 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: false
Is Active: false

Usage

js
import { useWakeLock } from '@vueuse/core'

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

const { isSupported, isActive, request, release } = useWakeLock()

If request is called, isActive will be true, and if release is called, or other tab is displayed, or the window is minimized,isActive will be false.

Type Declarations

typescript
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
 */
export declare const useWakeLock: (options?: UseWakeLockOptions) => {
  isSupported: Ref<boolean>
  isActive: Ref<boolean>
  request: (type: WakeLockType) => Promise<void>
  release: () => Promise<void>
}
export type UseWakeLockReturn = ReturnType<typeof useWakeLock>
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
 */
export declare const useWakeLock: (options?: UseWakeLockOptions) => {
  isSupported: Ref<boolean>
  isActive: Ref<boolean>
  request: (type: WakeLockType) => Promise<void>
  release: () => Promise<void>
}
export type UseWakeLockReturn = ReturnType<typeof useWakeLock>

Source

SourceDemoDocs

Contributors

Anthony Fu
Jelf
HannesOberreiter
wheat
koheing

Changelog

v8.9.2 on 7/12/2022
81d92 - fix(all)!: isSupported becomes Ref instead of boolean for SSR compatibility (#1800)

Released under the MIT License.