Electron-Debug调试-VSCode

柳豪
2023-12-01
  1. 创建launch.json

debug -> Add Configuration

  1. 在launch.json中的configurations中新增调试配置

-> AddConfiguration
=> {} Node.js:Electron Main
=> {} Chrome : Attach

  1. 在Electron Main中新增调试指令

“runtimeArgs”:["–remote-debugging-prot=9222","."], *可选

   "windows":{
        "runtimeExecutable":"${WorkspaceFolder}/node_modules/.bin/electron.cmd"
    }

注:Electron Main 中的端口 须与 Chrome Attach 中的端口一致
** 可选配置 **

    "Compounds":[{
        "name":"All",
        "configurations":["main","Renderer"] //名称列表
    }]

整体配置信息示例

{
    "version": "0.2.0",
    "configurations": [
        {
          "type": "node",
          "request": "launch",
          "name": "Main",
          "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
          "runtimeArgs": ["--remote-debugging-port=9222", "."],
          "windows": {
            "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron.cmd"
          }
        },
        {
          "name": "Renderer",
          "type": "chrome",
          "request": "attach",
          "port": 9222,
          "webRoot": "${workspaceFolder}"
        }
      ],
      "compounds": [
        {
          "name": "All",
          "configurations": ["Main", "Renderer"]
        }
      ]
}
 类似资料: