-
Notifications
You must be signed in to change notification settings - Fork 311
Dump HTML after page load
Andrea Cardaci edited this page Aug 6, 2017
·
1 revision
To dump the HTML of the whole page after the page is completely loaded. This can be particularly useful when loading a dynamic page where data is loaded via AJAX.
const CDP = require('chrome-remote-interface');
CDP(async(client) => {
const {Network, Page, Runtime} = client;
try {
await Network.enable();
await Page.enable();
await Network.setCacheDisabled({cacheDisabled: true});
await Page.navigate({url: 'https://github.com'});
await Page.loadEventFired();
const result = await Runtime.evaluate({
expression: 'document.documentElement.outerHTML'
});
const html = result.result.value;
console.log(html);
} catch (err) {
console.error(err);
} finally {
client.close();
}
}).on('error', (err) => {
console.error(err);
});