Module: scheduling

This module enables subscribing to periodic events, currently on a daily or weekly schedule.

The module guarantees a lower bound on when the event will fire, rather than a precise time for when the event will fire. This constraint is because the browser may not be open when the event would next fire, and because the module attempts to wait for an idle state to avoid browser jank.

The heuristic for determining when to fire the next idle daily event is identical to the heuristic used for the idle-daily event issued by the Firefox nsIdleService.

  1. Wait a day since the most recent idle daily event, or if the extension was just installed, wait a day after install.
  2. Listen for the next idle state, with a detection interval of 3 minutes.
  3. If an idle state does not occur within 24 hours, shorten the detection interval to 1 minute.

The idle daily event fires as soon as the browser enters an idle state that satisfies the heuristic. The idle weekly event fires just after an idle daily event when it has been at least 7 days since the last idle weekly event.

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

  • This module does not subscribe to the idle-daily event from the nsIdleService to minimize privileged extension code and so that it runs on a different schedule from Firefox daily tasks (e.g., Telemetry).

  • This module uses setTimeout to handle corner cases where the browser goes idle before the idle daily event should fire and remains idle through when the idle daily event should fire. The timeouts are configured on startup (and periodically) based on timestamps in persistent storage, so it is not a problem that timeouts do not persist between browser sessions.

Source:

Namespaces

onIdleDaily
onIdleWeekly