Accessing filesystem in WebExtensions addon

I have an addon, Redirector, which stores its data in a file in the profile folder. I’m currently rewriting it to use the new WebExtensions api, and want to migrate the contents of the file into chrome.storage. However, in my new version I can’t read the file to migrate it, since as far as I can tell there’s no filesystem access in a webextensions addon.

Is there any way for me to do this? Can I use anything from the addon sdk (e.g. io/file) in a webextensions addon? If not, then that seems pretty hard for authors that want to migrate their addons to the new api, if there’s no support for things like this to help us migrate our users to newer versions.

WebExtensions are still in development. Even when they come around the SDK based addons will still work, only XUL will be deprecated. However there is https://webextensions.uservoice.com/forums/315663-webextension-api-ideas where you can voice yourself that the API is needed.

1 Like

I know the SDK based addons will still work, but will it be possible to access addon sdk APIs from WebExtensions addons? Because I want to use WebExtensions as much as possible, but at the same time be able to use the addon sdk apis, at least those that will continue to be supported in the future.

Thanks for pointing me to uservoice, I’ve posted my idea there as well :slight_smile:

Sadly no, they are discontinuing work on the SDK APIs and switching to WE APIs, which are being developed separately. At least that’s the plan as they currently see it, which they said was 12-18 months out. Given how long its taken them to roll-out mandatory signatures, I’d give it at least 18-24 months. Your best bet for now would be to just use the SDK and wait for things to become stable, as WE is not even in beta Firefox builds yet.

1 Like

If you have a WE addon there will be a folder in profile called browser-extension-data/addon/storage.js.
The storage.is a json file so you can convert your old data to json data format and paste it into storage.js.
If you have done this, you can read the data with chrome.storage.get.

Maybe you can as first implement in your old addon to store data in json format, then later it could be copied and pasted into storage.js if you need up to date data in your WE addon.

Yeah, I’ve been thinking about that I could do an intermediate version that starts storing the data in storage.js so when I switch to WE it will just work. I would just prefer to not have to make a special version just for this migration. If there’s no file access possible in WE I’ll probably just make the users do a one time migration after the upgrade, which kind of sucks, but would work.

Hopefully OS.File doesn’t go away it is frickin awesome. Use that for now, I doubt it will go away, tons of work went into it, and its really a great API: https://developer.mozilla.org/en-US/docs/JavaScript_OS.File/OS.File_for_the_main_thread

That’s the thing, I can’t use that, not in a WebExtensions addon. Anyway, we’ll see, maybe they’ll add some way of accessing it before they release WE.