Fix images breaking on Firefox after a while (add heartbeat to prevent background page reap) #1852
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Since switching our image rendering to be over postMessage / MessageChannels, Firefox has had an issue where when its background page is reaped (which happens on MV3 extension on Firefox) after some time, and images will break on any existing tabs, while the rest of the extension will work (because sendMessage will cause the background page to come back alive, with a new worker, but the frontend will not know that it needs to reconnect to a new worker), and also new tabs will work because they will reconnect to the new backend worker.
I considered some different ideas (like ① putting a heartbeat directly in frontend worker to backend worker, and autoreparing, or ② having the backend signal all frontends that it's going byebye onSuspend), but in the end this idea was the simplest, to simply prevent the background page from dying.
The rest is as the comment says: