I tried using JSON.stringify(object)
, but it doesn’t go down on the whole structure and hierarchy.
On the other hand console.log(object)
does that but I cannot save it.
In the console.log
output I can expand one by one all the children and select and copy/paste but the structure is to big for that.
Advertisement
Answer
Update: You can now just right click
Right click > Save as in the Console panel to save the logged messages to a file.
Original Answer:
You can use this devtools snippet shown below to create a console.save method. It creates a FileBlob from the input, and then automatically downloads it.
JavaScript
x
27
27
1
(function(console){
2
3
console.save = function(data, filename){
4
5
if(!data) {
6
console.error('Console.save: No data')
7
return;
8
}
9
10
if(!filename) filename = 'console.json'
11
12
if(typeof data === "object"){
13
data = JSON.stringify(data, undefined, 4)
14
}
15
16
var blob = new Blob([data], {type: 'text/json'}),
17
e = document.createEvent('MouseEvents'),
18
a = document.createElement('a')
19
20
a.download = filename
21
a.href = window.URL.createObjectURL(blob)
22
a.dataset.downloadurl = ['text/json', a.download, a.href].join(':')
23
e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
24
a.dispatchEvent(e)
25
}
26
})(console)
27
Source: http://bgrins.github.io/devtools-snippets/#console-save