1

I have a question. When I type a lot of JS commands into a console log in Chrome, and I want to return it then, can I? Thank you Andrew

Andrew L.
  • 11
  • 1
  • [Save the console.log in Chrome to a file](https://stackoverflow.com/questions/7627113/save-the-console-log-in-chrome-to-a-file) – VM1 Apr 21 '22 at 09:00
  • _"and I want to return it"_ what exactly does that mean? – phuzi Apr 21 '22 at 09:06
  • 2
    Does this answer your question? [Save the console.log in Chrome to a file](https://stackoverflow.com/questions/7627113/save-the-console-log-in-chrome-to-a-file) – VM1 Apr 21 '22 at 09:12

1 Answers1

2

You can't. What's in the console can't be read from JavaScript.

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

console.stdlog = console.log.bind(console);
console.logs = [];
console.log = function(){
    console.logs.push(Array.from(arguments));
    console.stdlog.apply(console, arguments);
}
Nag
  • 39
  • 5