Save webpage HTML body content using console

var script = document.createElement(‘script’);
script.type = “text/javascript”;
script.async = true;
script.src = ‘https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js’;
document.getElementsByTagName(‘head’)[0].appendChild(script);
jQuery.noConflict();

// Console API to clear console before logging new data
console.API;
if (typeof console._commandLineAPI !== ‘undefined’) {
console.API = console._commandLineAPI; //chrome
} else if (typeof console._inspectorCommandLineAPI !== ‘undefined’) {
console.API = console._inspectorCommandLineAPI; //Safari
} else if (typeof console.clear !== ‘undefined’) {
console.API = console;
}

console.save = function (data, filename) {
if (!data) {
console.error(‘Console.save: No data’)
return;
}

if (!filename) filename = ‘filename.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.save(jQuery(‘body’).html())

 

Resource: https://github.com/edubey/browser-console-crawl