2017-08-09 834 views
4

我有默认的配置在launch.json,网站上的端口上运行8080不能在VSCode调试通过连接到Chrome浏览器

{ 
    "version": "0.2.0", 
    "configurations": [ 
     { 
      "type": "chrome", 
      "request": "launch", 
      "name": "Launch Chrome against localhost", 
      "url": "http://localhost:8080", 
      "webRoot": "${workspaceRoot}" 
     }, 
     { 
      "type": "chrome", 
      "request": "attach", 
      "name": "Attach to Chrome", 
      "port": 9222, 
      "webRoot": "${workspaceRoot}" 
     } 
    ] 
} 

enter image description here

然而,当我点击Debug按钮,我得到这个错误:

Cannot connect to the target: connect ECONNREFUSED 127.0.0.1:9222

enter image description here

Question1:为什么VSCode在创建此json时分配端口9222

MS对这个端口有什么特别的要求,MS决定把它放在launch.json中?

问题2:我需要做些什么才能使事情顺利进行。

启动调试总是启动一个新窗口。 我要求具体关于附加调试选项,以便它会在新选项卡中打开。

谢谢。

回答

2
  1. 您需要安装Debugger for Chrome扩展才能正常工作。在VS代码中打开扩展并搜索Chrome的调试器

  2. 您需要在第一个配置中指定的URL上运行Web服务器(默认为http://localhost:8080)。我使用我在全球安装的serve npm软件包。从我的应用程序文件夹运行serve -p 8080

  3. 选择启动Chrome对本地主机选项。它将启动浏览器,并且可以在代码中设置断点,并且调试应该可以工作。

关于第二个配置(附加到Chrome)。港口没有什么特别之处。为了连接到Chrome,您需要在配置中指定的端口上启用启用远程调试的Chrome。例如chrome.exe --remote-debugging-port=9222。我个人从未使用这个选项。只要按照上面的三个步骤,你应该没问题。

相关问题