@rtorcato/browser-common / idle
idle
Functions
isIdleDetectionApiAvailable()
isIdleDetectionApiAvailable():
boolean
Defined in: idle/index.ts:10
Checks if the Idle Detection API is available in the browser.
Returns
boolean
Example
import { isIdleDetectionApiAvailable } from '@rtorcato/browser-common/idle'
if (isIdleDetectionApiAvailable()) startIdleTracking()
onIdle()
onIdle(
callback,options?):number
Defined in: idle/index.ts:27
Registers a callback to be called when the browser is idle (using requestIdleCallback). Falls back to setTimeout if not available.
Parameters
callback
(deadline?) => void
The function to call when idle.
options?
IdleRequestOptions
Optional options for requestIdleCallback.
Returns
number
The callback ID (for cancellation).
Example
import { onIdle, cancelIdle } from '@rtorcato/browser-common/idle'
const id = onIdle((deadline) => doWork(deadline))
cancelIdle(id)
cancelIdle()
cancelIdle(
id):void
Defined in: idle/index.ts:47
Cancels an idle callback registered with onIdle.
Parameters
id
number
The callback ID returned by onIdle.
Returns
void
Example
import { cancelIdle } from '@rtorcato/browser-common/idle'
cancelIdle(id)
detectIdle()
detectIdle(
onIdle,onActive?):Promise<IdleDetector|null>
Defined in: idle/index.ts:83
Uses the Idle Detection API to run a callback when the user/system is idle. Requires permissions and a secure context.
Parameters
onIdle
() => void
Callback when idle.
onActive?
() => void
Optional callback when user becomes active.
Returns
Promise<IdleDetector | null>
The IdleDetector instance, or null if not available.
Example
import { detectIdle } from '@rtorcato/browser-common/idle'
const detector = await detectIdle(() => lockUI(), () => unlockUI())