如何在JavaScript中通过Chrome浏览器进行阅读 [英] How to read from Chrome's console in JavaScript

查看:112
本文介绍了如何在JavaScript中通过Chrome浏览器进行阅读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用程序中放置一个按钮,如果按它,它将获得写入控制台的所有内容并将其发送给我(用于报告错误)。我知道我可以保留一个变量,并且每次执行console.log时都会将消息附加到该变量,但我试图保持应用程序的内存消耗低,因此只需从

I would like to put a button in my app where if you press it, it will get the contents of everything that was written to the console and email it to me (for reporting bugs). I know I can keep a variable around and every time I do a console.log also append the message to that variable but I am trying to keep the memory consumption of the app low so it would be much more efficient just to grab it from the console.

有没有办法从javascript检索控制台消息?

Is there a way to retrieve the console messages from javascript?

谢谢

推荐答案

你不能。

你可以做的是钩住 console.log 函数,以便在日志记录时存储:

What you can do is hook the console.log function so that you store when it logs :

var store = [];
var oldf = console.log;
console.log = function(){
   store.push(arguments);
   oldf.apply(console, arguments);
}

这篇关于如何在JavaScript中通过Chrome浏览器进行阅读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆