如何调试electron-forge react-typescript的渲染器进程?

时间:2018-06-03 07:35:44

标签: typescript debugging visual-studio-code electron electron-forge

我使用电子伪造在react-typescript模板上生成应用程序基础。我为该应用程序编写了一些vscode调试配置。但是我只能调试Main进程,Renderer丢失了。我已经为chrome扩展安装了调试器并在之前使用过它。我想知道配置中缺少什么?

    {
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Electron: Main",
            "protocol": "inspector",
            "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron-forge-vscode-win",
            "runtimeArgs": [
                "--remote-debugging-port=9223",
                "."
            ],
            "windows": {
                "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron-forge-vscode-win.cmd"
            }
        },
        {
            "name": "Electron: Renderer",
            "type": "chrome",
            "request": "attach",
            "port": 9223,
            "webRoot": "${workspaceFolder}",
            "timeout": 30000
        }
    ],
    "compounds": [
        {
            "name": "Electron: All",
            "configurations": [
                "Electron: Main",
                "Electron: Renderer"
            ]
        }
    ]
}

2 个答案:

答案 0 :(得分:0)

复制您的 launch.json ,然后编写一些代码并设置断点。 测试代码位于 app.tsx 的末尾:

  int click = 0;
    private void RadioButton_Click(object sender, RoutedEventArgs e)
    {
        click++;
        ((RadioButton)sender).IsChecked = click % 2 == 1 ;
        click %= 2;
    }

断点很好。

我在 launch.json 中进行的另一项更改是:

setTimeout(() => {
    let x = 0;            //break point here
    console.log(x);
}, 3000);

答案 1 :(得分:0)

我知道这是事实,但是我想回答,以防其他人像今天一样整日都在为这个问题而苦苦挣扎。

matsu's blog中读取关键信息后:

  

转到main.js并注释掉这一行:

     

mainWindow.webContents.openDevTools()

     

远程调试不起作用   具有多个DevTools客户端。我们将在VS Code中使用调试器   而不是Electron的DevTools。

-

某些(全部?)电子伪造模板在启动时会打开Chrome开发工具。 Chrome / Electron的局限性在于,仅支持与任何类型的调试器的一个连接(在response from MSFT here中进行了确认)。我们只需要对此行进行注释即可。

在您的main.js(或index.ts等)中:

 // Open the DevTools.
  if (isDevMode) {
    await installExtension(REACT_DEVELOPER_TOOLS);
    //mainWindow.webContents.openDevTools(); <--- comment this out
  }