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
You can set an unconditional breakpoint using the context menu (see above), or by: Clicking on the line number for the line you want to break at in the source pane. Highlighting the line you want to break at in the source pane and pressing Ctrl + B (Windows/Linux) or Cmd + B (macOS).
The Firefox add-ons might not work if your Firefox browser is not up to date. Moreover, incorrect date/time settings of your system or corrupt Firefox user profile (or any of its settings/files) may also cause the issue.
You can open the Firefox Developer Tools from the menu by selecting Tools > Web Developer > Web Developer Tools or use the keyboard shortcut Ctrl + Shift + I or F12 on Windows and Linux, or Cmd + Opt + I on macOS.
If 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With