I was using setTimeout and recently setInterval in my extension (in content scripts) to fire events every n-seconds, since FF does it & Chrome introduced additional timer throttling in the background tabs for nested timers I’m thinking about other ways to handle it.
How can I achieve reliable functionality using Chrome/FF Alarms API?
The documentation states I can set periods (intervals) in minutes only (anything else will be rounded up to 1 minute)
I’m pretty sure Alarms are for long-time events, that’s why the minute-based granularity. The setup with milliseconds from epoch is just to make things more flexible if you need to schedule something at the specific time.
Anyway, as long as your tab is active, your setTimeout should work fine.
I do too understand it’s for long time events, but what about short-time events like stock trading?
So there is no alternative for precise timers in background tabs? How is this good for any serious business app that is expected to be running the same in the active and background tab? This makes Firefox useless for many things…
Are Firefox and Chrome not capable of handling very precise timers in the name of “saving battery life”?
This warmup API, I will use it for FF (thank you), but what about Chrome, it doesn’t have it. So now do I have to use some hacky solutions to keep my extension compatible cross browsers?
So setTimeout & setInterval has been throttled (slowed down) in background tabs, and there are no extension API replacement for those?
How is that a good thing for anyone?
I’ve already seen a bunch of weird, hacky solutions for background tab timers, but I guess browsers should give us replacement mechanisms for those or just make it work as it supposes to work?
If you’re worried about throttling, I’d assume you can always run the timers in the background page and use messaging, however the timing will be less accurate by then (same also applies to native messaging suggested above).
However, even if you manage to get an accurate timer for a background tab, its event loop may still be processed slower, so your actions will still happen slower. The only way around this would be to disable these resource optimizations the browser makes, which I’m not sure if that’s possible.