Need to export some data from the browser console?
Open Sources -> Snippets in the console, right click to make a new file. Call it consoleSave.js
打开调试工具,找到Sources -> Snippet,复制代码,保存为 consoleSave.js
Paste the JavaScript code below into the snippet (or get the latest version from http://bgrins.github.io/devtools-snippets/#console-save)
Right click on consoleSave.js and run the snippet.
运行脚本
Voila, now you can call console.save() to
download objects from the console!
js脚本
(function(console){
console.save = function(data, filename){
if(!data) {
console.error('Console.save: No data')
return;
}
if(!filename) filename = 'console.json'
if(typeof data === "object"){
data = JSON.stringify(data, undefined, 4)
}
var blob = new Blob([data], {type: 'text/json'}),
e = document.createEvent('MouseEvents'),
a = document.createElement('a')
a.download = filename
a.href = window.URL.createObjectURL(blob)
a.dataset.downloadurl = ['text/json', a.download, a.href].join(':')
e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
a.dispatchEvent(e)
}
})(console)
把要保存的内容储存为global变量
然后执行console.save({" ": })
保存为json文件
参考:https://coderwall.com/p/prhwzg/add-console-save-to-chrome