Question


In my XPI I am fetching javascript code from the user's PC (file://) and run the js code in sandbox. For some reason I get not well formed error on the first line of my code which is a comment:

// Yosy

My code is still running but this error is annoying and I want to fix this, any suggestions?

Code Example for running the code:

var sandbox = new Components.utils.Sandbox(safeWin); 
sandbox.window = win;
sandbox.doc = win.doc;
sandbox.__proto__ = win;
Was it helpful?

Solution

"Not well-formed" is an XML processing error. Somewhere the browser attempts to interpret your JavaScript code as XML. Your code example doesn't show it but I guess that you are using XMLHttpRequest to download your script - and by default XMLHttpRequest will attempt to parse the XML code (as it name already says). You want to tell it that you are downloading plain text that should not be parsed:

var request = new XMLHttpRequest();
request.open("GET", url);
request.overrideMimeType("text/plain");
request.send();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top