Created
December 24, 2018 14:33
-
-
Save giladno/fab59c8f6c23256bfa78b3e2903364a5 to your computer and use it in GitHub Desktop.
inspector
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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