I spent 4 hours trying to find a solution for loading a file into my Firefox Add-on. But, with no success (((.
The code I have:
const {TextDecoder, OS} = Cu.import("resource://gre/modules/osfile.jsm", {});
var decoder = new TextDecoder();
var promise = OS.File.read("C:\\test.txt");
promise = promise.then(function onSuccess(array) {
alert(decoder.decode(array));
});
It's impossible to force the code above to run (((. What am I doing wrong?
The code you have basically works as written. However, that assumes that
alert()
is defined and there was no error when you tried to read the file. However,alert()
will not normally be defined, unless you have defined it somewhere else in your code. What exactly the issue is would likely be determined if you looked in the Browser Console (Ctrl-Shift-J, or Cmd-Shift-J on OSX). Unfortunately, you have not included that information in the question.Reference information:
Below is a complete Firefox Add-on SDK extension which twice reads and outputs to the console the file at
B:\testFile.txt
. The output in the console for the example text file included below is:index.js:
package.json:
textFile.txt: