I've been into Firefox extension development recently, and ran into some issues:
So, in browser.xul i defined these lines:
<overlay id="sample" xmlns=".is.only.xul">
<script src="jquery.js" />
<script src="global.js" />
</overlay>
So, in global.js i have access to all jQuery stuff, and trying to load a simple script there:
var inner = null;
var o = function () {
var prefManager = Components.classes["@mozilla/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
return {
init : function () {
alert('here loading inner..');
$.get('.js', function(d) {
alert('loaded inner script!');
inner = d;
gBrowser.addEventListener("load", function () {
alert('onload');
}, false);
}).error(function(e) { alert('error loading inner..'); setTimeout(o.init,1000); });
$(this).ajaxError(function() { alert('ajaxError'); });
}
}
}
window.addEventListener("load", o.init, false);
But nor i receive a "loaded inner script", nor a "error loading inner" alert.. And i don't see the error console to log any errors from the extension... I assume the $.get
is silently failing due to some restrictions maybe, but is there a proper way to debug the errors normally? The error console is silent for the extension, it only shows errors from the web pages
I've been into Firefox extension development recently, and ran into some issues:
So, in browser.xul i defined these lines:
<overlay id="sample" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script src="jquery.js" />
<script src="global.js" />
</overlay>
So, in global.js i have access to all jQuery stuff, and trying to load a simple script there:
var inner = null;
var o = function () {
var prefManager = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
return {
init : function () {
alert('here loading inner..');
$.get('http://www.example.com/script.js', function(d) {
alert('loaded inner script!');
inner = d;
gBrowser.addEventListener("load", function () {
alert('onload');
}, false);
}).error(function(e) { alert('error loading inner..'); setTimeout(o.init,1000); });
$(this).ajaxError(function() { alert('ajaxError'); });
}
}
}
window.addEventListener("load", o.init, false);
But nor i receive a "loaded inner script", nor a "error loading inner" alert.. And i don't see the error console to log any errors from the extension... I assume the $.get
is silently failing due to some restrictions maybe, but is there a proper way to debug the errors normally? The error console is silent for the extension, it only shows errors from the web pages
- Alex, I really hope that you're not actually evaluating the results of that XHR get as script, right? – Boris Zbarsky Commented Jul 28, 2011 at 15:03
- yes, but mainly because the addon is made to be "autoupdatable" - i know it's bad, i never do this in everyday life, but in this particular project, i just had to – Alex K Commented Aug 1, 2011 at 15:56
- 4 The point is that if you do that, then you're introducing a security hole into the browser. Anyone using such a browser on an untrusted wifi connection, for example, allows the wifi router to inject arbitrary script into chrome. At least use SSL here! – Boris Zbarsky Commented Aug 1, 2011 at 17:54
- i see, but that means even scripts from stackoverflow.com can be substituted with arbitrary ones, since they are loaded without ssl too – Alex K Commented Aug 1, 2011 at 20:04
- 1 Yes, and presumably the stackoverflow.com maintainers don't care if random wifi operators can run random script pretending to be stackoverflow... or even impersonating the whole site. If they did, they would be running their site on SSL. – Boris Zbarsky Commented Aug 1, 2011 at 22:34
2 Answers
Reset to default 7If you look at the article Setting up an extension development environment it suggests setting up some preferences, including javascript.options.showInConsole = true
, which logs errors in chrome files to the Error Console.
In general it can be problematic using JQuery in a XUL page since it assumes that the document is an HTML DOM rather than an XML DOM and that the window
is a HTML window rather than a XUL window. If I were you I'd use the subscript loader for this. To debug you can use Venkman although it is a bit flakey and I often resort to just dump()
statements to the console instead.
Update: see my comment below about the Browser Toolbox.