node.js - 通过Chrome远程调试API在 Electron 中设置断点

标签 node.js google-chrome-devtools electron javascript-debugger node-debugger

我正在构建一个开源的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/

相关文章:

node.js - 动态匹配变量 Mongodb

node.js - npm: "Cannot find module internal/errors"

javascript - 查看 Chrome 控制台是否打开

google-chrome - 网络检查器下资源加载之间的空白时间

javascript - 找不到模块 'drivelist' 的声明文件

javascript - 如何过滤 JSON.parse 结果

javascript - 如何使用 node.js 将 .json 文件作为 HTTP POST 发送?

redirect - 在 Chrome 中内联 javascript 重定向之前中断 javascript

node.js - Atom Electron 不适用于 Raspberry Pi

javascript - 在窗口中拖放项目时防止 Electron 应用程序重定向