Why does my setTimeout stop working after a while?

I made an addon that plays a noise at the top of every hour. It was just a setTimeout that looped every hour. However, I user reported that it would stop working after a long period of time. To fix the issue, I tried having a setTimeout to check every minute in the background.js and then have that setTimeout function create another setTimeout function when it’s within a minute of the top of the hour. However, all of the setTimeouts stop triggering after a long period of time (like 10 hours for example). Never a consistent period of time and there is no obvious reason why this occurs.
Any ideas or workarounds?

The addon is Grandfather Fox on AMO if you want to download and decompress to view the addon’s source code. I think I may change the setTimeout to a Javascript interval instead of a setTimeout that loops, but I don’t see that fixing the issue. All help is much appreciated.

I’ve added a ton of console.logs into my code and will run it overnight and check the console in the morning to see if there are any errors and at what point the code stops triggering.

I have no idea why that happens, but the alarms API might work better. It is explicitly meant for long periods and also plays well with event pages.

1 Like

Ok nevermind my original question because the alarms API sets the event based on the actual time, not a countdown like the setTimeout. Much more reliable and exactly what I’m looking for. Thanks so much!

Ok now I’m confused.
I was testing it all day and each time I would set the time on my PC, the API would still trigger at the top of every hour, but since I uploaded it to AMO, that’s not the case anymore and I can’t get my source code to react the way it was previously either.