fix: MV3 service worker termination kills the background refresh and the 24h phishing list update #158
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
Two recurring jobs are scheduled with
setIntervalinside the Chrome MV3service worker, which is terminated after roughly 30 seconds idle. Neither
survives:
src/background/index.js:614—setInterval(backgroundRefresh, 60000), the60-second balance refresh.
src/shared/phishingDomains.js:166—setInterval(updatePhishingList, 24h).In practice both run only at service-worker startup.
README.md:614-617promises the phishing list is refreshed "once every 24 hours"; on Chrome that
is false. Phishing protection is a security feature, so silently degrading to
"vendored list only, refreshed whenever the worker happens to restart" matters.
Related, same root cause:
src/shared/phishingDomains.js:39-70useslocalStorage, which does not exist in an MV3 service worker. It is inside atry/catchso it degrades silently, which makes theREADME.md:618-619claimthat "The delta is persisted to localStorage if it is under 256 KiB" false on
Chrome.
Implementation requirements
setIntervalschedules withchrome.alarms(via the sharedcompat module if the Firefox compat work has already landed; otherwise
in a way that does not conflict with it). Alarms survive worker termination
and are the supported MV3 mechanism.
"alarms"permission tomanifest/chrome.json, which does notcurrently request it. Check whether
manifest/firefox.jsonneeds it too forthe MV2 path, and keep MV2 working — a persistent background page there does
not have the same constraint, so the shared code must behave correctly under
both.
chrome.alarmshas a minimum period (1 minute) — confirm the60-second refresh is still expressible, and adjust the interval with a note
in the PR if it is not.
localStorageuse inphishingDomains.js:39-70with theextension storage API so the delta actually persists on Chrome. Keep the
256 KiB cap behaviour. Note that
src/shared/ens.js:12-29also useslocalStorage, but only from popup context where it is valid — leave italone, and add a brief comment there recording that it is popup-only, so a
future change does not pull it into the worker.
not only on the first alarm tick.
README.md:614-619if the resulting behaviour differs at all fromwhat is documented there.
Definition of done
setIntervalremains insrc/background/orsrc/shared/phishingDomains.js.chrome.alarmsdrives both jobs;"alarms"is present inmanifest/chrome.json.verified by letting the worker idle out, then confirming the delta is
still applied.
terminated and revived.
localStorageuse in any code reachable from the serviceworker;
ens.jscarries a popup-only comment.README.mdmatches the implemented behaviour.TODO.mdupdated in the same commit.make checkpasses.