w3c / webextensions

Charter and administrivia for the WebExtensions Community Group (WECG)
Other
579 stars 50 forks source link

idle API: no way to reset the interval to default after idle.setDetectionInterval() #452

Open NV opened 9 months ago

NV commented 9 months ago

TL;DR: the default interval is not exposed so to revert it back to the initial value you have to hardcode the number from the documentation.

setDetectionInterval

chrome.idle.setDetectionInterval(
  intervalInSeconds: number,
)

Sets the interval, in seconds, used to determine when the system is in an idle state for onStateChanged events. The default interval is 60 seconds.

from: https://developer.chrome.com/docs/extensions/reference/idle/#method-setDetectionInterval (similar page on mdn)

Once you set the interval, it persists. There's no way to revert to the default interval. There's no way to read the current interval.

It would be nice to expose the default value, like so:

browser.idle.DEFAULT_INTERVAL_IN_SECONDS = 60

Similarly, there's no mention of the interval's minimum.

await chrome.idle.queryState(10) throws (at least in Chrome)

Uncaught TypeError: Error in invocation of idle.queryState(integer detectionIntervalInSeconds, function callback):
Error at parameter 'detectionIntervalInSeconds': Value must be at least 15.

It would be nice to expose:

browser.idle.MINIMUM_INTERVAL_IN_SECONDS = 15

Currently, I have to program defensively and wrap each setDetectionInterval and queryState call into try/catch, in case the minimum interval constant changes.