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)
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/alarms/create
It also states I can set EPOCH + n-milliseconds event timeouts:
" The time the alarm will fire first, given as milliseconds since the epoch."
So does it mean I cannot fire intervals in less than 1 minute periods?
But does it also mean I can fire single events in less than 1 minute periods using WHEN parameter (say EPOCH+100 ms)?
I’m confused.
My code workflow looks like this:
- Find entry on a page in DOM structure
- Read/Modify it
- Do n-seconds delay
- Scroll to the next item
- Goto 1
How can I do it without setTimeout / setInterval for background tabs, will Alarms let me fire those events every n-seconds?
I have tried to use Workers with moderate success, but I’m not sure if that’s the right solution.
I think the right question is how can I achieve a reliable timer (with n-seconds precision) in my extension in foreground & background tabs/windows?