2

I am wondering if there is a way to save the entire console to a file using javascript. I am outputting to the console a counter number and the text of a div which repeats itself x amount of times depending on how many divs are on the page and I want to save everything that is in the console. My console looks something like this:

Div: 34 | Title: Some Title

Div: 35 | Title: Some Other Title

Div: 36 | Title: Yet Another Title

I would like to save all those lines to a file using javascript. So that it does it automatically when the divs are done being displayed. Is there a way to do this? Thank you for your time.

Edit: https://jsfiddle.net/u4ohzofk/

var titles = $('.title');
for(i = 0; i < titles.length; i++) {
 console.log("Div: "+i+" | Title: "+$(titles[i]).text());
}
<div class="title">
Here is a title
</div>
<div class="title">
Here is a title2
</div>
<div class="title">
Here is a title3
</div>
<div class="title">
Here is a title4
</div>
<div class="title">
Here is a title5
</div>
<div class="title">
Here is a title6
</div>
<div class="title">
Here is a title7
</div>
<div class="title">
Here is a title8
</div>
<div class="title">
Here is a title9
</div>
<div class="title">
Here is a title10
</div>

I have created the above fiddle to further help me explain what I am looking for. I have divs with titles that I get off of a page. I number the divs and grab their titles and then spit that out into the console. I then want to save the entire console when it is done spitting out the divs. I want to do this automatically through javascript. Not manually. I am also not just inputting this into a variable because other elements are automatically displaying to the console that I am looking to save as well.

  • What browser are you using? – Christopher Dumas Dec 17 '16 at 14:46
  • 1
    This is an [XY problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). The console is only displaying what you tell it to. Show the relevant code and explain in more detail what higher level problem you are trying to solve – charlietfl Dec 17 '16 at 14:50
  • Possible duplicate of [Can I extend the console object (for rerouting the logging) in javascript?](http://stackoverflow.com/questions/9277780/can-i-extend-the-console-object-for-rerouting-the-logging-in-javascript) – worenga Dec 17 '16 at 14:53
  • Also possibly a duplicate of http://stackoverflow.com/questions/11849562/how-to-save-the-output-of-a-console-logobject-to-a-file – Christopher Dumas Dec 17 '16 at 14:55
  • I found an answer here: http://bgrins.github.io/devtools-snippets/#console-save. Hope this can help you –  Dec 17 '16 at 15:05
  • I have created an example of what I am looking for. https://jsfiddle.net/u4ohzofk/ – Michael Ortega Dec 17 '16 at 15:37
  • Everything that was posted above I already tried before I asked this question. Those are still manually. I am looking to be able to just save the console as a whole through javascript without having to tell it what objects I am looking to save. I just want a file to be created containing all that is in the console at the time of creation. Line breaks would be nice too. – Michael Ortega Dec 17 '16 at 15:50

1 Answers1

0
  • In Chrome, right-click in the console and choose Save As... and you're good to go.
  • In Safari, use Cmd-S.

Hope that helps!

Christopher Dumas
  • 1,220
  • 11
  • 27
  • I knew about this. I have also found some other plugins but I want to code it and I wanted to see if there is a more simple way than the current plugin out there because I just want to save the entire log as it is. Thanks. – Michael Ortega Dec 17 '16 at 15:23