1

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'
    });
})();
  • 1
    Currently only one debugger can be attached, but someday they'll fix it, see https://crbug.com/590878 – wOxxOm Aug 04 '17 at 08:50
  • Thank you for your help, @wOxxOm – bangrangdev Aug 05 '17 at 00:03
  • @wOxxOm I found you are good at chrome-devtools-protocol. I meet a familiar question about "Runtime.consoleAPICalled". Can you help me solve it out. [question](https://stackoverflow.com/questions/74475968/chrome-devtools-protocol-devtool-can-not-get-log-info-when-backend-emit-runt) – sisiea Nov 18 '22 at 03:03

0 Answers0