問題描述
是否可以通過編程方式訪問先前記錄的 Firebug 輸出?
Is it possible to access the previously-logged output of Firebug programmatically?
例如:
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"
}
推薦答案
如果不自己包裝 window.console
,我不相信這是可能的.查看源代碼,似乎當(dāng)調(diào)用 Firebug 的 console
方法(在主文檔中運(yùn)行,因此沒有特殊權(quán)限)時(shí),它會在主文檔中留下一些對象,然后引發(fā)一個(gè)自定義事件.在特權(quán)插件域中運(yùn)行的 Firebug 偵聽器拾取事件,吞噬文檔中剩余的對象并將適當(dāng)?shù)膬?nèi)容添加到控制臺面板,控制臺面板是瀏覽器 chrome 的一部分,因此無法訪問在主程序中運(yùn)行的 JavaScript窗口.
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.
我可能對這方面的細(xì)節(jié)有誤,因?yàn)槲抑皇谴致缘夭榭戳?Firebug 源代碼,并且很少進(jìn)行 Firefox 插件開發(fā),但我認(rèn)為這大體上是正確的.
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.
這篇關(guān)于您可以以編程方式訪問 Firebug 控制臺輸出嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!