loading
Note:
Secure context, and the browser has the last word The Screen Wake Lock API requires a secure context (HTTPS or localhost). The browser automatically releases the lock whenever the page is hidden (tab switch, minimize, screen off) and may refuse a request outright - for example in battery-saver mode. Treat the boolean result of Request as a hint, not a guarantee.

Support check

IsSupported

Returns true when the runtime exposes navigator.wakeLock. During prerender/SSR the check returns false rather than throwing, so defer it to OnAfterRenderAsync.

C#
@inject Bit.Butil.WakeLock wakeLock

var supported = await wakeLock.IsSupported();
Live sample
support check output
Results will appear here when you interact with the samples.

Request and release

Request / Release

Request acquires a screen wake lock and returns true on success. Release drops the most recently acquired lock; it is a no-op when nothing is held, so it's always safe to call from cleanup code.

C#
var acquired = await wakeLock.Request();
if (acquired)
{
    // screen stays awake while the page is visible
}

// later:
await wakeLock.Release();
Live sample
Status No lock requested yet.
request / release output
Results will appear here when you interact with the samples.

Persistent lock

RequestPersistent

Browsers always release the wake lock when the page is hidden. RequestPersistent acquires a lock and re-acquires it automatically every time the page becomes visible again - dispose the returned handle to stop the auto-reacquire and release the lock.

C#
private IAsyncDisposable? _persistent;

_persistent = await wakeLock.RequestPersistent();

// screen stays awake across tab switches - the lock is restored on resume

// stop and release:
await _persistent.DisposeAsync();
Live sample
Persistent lock Inactive
persistent lock output
Results will appear here when you interact with the samples.

API reference

Member
Signature
Description
IsSupported
ValueTask<bool> IsSupported()
True when the runtime exposes navigator.wakeLock. Returns default (false) during prerender/SSR instead of throwing.
Request
ValueTask<bool> Request()
Requests a screen wake lock; returns true when acquired. The lock is released explicitly or when the user-agent decides (typically when the page is hidden).
Release
ValueTask Release()
Releases the most recently acquired lock if it is still active. No-op otherwise.
RequestPersistent
ValueTask<IAsyncDisposable> RequestPersistent()
Acquires a wake lock and re-acquires it whenever the page becomes visible again. Dispose the handle to stop the auto-reacquire and release the lock.
DisposeAsync
ValueTask DisposeAsync()
Releases any held lock. Called automatically on scope/circuit teardown.
An unhandled error has occurred. Reload 🗙