Skip to content

Connect to Node.js

Andrea Cardaci edited this page Dec 4, 2016 · 4 revisions

Run Node.js with node --inspect=9222 --debug-brk script.js in order to be able to inspect the runtime. Some preliminary setup is needed in order to make it work, the following recipe shows a minimal example (without error checking) that simply resumes the script execution.

Note: this is an experimental Node.js feature, things may change.

const CDP = require('chrome-remote-interface');

CDP((client) => {
    client.Debugger.enable();
    client.Runtime.runIfWaitingForDebugger();
    client.Debugger.paused(() => {
        client.Debugger.resume();
        client.close();
    });
}).on('error', (err) => {
    console.error(err);
});