Last active
August 4, 2018 08:46
-
-
Save arliber/de8d8b770fe6567af432c1ef8b624f98 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getPageContents(url) { | |
return new Promise((resolve, reject) => { | |
CDP((client) => { | |
const {Page, Runtime} = client; | |
// Evaluate outerHTML after page has loaded | |
Page.loadEventFired(() => { | |
setTimeout(() => { | |
Runtime.evaluate({expression: 'document.body.outerHTML'}).then((result) => { | |
resolve(result.result.value); | |
client.close(); | |
}); | |
}, 3000); | |
}); | |
// Enable events on domains we are interested in | |
Promise.all([ | |
Page.enable() | |
]).then(() => { | |
return Page.navigate({url}); | |
}); | |
}).on('error', (err) => { | |
console.error('getPageContents: Cannot connect to browser:', err); | |
reject(); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment