我正在构建一个开源的Node.js调试器,它是一个 Electron 应用程序,并在渲染过程中使用了内置的调试器。
完整资料:https://github.com/fijiwebdesign/electron-scope/
在主要过程中,我想启动脚本进行调试并在第一行上设置断点。
我正在遵循Electron中针对chrome调试器api的测试:
https://github.com/electron/electron/blob/702352804239f58e5abcd0b96dbd748b68ab0278/spec/api-debugger-spec.js#L77
我的代码:
win.webContents.debugger.sendCommand(
'Debugger.setBreakpointByUrl', {
lineNumber: 0,
url: './test.js'
},
function (err, result){
if(err){
console.error('Error:', err)
}
console.log('Breakpoint Result: ', result)
})
充分的引用:https://github.com/fijiwebdesign/electron-scope/blob/setBreakpoint/index.js#L51
记录:
Result: { breakpointId: './test.js:0:0', locations: [] }
但是,没有设置断点。我假设是否有地点可以保存这些信息。
您可以在此处找到要设置断点的分支:
https://github.com/fijiwebdesign/electron-scope/tree/setBreakpoint
最佳答案
我认为您可能需要运行Debugger.enable
来激活调试器,以便后续的调试器命令起作用。但是,我对Electron的API并不熟悉,因此它有可能会固有地做到这一点。
win.debugger.sendCommand('Debugger.enable', {}, function() {
setBreakpoint(win);
});
关于node.js - 通过Chrome远程调试API在 Electron 中设置断点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42015863/