在 VS 代码中调试

Debugging in VS Code

我一直在关注 post 关于在 VSCode 中为 Chrome 使用 调试器:

我的launch.json是这样的:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "chrome",
      "request": "launch",
      "name": "Launch Chrome",
      "url": "http://localhost:4200",
      "trace": true,
      "webRoot": "${workspaceFolder}/src",
      "sourceMaps": true
    }
  ]
}

我的 Karma 配置是这样的:

logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['ChromeDebugging'],
singleRun: true,
restartOnFileChange: true,
customLaunchers: {
  ChromeDebugging: {
    base: 'Chrome',
    flags: ['--remote-debugging-port=4200']
  }
}

当我从调试面板启动时,它会直接转到 localhost:4200,但它没有到达我的断点。我错过了一些明显的东西吗?感谢您提供任何有用的提示。

您需要 attach 而不是 launch 您在 chrome 中的调试器。

Launch.json

将此行从 "request": "launch" 更改为 "request": "attach"

看看这个很棒的 blog post for further details