use-wake-lock
Keep the screen awake with the Screen Wake Lock API.
| Package | @vizejs/composable/use-wake-lock |
| Own the source | vize lib pull composable:use-wake-lock |
| Runtime exports | useWakeLock |
| Gzip budget | 2048 B |
Usage
import { useWakeLock } from "@vizejs/composable/use-wake-lock";
Runtime contract
| Utility | Category | Stability | SSR | Hydration | Cleanup | Targets | Host globals | Uses |
|---|---|---|---|---|---|---|---|---|
useWakeLock |
system | experimental | deterministic-fallback | caller-managed | caller, reactive-scope | web, desktop | window |
tryOnScopeDispose |
API
useWakeLock
Keep the screen awake with the Screen Wake Lock API. Browsers release screen locks when the page is hidden; while a lock is requested, it is re-acquired on the next visibilitychange to visible. Request failures (missing user activation, battery saver) are exposed through error rather than thrown. The lock and the visibility listener are released when the owning reactive scope stops. Server rendering: nothing is requested, supported and active are false.
function useWakeLock(options: UseWakeLockOptions = {}): WakeLockControls
const wakeLock = useWakeLock();
const startPresentation = () => wakeLock.request();
Types
WakeLockSentinelLike
Minimal WakeLockSentinel consumed by useWakeLock.
| Member | Type | Description |
|---|---|---|
released |
boolean |
Whether the platform already released this lock. |
release |
() => Promise<void> |
Release the lock. |
WakeLockHost
Capabilities used by useWakeLock.
| Member | Type | Description |
|---|---|---|
wakeLock |
{ /** Request a lock of |
Screen Wake Lock API (navigator.wakeLock). |
document? |
{ /** Current visibility. / readonly visibilityState: string; /* Subscribe to |
Document whose visibilitychange re-acquires a lock the platform released while the page was hidden. |
UseWakeLockOptions
Options for useWakeLock.
| Member | Type | Description |
|---|---|---|
host? |
MaybeRefOrGetter<WakeLockHost | null | undefined> |
Wake Lock capability for alternate runtimes and tests. |
reacquireOnVisible? |
boolean |
Re-acquire a requested lock when the page becomes visible again (the platform releases screen locks whenever the page is hidden). |
WakeLockControls
Reactive state and actions returned by useWakeLock.
| Member | Type | Description |
|---|---|---|
supported |
ComputedRef<boolean> |
Whether the Screen Wake Lock API is available. |
active |
Readonly<Ref<boolean>> |
Whether a lock is currently held. |
requested |
Readonly<Ref<boolean>> |
Whether the caller wants a lock: set by request, cleared by release. While requested, the lock is re-acquired after visibility returns. |
error |
Readonly<ShallowRef<unknown>> |
Most recent request failure (for example NotAllowedError), cleared on success. |
request |
(type?: WakeLockKind) => Promise<boolean> |
Request a wake lock. |
release |
() => Promise<void> |
Release the lock and stop re-acquiring it. Repeated calls are safe. |