Ad- don SDK: saveAs dialog

In the background script I have a binary blob and a file name suggestion.
Now Id like do display the “download” or a save as dialog for that blob.
Previously I just grabbed the current content window and programmatically clicked a link to the blob, but that breaks with e10s.

How can I achieve something like this directly from the background script?

Can you not programmatically click it from within content script?

You can use nsIFilePicker it has to run from main.js/index.js with mode modeSave. It gives you very fine tuned control.

Here is a simple example:

https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIFilePicker#Example

This is an example of something I use, it shows how I have options for prefilling it with a recommended filename, extension filters, etc.

https://github.com/Noitidart/NativeShot/blob/cab3d3e62d1abc4e95ea93a17b8c08e87d2cffde/bootstrap.js#L2215-L2239

Yes I had tried that from a SDKs tab.attach() content script. For some reason it does not work with blob:-urls created in the background (opening the same url in a tab works, so the url itself is fine).
Now I just got it working by passing a base64 data-url to the content script; with the obvious performance drawback for large files.
But I will leave it that way for now. I don’t really expect the files (e-books) to get any larger than say 30MB.

The nsIFilePicker seems a bit overkill to me, considering “downloading” something is an every-day web thing. And I also like to have the possibility to directly open the files, which an nsIFilePicker approach wouldn’t provide.

But thanks for your time anyway!

1 Like