2009年1月13日

Using firebug console on chrome extensions

When working on a firefox extension, you cannot use firebug console.log directly from your XUL chrome/overlay.js because the console belongs to the document window but in XUL, you get a XUL window.

The equivalent of a window in chrome overlay is the "content" but it is XPCNativeWrapper wrapped which hide all the javascript methods of an Object. We need to unwrap the content first before we can get a console. So to get the console instance, you need this:


DEBUG=false;
// Wrap firebug console.log
function log() {
if (!DEBUG) return;
var console = content.wrappedJSObject.console;
if (console.firebug) {
console.log.apply(console, arguments);
}
}

Safely_accessing_content_DOM_from_chrome