Reputation: 192
I created an add-on following Mozilla's tutorials. cfx test
and cfx run
worked perfectly. I put the folder on my desktop and installed the add-on into Firefox using cfx xpi
and Ctrl+o (the xpi file).
Now the add-on gives this error in the console log:
Win error 2 during operation open on file purls.txt (The system cannot find the file specified.)
Here is the relevant code in main.js:
const {TextEncoder, TextDecoder, OS} = Cu.import("resource://gre/modules/osfile.jsm", {});
let decoder = new TextDecoder();
let promise = OS.File.read("purls.txt").then(
function onSuccess(array) {
// Do stuff
},
function onReject(reason) {
console.error("Couldn't read from purls.txt:\n"+reason);
}
);
Please help me figure out what is going on. When I use cfx run
the add-on finds the purls.txt file and opens it/reads from it without problem.
Upvotes: 0
Views: 776
Reputation: 37228
You didn't give it a path to purls.txt, so it was probably looking for purls.txt on your drive. Is it on the desktop? Then create a path to the desktop. See pathToPurls
;
const {TextEncoder, TextDecoder, OS} = Cu.import("resource://gre/modules/osfile.jsm", {});
let decoder = new TextDecoder();
let pathToPurls = OS.Path.join(OS.Constants.Path.desktopDir, "purls.txt");
console.log('pathToPurls:', pathToPurls);
let promise = OS.File.read(pathToPurls).then(
function onSuccess(array) {
// Do stuff
},
function onReject(reason) {
console.error("Couldn't read from purls.txt:\n"+reason);
}
);
Upvotes: 1