简体   繁体   English

使用 VSCode Chrome 调试器调试 Electron 渲染过程

[英]Debugging Electron render process with VSCode Chrome debugger

Setting up an angular + electron debug configuration and it's slowly but surely crushing my soul.设置角度 + 电子调试配置,它正在缓慢但肯定地粉碎我的灵魂。 For some reason breakpoints aren't hitting in the render process (VSCode is showing the error Breakpoint ignored because generated code not found (source map problem?)" ).出于某种原因,渲染过程中没有命中断点(VSCode 显示错误Breakpoint ignored because generated code not found (source map problem?)" ignore Breakpoint ignored because generated code not found (source map problem?)" )。

My debug config looks like this (full repo is here ):我的调试配置看起来像这样(完整的回购在 这里):

// .vscode/launch.json
{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Electron: Main",
      "protocol": "inspector",
      // Prelaunch task compiles main.ts for Electron & starts Angular dev server.
      "preLaunchTask": "Build: All",
      "cwd": "${workspaceFolder}",
      "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
      "runtimeArgs": ["--remote-debugging-port=9223", "--serve", "."],
      "windows": {
        "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron.cmd"
      }
    },
    {
      "name": "Electron: Renderer",
      "type": "chrome",
      "request": "attach",
      "port": 9223,
      "webRoot": "${workspaceFolder}",
      "timeout": 30000,
      "urlFilter": "http://localhost:4200/*",
      // Source map overrides are copied from Angular CLI debugging recipe.
      // See: https://github.com/Microsoft/vscode-recipes/tree/master/Angular-CLI
      "sourceMaps": true,
      "sourceMapPathOverrides": {
        "webpack:/*": "${webRoot}/*",
        "/./*": "${webRoot}/*",
        "/src/*": "${webRoot}/*",
        "/*": "*",
        "/./~/*": "${webRoot}/node_modules/*"
      }
    }
  ],
  "compounds": [
    {
      "name": "Electron: All",
      // The main process should be started before renderer to prevent timeout.
      "configurations": ["Electron: Main", "Electron: Renderer"]
    }
  ]
}
// .vscode/tasks.json
{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Build: All",
      "type": "shell",
      "command": "npm run electron:serve-tsc && ng serve",
      "isBackground": true,
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "problemMatcher": {
        "owner": "typescript",
        "source": "ts",
        "applyTo": "closedDocuments",
        "fileLocation": ["relative", "${cwd}"],
        "pattern": "$tsc",
        "background": {
          "activeOnStart": true,
          "beginsPattern": "^.*",
          "endsPattern": "^.*Compiled successfully.*"
        }
      }
    }
  ]
}

I can debug the main process just fine with the above config, which is awesome.我可以用上面的配置很好地调试主进程,这太棒了。 The chrome debugger also seems to be attaching correctly (can see the outputs in the debug console), but sadly breakpoints aren't hitting. chrome 调试器似乎也正确附加(可以在调试控制台中看到输出),但遗憾的是没有命中断点。

Just adding debugger;只需添加debugger; statements to the Angular code lets me debug in the chrome devtools in the Electron window, but it would be far far better to debug inside VSCode. Angular 代码的语句让我可以在 Electron 窗口中的 chrome devtools 中进行调试,但在 VSCode 中进行调试会好得多。

Is this even possible to do??这甚至可以做到吗?

(For anyone ending up here) You need to: (对于任何人在这里结束)您需要:

  1. Enable sourcemaps on your tsconfig.json :在 tsconfig.json 上启用源映射
 { "compilerOptions": { "sourceMap": true, ... } }
  1. Add sourcemaps location on your launch configuration(s), for example:在您的启动配置上添加 sourcemaps 位置,例如:
 "outFiles": [ "${workspaceRoot}/node_modules/**/*.js" ]

(from https://github.com/Microsoft/vscode-node-debug/issues/82#issuecomment-290642560 ) (来自https://github.com/Microsoft/vscode-node-debug/issues/82#issuecomment-290642560

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM