使用VS代码启动Angular应用程序时Chrome挂起

v64noz0r  于 2023-03-21  发布在  Go
关注(0)|答案(2)|浏览(127)

我有一个Angular 7 CLI应用程序,当我尝试使用Chrome(76)和VS代码(1.37)调试它时,它会使Chrome挂起。我甚至不能打开调试工具并检查index.html,但我运行ng serve就可以了。我甚至可以在现有的Chrome和Firefox选项卡中打开http://localhost:4200/#/,页面会加载,但当我尝试从VS代码启动Chrome进行调试时,浏览器中没有加载任何内容。
我尝试了几种不同的launch.json配置,结果都是一样的
开箱即用配置

{
  "name": "ng serve",
  "type": "chrome",
  "request": "launch",
  "url": "http://localhost:4200/#",
  "webRoot": "${workspaceFolder}"
},

高级配置:https://github.com/microsoft/vscode-recipes/tree/master/Angular-CLI

{
  "name": "ng serve",
  "type": "chrome",
  "request": "launch",
  "preLaunchTask": "npm: start",
  "url": "http://localhost:4200/#",
  "webRoot": "${workspaceFolder}",
  "sourceMapPathOverrides": {
    "webpack:/*": "${webRoot}/*",
    "/./*": "${webRoot}/*",
    "/src/*": "${webRoot}/*",
    "/*": "*",
    "/./~/*": "${webRoot}/node_modules/*"
  }
},

我还尝试了其他几种方法,但都没有成功:

  • 重新安装chrome
  • 安装VS代码1.36
  • 安装VS代码内部人员
  • 我重新启动我的windows机器。
  • 克隆我的repo的新副本,运行npminstall并重建应用程序

所以我创建了一个新的空的Angular CLI应用程序ng new,我可以很好地调试它。这让我相信它与chrome或vs代码无关。然后我决定给予firefox调试,它工作得很好,但现在我真的很困惑。

{
  "type": "firefox",
  "request": "launch",
  "reAttach": true,
  "name": "Launch Firefox localhost",
  "url": "http://localhost:4200/#",
  "webRoot": "${workspaceFolder}"
},
baubqpgj

baubqpgj1#

这是我的开发人员机器的安全相关问题。我能够通过使用不同的基于 chrome 的浏览器(Opera,Edge Beta,Brave)来绕过这个问题。

https://github.com/microsoft/vscode-chrome-debug/issues/911

xe55xuns

xe55xuns2#

除了Calidus的答案,去launch.json,只是改变“ chrome ”到“边缘”

{
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Launch Edge against localhost",
      "type": "edge",
      "request": "launch",
      "url": "http://localhost:4200/",
      "webRoot": "${workspaceFolder}"
    },...

相关问题