Working with the Storage API sync data

If someone is using the Sync area in the Storage API, the data stays on Firefox, even if the temporary extension is removed and then reinstalled. That can make it difficult for testing during development.

Is there an efficient way to have the Sync storage area cleared when you remove the temporary add-on?

In the past, I’ve manually typed the clear command into the debugger before removing the extension or used an onInstalled listener to clear the storage first. Surely there must be a better way though.

The fact that the data stays there even after reinstalling is one of the main features of Firefox Sync - you want your data to be backed up in the cloud and synchronized across your devices.

Maybe you can put the clearing command into your extension background script. That way every time the extension is reloaded, it will clear the storage. Or you can create a button that will execute that code.
If you are using Webpack or some other build tool, you should have available some variable to detect if you are running in Prod / Dev mode which you can use to make sure these can be executed only in Dev mode.

I’m using both of these methods to develop my extensions. Not to clear a Storage though, but I have a button to reload extension and I have a script that opens extension pages when extension reloads.

1 Like

Note that for “development only paths” you may also want to check the temporary flag in https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/runtime/onInstalled

2 Likes

Thank you for the info Martin!
I think this should be promoted much much more. I’m sure many developers would use it to help them setup development environment.

1 Like

Thanks for the information :slight_smile: