Skip to content

Instantly share code, notes, and snippets.

@giladno
Created December 24, 2018 14:33
Show Gist options
  • Save giladno/fab59c8f6c23256bfa78b3e2903364a5 to your computer and use it in GitHub Desktop.
Save giladno/fab59c8f6c23256bfa78b3e2903364a5 to your computer and use it in GitHub Desktop.
inspector
const util = require('util');
const inspector = require('inspector');
const session = new inspector.Session();
const post = util.promisify(session.post).bind(session);
function test() {
console.log('hello');
console.log('world');
return 12345;
}
(async () => {
session.connect();
try {
let scripts = {};
session.on('Debugger.scriptParsed', ({params}) => {
scripts[params.url] = params.scriptId;
});
session.on('Debugger.paused', ({params}) => {
console.log(params);
});
await post('Debugger.enable');
let scriptId = Object.keys(scripts).reduce(
(id, url) => id || (url == `file://${__filename}` && scripts[url]),
0
);
await post('Debugger.setBreakpoint', {location: {scriptId, lineNumber: 9}});
console.log(test());
} finally {
session.disconnect();
}
})().catch(err => console.error(err));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment