0

I have some standalone JavaScript code that I've written to use with MaxMSP (a visual language for MIDI and DSP) that I need to debug.

I downloaded WebStorm to try it out. When I try to execute code that reads a local file, I get the following error:

Exception... "Security error" code: "1000" nsresult: "0x805303e8 (NS_ERROR_DOM_SECURITY_ERR)"

I know people have seen this before and I have tried all the suggestions I found to bypass security and enable local file reading from Firefox but I'm still not able to get this to work.

I'm wondering if something has changed in recent versions of Firefox that make all the old suggestions useless.

Would appreciate any suggestions.

Thanks, David

David
  • 5,991
  • 5
  • 33
  • 39
  • What solutions have you tried? – James Jan 17 '12 at 12:42
  • Please post your code, otherwise it's hard to understand your problem. – Andreas Köberle Jan 17 '12 at 16:47
  • Turns out there's more going on. It seems that the "File" object used in MaxMSP is something they provide and not part of "standard" JavaScript and THAT is why I was getting the errors when trying to read a file through a debugger that used Firefox. So assuming I can turn off the security stuff, I'm still then left with the question, how do I read a local file from JavaScript. I looked at the html5 FileReader stuff but it seems to require that a filename be provided via an html form input tag or by drag-drop. I need a way to just specify a filename (hardcoded) and then just just read data. – David Jan 17 '12 at 19:23
  • I wrote the following code to try and read a text file. I no longer get any exceptions, but the text variable has nothing in it after the read. var xmlhttp = new XMLHttpRequest(); xmlhttp.open("GET", filename, false); // Synchronous var text = xmlhttp.responseText; – David Jan 17 '12 at 23:32

1 Answers1

0

OK --- I figured this out! The big problem for me is lack of knowledge of javascript libraries.

The XMLHttpRequest works but it needs an extra line

xmlhttp.send();

I didn't know about that. So code that actually works to read data from a local file (assuming one has followed the instructions posted in other places to turn off security is as simple as

var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", filename, false); // Synchronous
xmlhttp.send();
var text = xmlhttp.responseText;

I hope this saves others some time --- it was a real PITA for me to figure this out.

David
  • 5,991
  • 5
  • 33
  • 39