stopkillinggames.com
stopkillinggames.com

Reputation: 1426

How to overcome IE11 limit of 1024 characters in console.log()?

I have to debug code using IE11 (our code works in IE but not in modern browsers). I do console.log(someString) and that string contains 200,000+ characters. IE11 only prints first 1024. I need the entire string to be dumped.

Upvotes: 0

Views: 397

Answers (1)

dangarfield
dangarfield

Reputation: 2340

Just create a 'virtual file' and save it like you would any other file.

function save(filename, data) {
    const blob = new Blob([data], {type: 'text/plain'});
    if(window.navigator.msSaveOrOpenBlob) {
        window.navigator.msSaveBlob(blob, filename);
    }
    else{
        const elem = window.document.createElement('a');
        elem.href = window.URL.createObjectURL(blob);
        elem.download = filename;        
        document.body.appendChild(elem);
        elem.click();        
        document.body.removeChild(elem);
    }
}

save('test.txt','A big load of data')

Edit: I've just realised that you have a lot of stars and probably know all of this. Alternatively, you could wrap all console.log statements and send to your server for remote logging or a different instrumentation agent to collect and view these logs - How to safely wrap `console.log`?

Upvotes: 1

Related Questions