首页 > 解决方案 > 从 vscode 调试启动时,如何使 Firefox 正确恢复其状态?

问题描述

对于我的 React webapp,我有一个启动配置来启动 Chrome 或 Firefox 进行调试。两者都工作得很好,除了 Firefox 在调试启动后没有恢复它以前的设置(或者它甚至没有保存它们)。

当我启动 Chrome 时,它​​会记住浏览器的大小和位置,并且我接受了本地主机的自签名证书。

Firefox 不会做任何事情。启动后,我总是必须重新定位窗口并再次接受自签名证书,随着时间的推移,这变得非常烦人。

这是我的启动设置:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "firefox",
            "request": "launch",
            "reAttach": true,
            "name": "Launch MSG on FF",
            "url": "https://localhost:3001",
            "webRoot": "${workspaceFolder}/src",
            "clearConsoleOnReload": true,
            "preLaunchTask": "tsc: watch"
        },
        {
            "type": "chrome",
            "request": "launch",
            "name": "Launch MSG on Chrome",
            "url": "https://localhost:3001",
            "webRoot": "${workspaceFolder}/src",
            "userDataDir": "${workspaceRoot}/.vscode/chrome",
            "sourceMaps": true,
            "preLaunchTask": "tsc: watch",
            "sourceMapPathOverrides": {
                "webpack:///build/*": "${webRoot}/*"
            }
        },
        {
            "type": "node",
            "name": "Run Tests",
            "request": "launch",
            "program": "${workspaceFolder}/node_modules/jest/bin/jest",
            "args": [
                "--config ${workspaceFolder}/jest.config.js"
            ],
            "cwd": "${workspaceFolder}",
            "console": "integratedTerminal",
            "internalConsoleOptions": "neverOpen",
            "disableOptimisticBPs": true
        }
    ]
}

在从 vscode 调试时,需要更改什么以使 FF 也保持最后状态?

以防万一这很重要:我在 macOS 上,并且调试实例的 FF 配置文件文件夹位于/var/folders/03/...(并且该文件夹存在并且是可写的)。

标签: reactjsfirefoxvisual-studio-code

解决方案


您正在寻找以下标志:

keepProfileChanges : true

此外,您可以使用以下方式指定配置文件:

profile : "dev"

而且,只需一点点,您可以使用以下命令自动打开开发工具:

firefoxArgs : [
   -devtools
]

为简洁起见:

"configurations": [
  {
    "type": "firefox",
    "request": "launch",
    "reAttach": true,
    "name": "Launch Name",
    "clearConsoleOnReload": true,
    "keepProfileChanges": true,
    "profile": "dev",
    "firefoxArgs": [
        "-devtools",
    ]
]

如果您需要创建配置文件的资源:参考

Firefox CLI参考


推荐阅读