首页 > 解决方案 > 在 Visual Studio Code 中调试时 Firefox 未打开

问题描述

当我使用 Chrome 的启动配置开始调试时,浏览器会打开。但是当我将我的启动配置用于 Firefox 时,浏览器没有打开。不过,Firefox 进程已启动。没有错误消息。

.vscode/launch.json:

{
    "version": "0.2.0",
    "configurations": [
      {
        "type": "chrome",
        "request": "launch",
        "name": "Chrome + localhost",
        "url": "http://localhost:4200",
        "webRoot": "${workspaceFolder}"
      },
      {
        "type": "firefox",
        "request": "launch",
        "reAttach": true,
        "name": "Firefox + localhost",
        "url": "http://localhost:4200",
        "webRoot": "${workspaceFolder}"
      },
    ]
  }

标签: firefoxvisual-studio-codevscode-debugger

解决方案


要使用附加模式,您必须从启用了远程调试的终端手动启动 Firefox。请注意,如果您不使用 Firefox 开发者版,则必须先配置 Firefox 以允许远程调试。为此,请打开开发人员工具设置并选中标记为“启用浏览器 chrome 和附加调试工具箱”和“启用远程调试”的复选框(如此处所述)。或者,您可以在 中设置以下值about:config

Preference Name                          Value  Comment
devtools.debugger.remote-enabled         true   Required
devtools.chrome.enabled                  true   Required
devtools.debugger.prompt-connection      false  Recommended
devtools.debugger.force-local            false  Set this only if you want to attach VS Code to Firefox running on a different machine (using the host property in the attach configuration)

然后关闭 Firefox 并从这样的终端启动它:

视窗

"C:\Program Files\Mozilla Firefox\firefox.exe" -start-debugger-server

操作系统

/Applications/Firefox.app/Contents/MacOS/firefox -start-debugger-server

Linux

firefox -start-debugger-server

导航到您的 Web 应用程序并使用此 launch.json 配置附加到 Firefox:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch index.html",
            "type": "firefox",
            "request": "attach"
        }
    ]
}

如果您的应用程序在 Web 服务器上运行,您需要将 url 和 webRoot 属性添加到配置中(如上面的第二个启动配置示例)。


推荐阅读