firefox add-on sdk: previously removed and reinstalled add-on doesn't work but shows up as installed in add-ons manager

StackOverflow https://stackoverflow.com/questions/23070142

  •  03-07-2023
  •  | 
  •  

Question

I just created a simple add-on with the SDK. I installed it and the icon shows up and everything works at once without a restart of firefox. Then I removed the add-on using the Add-ons Manager of firefox. After that I closed and reopened firefox and installed the add-on again and the Manager shows that the installation was successful. No error messages. But the icon doesn't show and nothing works.

The firefox console and the sdk console show no errors. My add-on stores one boolean in the sdk/simple-storage. Then I made a reset of firefox and installed it again and everything works fine.

Do you know, what causes this problem and how to solve it without resetting of firefox?

Was it helpful?

Solution

In my experience, reinstalling an add-on with the same version number is considered a downgrade. So save the version number in simple-storage then

const self = require('sdk/self');
const {storage} = require('sdk/simple-storage');
if (storage && storage.version===self.version && self.loadReason==='downgrade')
  storage = {};

Caveats:

  1. The assumption here is that if you (the developer) upgrade an add-on after someone uninstalls it and before they restart Firefox, then the reinstalled add-on will run as the old version again before updating itself automatically. Which I think is a safe assumption.
  2. If someone uninstalls then clicks Undo, that is not a reinstall/downgrade but an enable.

OTHER TIPS

As I expected, it's a bug in sdk/simple-storage. The simple storage files are not deleted when the add-on gets removed. This causes a problem when the same add-on gets reinstalled. When I delete the "jetpack" folder in the firefox profile folder, the reinstall works fine. So my solution to this: don't use simple-storage. When you know another workaround, please let me know.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top