I want to pass a single number from Firefox extension to external world, so that another application can get it. The only solution I can think of is to write it to a file in some known location, but I cannot find any simple way to do it. I've already tried Indexeddb and Nativemessages APIs according to Mdn, and failed.
So, what way is simplest or where can I find some good easy tutorial how to do it?
For security reasons, the only way to "save" and "read" the filesystem from JavaScript (not just extensions) is download and upload.
For extensions, browser.downloads.download
has a bit more functionality than programmatically clicking an <a download="whatever">
tag (possibly/frequently hidden). MDN has an example on the documentation page I linked.
Of course, downloading is also affected by the browser settings for the download directory and "Always ask where to save files." You get to decide if clicking on confirmations is part of the user experience you want (or is even acceptable).
As for those security reasons, it's really undesirable for JavaScript (even extensions) to be able to read or write any file anywhere in the filesystem transparently, possibly sending files from the filesystem to a nasty site or overwriting files in the filesystem with arbitrary malicious content. That's why so many malicious sites try to get you to click on them somewhere. They hijack that click to do stuff you didn't know it would do.