Additional asset directory

Is there a way, and if so, how would I go about adding an additional directory after the extension is installed where image assets would be placed?

To add context. We’d like to allow users to save images locally to their machine that the extension would use. These images are optional for the user to download, and the reason is to remove unnecessary web requests to our server very time a page is loaded that has the image.

I know previously (I’m not sure about now?) that GreaseMonkey would create a directory in the profile and save script files to that directory.

Is this still possible, or do we need to store the image file data in Storage or IndexedDB as base64 and serve that instead?

The “additional directory” is most likely indexedDB: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Working_with_files

Also when using IndexedDB, make sure to store images as Blob, not base64. Else your users may experience very bad performance if they use some other add-ons, mostly adblockers: Performance issues due to add-on incompatiblity

One thing to note though, in Firefox you can send blobs using browser.runtime.sendMessage, in Chrome you cannot. But you can still convert them to base64 on the fly if needed or if you just want to display them, you can use URL.createObjectURL.

1 Like

Oh, that’s useful information, thanks! That probably would have been a pain to find out first hand. LOL