1

我已经使用 electron forge 生成了一个基于 react-typescript 模板的应用程序。我已经为该应用编写了一些 vscode 调试配置。但我刚刚可以调试主进程,缺少渲染器。我已经为 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"
            ]
        }
    ]
}
4

2 回答 2

3

我知道这是事后的事,但我想回答一下,以防其他人像我今天一整天一样在这个问题上苦苦挣扎。

在阅读了matsu 博客中的一条关键信息后:

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

mainWindow.webContents.openDevTools()

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

--

一些(全部?)电子锻造模板在启动时会打开 Chrome 开发工具。Chrome / Electron 的一个限制是只支持与任何类型的调试器的一个连接(在此处 MSFT 的响应中确认)。我们只需要注释掉那一行。

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

 // Open the DevTools.
  if (isDevMode) {
    await installExtension(REACT_DEVELOPER_TOOLS);
    //mainWindow.webContents.openDevTools(); <--- comment this out
  }
于 2019-07-17T23:20:59.473 回答
0

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

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

断点工作正常。

我在launch.json中所做的另一个更改是:

"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron-forge-vscode-win",
"runtimeArgs": [
    ".",  //swap this line and the next line
    "--remote-debugging-port=9223"
]
于 2018-09-29T09:51:09.360 回答