Module: idle

This module enables adding browser idle state listeners with varying detection intervals. The module is needed because the WebExtensions idle API currently only supports one detection interval per extension.

The implementation of this module combines the WebExtensions idle API and setTimeout. It configures the idle API to use the minimum idle detection interval with idle.setDetectionInterval(), adds a listener for the idle.onStateChanged event, and then uses setTimeout after the browser goes idle to notify idle state listeners with detection intervals greater than the minimum. If there are any pending idle notification timeouts when the browser goes active, those timeouts are cleared.

Some implementation quirks to be aware of for use and future development:

  • This module depends on configuring the detection interval for the idle API to its minimum value. Any subsequent changes to the idle state detection interval in the idle API will result in unpredictable behavior.

  • Idle state events generated by this module are not guaranteed to reflect idle state transitions (e.g., a listener might receive "active" followed by "active"). We might want to implement this guarantee eventually.

  • Because the browser idle state resets with each browser session, it is not a problem that timeouts do not persist between browser sessions.

  • The module does not directly interact with the Firefox nsIdleService, even though it supports varying idle state detection intervals, in order to minimize privileged extension code.

Source:

Namespaces

onStateChanged

Methods

(static) queryState(detectionIntervalInSeconds) → {string}

Determine whether the browser has been idle for a specified time. This function is synchronous, unlike idle.queryState. Note that, if an idle state listener has not been added, this function will always return the default value of active state.

Parameters:
Name Type Description
detectionIntervalInSeconds number

The detection interval to use.

Source:
Returns:
  • The idle state, either "idle" or "active".
Type
string