Chrome extension setTimeout not working properly Chrome extension setTimeout not working properly google-chrome google-chrome

Chrome extension setTimeout not working properly


I suspect the problem may with the automatic suspension of event pages after some period of inactivity. On my machine, onSuspend seems to called after ~10 seconds.

https://developer.chrome.com/extensions/event_pages#lifetime notes that

Once the event page has been idle a short time (a few seconds), the runtime.onSuspend event is dispatched. The event page has a few more seconds to handle this event before it is forcibly unloaded.

So, that may get you more around 13 seconds before the page is actually unloaded (giving you some cleanup time in onSuspend, I reckon). Then your page is unloaded and code initiated from there is no longer run.

https://developer.chrome.com/extensions/event_pages#transition says to use the alarms api for event pages instead of setTimeout.