reddit-moderator-toolbox
reddit-moderator-toolbox copied to clipboard
Manifest v3 support
I could have sworn we already had an issue but I can't find it.
https://developer.chrome.com/docs/extensions/mv3/
We can start working on it but only reasonably implement it once firefox is also ready unless we want to keep two versions of the manifest and the affected areas in the code. https://blog.mozilla.org/addons/2021/05/27/manifest-v3-update/
Looking at these are some areas we need to make changes to:
- [x] Service workers replace background pages. See also this and this page. It seems like our caching mechanism will be the biggest challenge there as it depends on persistent data, which is no longer possible.
- [x] Manifest: Host permissions
- [x] Manifest: Web-accessible resources
- [x] Double check we are not using any of the deprecated APIs
The deadline for this appears to be the start of 2023.
Started looking into this a little bit again. Caching does seem to be the biggest hurdle as far as I can tell. The way our caching is set up it times out after a certain period, we use active timers for that. Once of those timers expires, the background page sends an event to all tabs so cache is cleared across the board.
This doesn't work with service workers because they are event based and don't stay active. However, it seems like for whatever reason (I honestly can't remember) this event is only handled in TBCore here: https://github.com/toolbox-team/reddit-moderator-toolbox/blob/master/extension/data/tbcore.js#L1431
We also use local storage right now, but that isn't really an issue.
My current thinking is something along the lines of:
- We start storing cache together with a timestamp.
- If a cache value is requested we check against the timestamp if it might be stale.
- If we do need a proactive timer on caching (needs investigating) we move that to the content_scripts where it basically will trigger based on whatever frontend script first times out after which that script will send a global event to all other tabs. (We already do have this mechanism).
Naturally this needs a bit more refining, I also do need to look into our caching once more to trace back my thoughts on implementing this.
Modqueue caching is a seperate mechanism, it uses a local map to store it's cache. This likely needs to be moved to an extension storage object.
Instead of refactoring all the cache related timeouts we might be able to leverage alarms
- https://developer.chrome.com/docs/extensions/reference/alarms/
- https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/alarms
- https://stackoverflow.com/questions/66391018/how-do-i-call-a-function-periodically-in-a-manifest-v3-chrome-extension
Seems like it might be a good fit... but the behavior I am reading does need some more consideration.
For some reason we still have a jquery ajax call in the background scripts https://github.com/toolbox-team/reddit-moderator-toolbox/blob/master/extension/data/background/handlers/notifications.js#L136
Needs to be replaced with a regular request.
I don't think there's anything left in this issue that needs addressing, so I'm closing it now. We can track moving to MV3 for Firefox in a separate issue, but I don't think it makes sense for us to prioritize that right now since Chrome and FF are on completely different schedules for that, so I won't bother making anything for that until it comes up