I’m inserting CSS into a tab using the insertCSS() method from the Tabs API. This works well except for when it comes to removing the CSS. Because the CSS is a dynamically generated string based on the user’s settings.
Currently, I’m keeping track of the CSS on each tab using a content script. When it’s time to remove the CSS, I just have the content script do it. This works, but is not ideal.
An issue I’m running into is that if the add-on is updated, the content scripts are reloaded, meaning the former CSS that was kept in the content script is lost, so I can no longer remove the previous CSS.
Is there a way to see what CSS has been previously added to the tab by the extension?
There is a different way to fix this - postpone addon update till restart (browser restart as well) by registering empty onUpdateAvailable
handler:
browser.runtime.onUpdateAvailable.addListener(details => {});
If the extension is not listening for this event when an update becomes available, the extension is reloaded immediately and the update is applied. If the extension is listening, then the update will be applied the next time the extension is reloaded.
Note that calling browser.runtime.reload();
will also update addon BUT it will also reset all popup warning messages approved by the user (if you have any).
1 Like
This is probably the cleanest way to go about it, although I won’t go as far as to stop the update process. I could just add some cleanup to the listener though and then reload.
It’s not exactly stopping, it’s only postponing till the next Firefox start.
I’ve noticed “uBlock Origin” is also using this. And I use it as well in some of my extensions because restarting extension stops all content scripts but the injected DOM stays on the page.
It’s poor practice because it doesn’t take into account people who rarely close the browser. In my experience, that would mainly be laptop users who just sleep their laptop with Firefox open.
I myself am guilty of this. Firefox stays open on my laptop for weeks, even months at a time.
Good point! But with OS updates and Firefox updates, both being released every 4 weeks the average waiting interval should be only 2 weeks
. That is on Windows, in Linux I guess you can stay whole month with same instance running.
But I’m pretty sure most users restart browser at least once a day (maybe we should make a Poll on Reddit to find out
).