File access not possible in Firefox extension 17.0.1

After upgrading to Firefox 17.0.1, PrivilegeManager is no longer supported. Various sources say that you can still simply remove the corresponding line from the code, and everything should work fine. Unfortunately, this is not the case here.

I always get the error message: TypeError: Components.classes undefined. Are there any changes to the components. The Mozilla code snippets page (https://developer.mozilla.org/en-US/docs/Code_snippets/File_I_O) shows the same syntax (without using FileUtils.jsm).

My code is:

//netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); var file = Components.classes["@mozilla.org/file/local;1"] .createInstance(Components.interfaces.nsILocalFile); file.initWithPath(filePath); 
+4
source share
2 answers

To finally solve my problem: Initially, I was still working with an outdated Privilege Manager. When I tried to just remove this line from my code, it did not work for me. The problem was that I worked at home, because the extension was not executed as an extension, but - out of laziness - only as a regular xul file. As Boris Zbarsky and Paa already mentioned, you must run the code in the extension itself in order to get the chrome privileges.

After that, executing the above code (with just deleting the PrivilegeManager line) works just fine!

0
source

As some commentators have noted, you may be using the code in the wrong place (i.e. unprivileged, web page context). However, this may just be a review issue.

If this is a field of view, try the following:

 const {Cc,Ci,Cu} = require("chrome"); var file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile); file.initWithPath(filePath); 

If you work in the wrong place, require will create an error.

0
source

All Articles