dnakov / little-rat

🐀 Small chrome extension to monitor (and optionally block) other extensions' network calls
MIT License
2.08k stars 64 forks source link

Data is lost when service worker stops (after 30 seconds of inactivity). #3

Closed keithx2 closed 1 year ago

keithx2 commented 1 year ago

Maybe use storage.session to save and recover data.

dnakov commented 1 year ago

I haven't been able to reproduce this. If you have more info, lmk. Gonna keep it open for a few days.

keithx2 commented 1 year ago

Make sure the developer console for the extension is not open. Make sure there is no network activity for at least 30 seconds. The extension will go inactive in 30 seconds or less. When the extension restarts, the code in service-worker.js will run again and the variable 'extensions' will be empty. The 'extensions' variable should be saved in storage.session each time it is modified in the onRuleMatchedDebug listener. When the extension restarts, check to see if it exists in storage.session. If it does exist, use it to initialize the 'extensions' variable in service-worker.js when the extension restarts.

keithx2 commented 1 year ago

The extension is working much better now :)

I did notice one small problem. When I select 'Purge all caches' and then 'Update now' in the uBlock Origin dashboard, there will be 16 network calls. When the service worker is active, the counter is correct. The button badge shows 16 and when I open the popup, 16 is displayed for uBlock Origin. However, if the service worker is inactive when I press 'Update now', the button badge will show 16 and the popup will display 15 when I open it a few seconds later.