Open Bug 1383244 Opened 7 years ago Updated 2 years ago

Idle timeout doesn't always happen as expected with the `idle` api

Categories

(WebExtensions :: General, defect, P5)

55 Branch
defect

Tracking

(Not tracked)

People

(Reporter: pmorris, Unassigned)

Details

The idle timeout with the idle api[0] doesn't always work as expected.

I'm working on porting "Mind the Time"[1] to WebExtensions and have uploaded some beta releases.  Sometimes I'll leave my laptop sitting for awhile with a tab/window activated/focused.  Usually the idle timeout will happen and the right amount of time will be logged for the current domain, but sometimes the idle timeout does not happen and way too much time is logged.

This is on FF 55.0 dev edition, multi-process, on Ubuntu 16.04, with my own profile with many open tabs, other add-ons, and several windows open.  I've added console logging to the beta version of Mind the Time to explore the issue and it shows that the idle timeout does not always fire when I expect it to.

This leads to a regression in my addon's functionality that's blocking its migration to WebExtensions.

[0] https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/idle
[1] https://addons.mozilla.org/en-US/firefox/addon/mind-the-time/
Flags: needinfo?(amckay)
This sounds similar to bug 1359403, although that talks about alarms and suspension but not sure if its a duplicate. See also bug 1377744.
Flags: needinfo?(amckay)
Priority: -- → P5
I don't think this is a duplicate of either of those other bugs.  This one involves the `idle` api and AFAICT the others don't.  This bug is tricky because mostly the idle timeout works, but when it doesn't it makes the time logged by my add-on incorrect, sometimes making it off by many hours.  And that messes up its primary functionality.
I made a simple add-on to help with detecting/reproducing the issue:
https://addons.mozilla.org/en-US/firefox/addon/idle-api-tester/
Paul, sorry for the slow reply but can you narrow this down a bit?  Did the non-webextension version of Mind the Time use nsIIdleService?  And are the quirks you're seeing unique to webextensions?  (ie, did you see similar things when using nsIIdleService directly?)
Flags: needinfo?(paul)
Sure thing.  Before webextensions Mind the Time was built with the add-on sdk, and used the sdk's lower level apis for idle timeout functionality.  Below is the code that uses "sdk/system/events" and "user-interaction-active".  I've only seen these quirks after converting to webextensions, not with the previous sdk version of the add-on.

let systemEvents = require("sdk/system/events");

exports.addActivityListener = function(callback) {
    systemEvents.on("user-interaction-active", callback);
};

exports.removeActivityListener = function(callback) {
    systemEvents.off("user-interaction-active", callback);
};
Flags: needinfo?(paul)
Product: Toolkit → WebExtensions
Bulk move of bugs per https://bugzilla.mozilla.org/show_bug.cgi?id=1483958
Component: Untriaged → General
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.