IdleDetector Class

Observes the idle state of the user and of the screen (https://wicg.github.io/idle-detection/#api-idledetector), read from the IdleStateProvider of the browsing context (IdleDetectionOptions.Provider): the change event is fired when the state changes, once the detector is started.

public sealed class IdleDetector : EventTarget
Inheritance
EventTarget IdleDetector

Constructors

NameDescription
IdleDetector()Creates a detector for the current global object (https://wicg.github.io/idle-detection/#api-idledetector).
IdleDetector(GlobalScope)Creates a detector for a global object.

IdleDetector overloads

IdleDetector()

IdleDetection.cs

Creates a detector for the current global object (https://wicg.github.io/idle-detection/#api-idledetector).

public IdleDetector()

IdleDetector(GlobalScope)

IdleDetection.cs

Creates a detector for a global object.

public IdleDetector(GlobalScope global)
Parameters
global GlobalScope
The window or the dedicated worker whose detector it is.

Properties

NameDescription
OnChangeGets or sets the event handler of the change event.
ScreenStateGets the last known idle state of the screen, or null before the detector is started.
UserStateGets the last known idle state of the user, or null before the detector is started.

Gets or sets the event handler of the change event.

public Action<Event>? OnChange { get; set; }

ScreenState

IdleDetection.cs

Gets the last known idle state of the screen, or null before the detector is started.

public ScreenIdleState? ScreenState { get; }

Gets the last known idle state of the user, or null before the detector is started.

public UserIdleState? UserState { get; }

Methods

NameDescription
RequestPermission()Asks the user to allow the origin to detect the idle state (https://wicg.github.io/idle-detection/#api-idledetector-requestpermission), with BrowsingContextOptions.RequestPermission, unless the permission is already granted or denied. The task fails with an InvalidStateError DomException when the document is not fully active, and with a NotAllowedError when the window has no transient activation.
Start(IdleOptions?)Starts the detector (https://wicg.github.io/idle-detection/#api-idledetector-start): the change event is fired with the initial state, then at each change. The task fails with an InvalidStateError DomException when the document is not fully active or the detector is already started, a NotAllowedError when the document is not allowed to use the idle-detection feature or the idle-detection permission is denied, a TypeErrorException when the threshold is less than 60 seconds, and the abort reason of the signal when it is aborted.

RequestPermission()

IdleDetection.cs

Asks the user to allow the origin to detect the idle state (https://wicg.github.io/idle-detection/#api-idledetector-requestpermission), with BrowsingContextOptions.RequestPermission, unless the permission is already granted or denied. The task fails with an InvalidStateError DomException when the document is not fully active, and with a NotAllowedError when the window has no transient activation.

public static Task<PermissionState> RequestPermission()

Start(IdleOptions?)

IdleDetection.cs

Starts the detector (https://wicg.github.io/idle-detection/#api-idledetector-start): the change event is fired with the initial state, then at each change. The task fails with an InvalidStateError DomException when the document is not fully active or the detector is already started, a NotAllowedError when the document is not allowed to use the idle-detection feature or the idle-detection permission is denied, a TypeErrorException when the threshold is less than 60 seconds, and the abort reason of the signal when it is aborted.

public Task Start(IdleOptions? options = null)

Parameters

options IdleOptions?
The threshold, and the signal that stops the detector.

Returns

Task

See also