【问题标题】:Set breakpoint in electron via chrome remote debugging API通过 chrome 远程调试 API 在电子中设置断点
【发布时间】:2017-02-03 20:13:31
【问题描述】:

我正在构建一个开源 Node.js 调试器,它是一个电子应用程序,并在渲染过程中使用内置调试器。 完整来源: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

【问题讨论】:

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


    【解决方案1】:

    我认为您可能需要运行Debugger.enable 来激活调试器,以便后续的调试器命令能够工作。但是,我不熟悉 Electron 的 API,所以它可能天生就是这样。

    win.debugger.sendCommand('Debugger.enable', {}, function() {
        setBreakpoint(win);
    });
    

    【讨论】:

      猜你喜欢
      • 2012-02-06
      • 2011-05-13
      • 1970-01-01
      • 2014-07-17
      • 2011-08-12
      • 2013-06-22
      • 2013-06-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多