-
Notifications
You must be signed in to change notification settings - Fork 309
Async await example
Andrea Cardaci edited this page Jul 12, 2018
·
7 revisions
The main example but using the brand new async
/await
primitives (since Node.js 7.6.0).
const CDP = require('chrome-remote-interface');
async function example() {
try {
// connect to endpoint
let client = await CDP();
// extract domains
const {Network, Page} = client;
// setup handlers
Network.requestWillBeSent((params) => {
console.log(params.request.url);
});
// enable events then start!
await Network.enable();
await Page.enable();
await Page.navigate({url: 'https://github.com'});
await Page.loadEventFired();
} catch (err) {
console.error(err);
} finally {
if (client) {
await client.close();
}
}
}
example();