【问题标题】:Firefox does not open when debugging in Visual Studio Code在 Visual Studio Code 中调试时 Firefox 未打开
【发布时间】:2019-07-29 21:13:03
【问题描述】:

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

  • Visual Studio 代码 1.36.1
  • Debugger for Firefox1.8.1
  • 火狐 68.0.1
  • Windows 10 1803
  • Angular 7.0.0(应该没关系)

.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}"
      },
    ]
  }

【问题讨论】:

标签: firefox visual-studio-code vscode-debugger


【解决方案1】:

要使用附加模式,您必须从启用了远程调试的终端手动启动 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 属性添加到配置中(如上面的第二个启动配置示例)。

【讨论】:

  • 我确定这对于 attach 模式是正确的,也许这就是 OP 真正想要的,但鉴于问题表明 Chrome 正确打开而 Firefox 没有,我猜 launch 模式 is 是想要的,这是在回答一个不同的问题(我想 Chrome 中的附加模式也需要单独启动浏览器)。
【解决方案2】:

我的配置和工作流程。

附注我在about:config 中更新了 Firefox 配置,但没有像 Google Chrome 那样获得所需的简单结果。

我安装了以下浏览器(Ubuntu 20.04 x64):

  • Firefox 用于 Ubuntu 94.0
  • Google Chrome 版本 96.0.4664.45(官方版本)(64 位)
  • Microsoft Edge 版本 96.0.1054.34(官方版本)测试版(64 位)

对于所有浏览器,我没有更改它们的配置。

我的调试扩展(只有一个):Debugger for Firefox

我的 VS 代码:

Version: 1.62.3
Commit: ccbaa2d27e38e5afa3e5c21c1c7bef4657064247
Date: 2021-11-17T08:00:36.721Z
Electron: 13.5.2
Chrome: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Linux x64 5.11.0-40-generic

配置

{
    "configurations": [
        {
            // Start Debug -> Open Firefox, Open Debug console, Click an line in JS File and F5
            "type": "firefox",
            "request": "launch",
            "reAttach": true,
            "name": "Firefox + File",
            "file": "${file}"
        },
        {
            // Start Debug -> Open Firefox, Open Debug console, Click an line in JS File and F5
            "type": "firefox",
            "request": "launch",
            "reAttach": true,
            "name": "Firefox + Server",
            "url": "http://localhost:8080/${fileBasename}",
            // "url": "http://localhost:8080/index.html",
            "webRoot": "${workspaceFolder}/public/"
        }
        {
            "type": "pwa-chrome",
            "name": "Chrome + File",
            "request": "launch",
            "file": "${file}"
        },
        {
            "type": "pwa-chrome",
            "name": "Chrome + Server",
            "request": "launch",
            "url": "http://localhost:8080/${fileBasename}",
            // "url": "http://localhost:8080", // the index file
            "webRoot": "${workspaceFolder}/public"
        },
        {
            "name": "Edge + Server",
            "request": "launch",
            "type": "pwa-msedge",
            "url": "http://localhost:8080/${fileBasename}",
            // "url": "http://localhost:8080",
            "webRoot": "${workspaceFolder}/public",
            "runtimeExecutable":"/opt/microsoft/msedge-beta/msedge"
        }
    ]
}

我可以将我的index.html 和其他 html 文件作为本地文件和服务器页面运行在公共目录中。在我的服务器上,该文件位于public 目录中。我从公共目录所在的根目录工作。

我只有 Firefox 才有一些不愉快的问题。现在它适用于以下解决方法和上述配置。

在 Firefox 中开始调试的步骤:

  1. 使用提供的配置,我们可以根据需要更改路径或文件。 https://code.visualstudio.com/docs/editor/variables-reference 但对我来说,当我在 URL 中使用指定文件时,它可以工作,例如,/index.html
  2. 开始调试(选择配置并按F5)。
  3. Firefox 已打开,但调试仍未成功。
  4. 打开开发工具 (F12)。 是的,没有它调试对我不起作用。
  5. 重新加载页面(在浏览器中按 F5 或在您的操作系统中按 Ctrl+R 或其他组合键)。
  6. 已使用您的断点开始调试。

我收到了 VS Code 的以下消息,但它在没有额外路径的情况下工作:

此文件的路径未映射到 Firefox 加载的任何 url。 Firefox 尚未加载此文件,或者您的调试配置需要此文件的路径映射 - 您是否认为该文件已加载并希望路径映射向导尝试为您创建路径映射?

我对 Microsoft Edge 浏览器进行了一些修复。我设置了浏览器bin文件的路径:"runtimeExecutable":"/opt/microsoft/msedge-beta/msedge".

【讨论】:

    猜你喜欢
    • 2018-09-13
    • 2020-01-06
    • 1970-01-01
    • 1970-01-01
    • 2019-07-06
    • 1970-01-01
    • 2023-01-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多