-
Notifications
You must be signed in to change notification settings - Fork 309
Connect to Node.js
Andrea Cardaci edited this page Mar 19, 2020
·
4 revisions
Run Node.js with node --inspect-brk=9222 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(async(client) => {
const {Debugger, Runtime} = client;
try {
client.Debugger.paused(() => {
client.Debugger.resume();
client.close();
});
await client.Runtime.runIfWaitingForDebugger();
await client.Debugger.enable();
} catch (err) {
console.error(err);
} finally {
client.close();
}
}).on('error', (err) => {
console.error(err);
});