Firefox: Background event page gets terminated too early?
As others have described (e.g. https://github.com/ActivityWatch/aw-watcher-web/issues/112#issuecomment-2103150065 https://github.com/ActivityWatch/aw-watcher-web/issues/93#issuecomment-1597528638 https://github.com/ActivityWatch/aw-watcher-web/issues/20#issuecomment-767308305, ..), the extension seems to not send the data reliably.
I suspect this might be due to the Background event page getting terminated too early: https://github.com/Saghen/aw-watcher-web/blob/8ec8093b41e68a06c67f5e50218ec581901cf53a/src/background/heartbeat.ts#L67-L74
export const tabActivatedListener =
(client: AWClient) =>
async (activeInfo: browser.Tabs.OnActivatedActiveInfoType) => {
const tab = await getTab(activeInfo.tabId)
const tabs = await getTabs()
console.debug('Sending heartbeat for tab activation', tab)
heartbeat(client, tab, tabs.length)
}
I suspect that before these awaits have finished, the background page is already terminated.
One hint for this is that when I debug the background page in Firefox:
- This issue does not happen anymore (the timeline is continuous, before it had many empty spaced)
- It says
Background event page was not terminated on idle because a DevTools toolbox is attached to the extension.every now and then
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Background_scripts
An easy fix might be to set persistent: true in the manifest.json: https://github.com/ActivityWatch/aw-watcher-web/issues/107#issuecomment-1549483608
Ok just tried it, the latter seems to indeed fix the issue