我正在使用 Greasemonkey 为一个应用程序编写覆盖 UI,将 JS 注入(inject)到页面。
现在我在挂接网页上运行的一些 ajax 调用时遇到问题。 但是,该页面正在生成控制台日志,通知内容已完全加载。我的问题是:
在纯 JavaScript 中,是否有可能读取由完全不同的脚本生成的控制台输出?
function blackBox(){
//this is generating come console output.
//this runs on code layer I have no access to.
}
function readConsole(){
//read console record by record
if(console.msg == "something I want"){
doSomething();
}
}
提前致谢:)
最佳答案
正如其他人所说,您可以用自己的函数覆盖 console.log()
函数,并实现您自己的实现:
var oldLog = unsafeWindow.console.log;
var messages = [];
unsafeWindow.console.log = function(msg) {
messages.push(msg);
oldLog.apply(null, arguments);
}
// Access the entire console.log history in messages
关于javascript - 读取 console.log() 输出形式的 javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52347756/