Can you programmatically access the Firebug console output?

£可爱£侵袭症+ 提交于 2019-11-26 22:44:12

问题


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"
}

回答1:


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




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/4375522/can-you-programmatically-access-the-firebug-console-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!