WakeLock
Keep the screen from dimming or locking while your app is doing something the user is watching - presentations, dashboards, recipe steps - via the Screen Wake Lock API.
@inject Bit.Butil.WakeLock wakeLockMDN reference
Request as a hint, not a guarantee.
Returns true when the runtime exposes navigator.wakeLock. During prerender/SSR the check returns false rather than throwing, so defer it to OnAfterRenderAsync.
@inject Bit.Butil.WakeLock wakeLock
var supported = await wakeLock.IsSupported();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.
var acquired = await wakeLock.Request();
if (acquired)
{
// screen stays awake while the page is visible
}
// later:
await wakeLock.Release();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.
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();API reference
ValueTask<bool> IsSupported()ValueTask<bool> Request()ValueTask Release()ValueTask<IAsyncDisposable> RequestPersistent()ValueTask DisposeAsync()