Was looking into some workarounds for the ongoing issues with MV3 on Chrome where the worker stops receiving any events and remains stuck in a running state.
Issue: https://bugs.chromium.org/p/chromium/issues/detail?id=1316588#c96The workaround referenced in the issue works, i.e.,
detect and call chrome.runtime.reload and we have been seeing reports that the issue is occurring for users with the workaround reloading the extension behind the scenes.
However, using
chrome.runtime.reload can lead to other issues such as content scripts getting disconnected, so i'm on the lookout for a safer way to reload the service worker.
Summarising the options:- Use an infinite loop to force the worker to be killed and restart (From the workaround above).
- Use
chrome.runtime.reload and unregister and re-register the content scripts / make them resilient.
A third option i'm exploring with the
release of Offscreen documents is to inject an offscreen document that can then unregister and re-register the service worker combined with
skipWaiting (so that it takes over immediately and doesn't get caught up in the other issue in MV3)
.Questions:- Are there any caveats I'm missing or new issues that would arise due to unregistering and re-registering the extension service worker?
- Are there other options that folks have explored and that have worked for them w.r.t the bug mentioned above.