I am developing web automation system using Chrome and Chrome DevTools Protocol (https://chromedevtools.github.io/devtools-protocol/) in Nodejs.
Calling the Runtime.consoleAPICalled method works fine, but when I open devtools of the launched Chrome, it no longer works.
How do I get the API to be called regardless of Chrome devtools?
const CDP = require('chrome-remote-interface');
const chromeLauncher = require('chrome-launcher');
(async function launch() {
const chrome = await chromeLauncher.launch({
port: 9222,
chromeFlags: [
'--window-size=1024,768',
'--disable-gpu'
]
});
const protocol = await CDP({ port: chrome.port });
const { Page } = protocol;
const { Runtime } = protocol;
await Page.enable();
await Runtime.enable();
Runtime.consoleAPICalled(function(params) {
// Not working when I open Chrome devtools.
console.log('Runtime.consoleAPICalled', params);
});
Page.loadEventFired(async() => {
await Runtime.evaluate({
"expression": `
setInterval(function () {
console.log(new Date());
}, 1000);
`
});
});
Page.navigate({
url: 'https://www.google.com'
});
})();