15

Is it possible to access the previously-logged output of Firebug programmatically?

For example:

console.log('a');
console.log('b');
console.log('c');

for (var i = 0; i < console.output.length; ++i) {
    alert(console.output[i]);  // "a", "b", "c"
}
nickf
  • 537,072
  • 198
  • 649
  • 721

3 Answers3

5

Without wrapping window.console yourself, I don't believe this is possible. Looking at the source, it seems that when a Firebug's console method (running within the main document and therefore having no special privileges) is called, it leaves some objects lying around in the main document and then raises a custom event. A Firebug listener running in privileged-plug-in-land picks up the event, gobbles up the objects left in the document and adds appropriate things to the console panel, which is part of the browser chrome and therefore inaccessible to JavaScript running in the main window.

I could be wrong about the details of this because I've only taken a cursory look at the Firebug source and done very little Firefox plug-in development, but I think this is broadly correct.

Tim Down
  • 318,141
  • 75
  • 454
  • 536
5

Paul Irish created a wrapper for console.log that should solve your problem, have a look here

sebarmeli
  • 17,949
  • 7
  • 35
  • 40
2

See this thread. (Not an exact duplicate, but related).

I haven't found a way to read the console output, but if all you're interested in is capturing your ::log() messages, you can override the .log() method, or create your own which would write your log messages another container, and then call .log().

var myLogStr='';

function myLog(str)
{
  if(console) console.log(str);
  myLogString+=str+'\n';
}

Of course, all of the Firebug objects ( console, etc) exist in the DOM, so you could track down the ID of the console window and retrieve the contents directly.

Update

Firebug also offers some events that you can hook into, which may provide a way to intercept errors, etc.

Community
  • 1
  • 1
3Dave
  • 28,657
  • 18
  • 88
  • 151
  • LOL... I hadn't noticed that. I upvoted you on that thread. I think it's worth either opening a question on the Firebug list or exploring the DOM with FireBug running to find the console object's internals, though. It'd be nice to capture error output, etc. – 3Dave Dec 07 '10 at 10:42
  • Link is dead unfortunately – Sebas Apr 29 '14 at 09:08
  • @Sebas this was from before I realized one should paste the relevant content into the answer. I'll see if I can find a cached version. – 3Dave Apr 29 '14 at 14:02