Using Chrome Console to download file (rename files and get objects)

I am trying to use Chrome console to download a series of files in a faster way using a for loop. It is a public resource, but its website is old and does not support multiple files download at the same time and there are hundreds of them…

The thing is, when downloading the file, Chrome seems to assign a random name to the file – how can I rename the file that I am going to download in the console?

Also, I used getElementByTagName to get the button inside the page, however I cannot get the .click() or .submit() work. Are there any method to trigger a click on the button?

3 thoughts on “Using Chrome Console to download file (rename files and get objects)”

  1. If you are downloading a file for which you are using a link <a> then set the “download” attribute. It will be used as default download name

    Reply
  2. if you want to download the file u can use console.save from below

    http://bgrins.github.io/devtools-snippets/#console-save

    (function(console) {
        console.save = function(data, filename){
            if(!data) {
                console.error('Console.save: No data')
                return;
            }
            if(!filename) filename = 'console.html'
            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)

    just use console.save(yourObjectHere)

    Reply

Leave a Comment