怎么将chrome console控制台中变量原样的复制出来并保存下载到本地

复制以下代码到console控制中, 并回车执行, 然后只有使用 console.save(变量名) 命令轻松的将控制台中的变量下载到本地来. 

(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)

 其实在console控制台,也可以使用copy(变量名)来复制变量到剪切板上.copy命令也很方便

注意:

有些情况使用copy命令复制数组时总是得到空数组, 建议使用对象类型, 使用对象类型就能复制出来的. 

来自我的博客:https://blog.nice100.net/default/42.html

猜你喜欢

转载自blog.csdn.net/weixin_37281289/article/details/109550714
今日推荐