This is somewhat a code/browser specific question, but I noticed that my setTimeout/setInterval code will eventually NEVER execute in the background even if the tab is not asleep. The following logs are from code that is supposed to execute every 1s and I'd be fine bumping that to ~15s which would work with Firefox, but not to every 3 minutes like Chrome/Edge seem to demand:
Took 1.6927670464932056 time to execute at Tue Mar 07 2023 15:03:26 GMT-0700 (Mountain Standard Time)
main-loop.service.ts:191 Took 1.6322318190016232 time to execute at Tue Mar 07 2023 15:03:29 GMT-0700 (Mountain Standard Time)
main-loop.service.ts:191 Took 1.6322318190016232 time to execute at Tue Mar 07 2023 15:03:29 GMT-0700 (Mountain Standard Time)
main-loop.service.ts:191 Took 1.5268028376189324 time to execute at Tue Mar 07 2023 15:03:31 GMT-0700 (Mountain Standard Time)
main-loop.service.ts:191 Took 1.5268028376189324 time to execute at Tue Mar 07 2023 15:03:31 GMT-0700 (Mountain Standard Time)
main-loop.service.ts:191 Took 1.4788079994765282 time to execute at Tue Mar 07 2023 15:03:34 GMT-0700 (Mountain Standard Time)
main-loop.service.ts:191 Took 1.4788079994765282 time to execute at Tue Mar 07 2023 15:03:34 GMT-0700 (Mountain Standard Time)
main-loop.service.ts:191 Took 1.4304450467780012 time to execute at Tue Mar 07 2023 15:03:36 GMT-0700 (Mountain Standard Time)
main-loop.service.ts:191 Took 1.4304450467780012 time to execute at Tue Mar 07 2023 15:03:36 GMT-0700 (Mountain Standard Time)
main-loop.service.ts:191 Took 1.4040571259142123 time to execute at Tue Mar 07 2023 15:03:46 GMT-0700 (Mountain Standard Time)
main-loop.service.ts:191 Took 1.4040571259142123 time to execute at Tue Mar 07 2023 15:03:46 GMT-0700 (Mountain Standard Time)
main-loop.service.ts:191 Took 1.428811537802659 time to execute at Tue Mar 07 2023 15:07:16 GMT-0700 (Mountain Standard Time)
main-loop.service.ts:191 Took 1.428811537802659 time to execute at Tue Mar 07 2023 15:07:16 GMT-0700 (Mountain Standard Time)
main-loop.service.ts:191 Took 1.4115845539280958 time to execute at Tue Mar 07 2023 15:10:16 GMT-0700 (Mountain Standard Time)
main-loop.service.ts:191 Took 1.4115845539280958 time to execute at Tue Mar 07 2023 15:10:16 GMT-0700 (Mountain Standard Time)
It gets progressively longer until eventually it is basically stopped. This is a game intended to run in the background so any settings/code that can work around this would be great.
Edit: What ended up working was to add in some background music. The volume has to be non-zero, but users can just mute the tab and background tasks will still work.