WSL 2 与 VSCode 上的 Chrome 调试器的 ECONNREFUSED 错误

Kha*_* Yi 9 html web-deployment visual-studio-code windows-subsystem-for-linux chrome-debugging

我在 Windows 10 机器上,使用 WSL 2 (Ubuntu 18.04) 的 VS Code 尝试使用Chrome 调试器扩展,但无济于事。以下是我的launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch index.html",
            "type": "chrome",
            "request": "launch",
            "file": "${workspaceFolder}/index.html",
            "runtimeExecutable": "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe",
            "runtimeArgs": [" --remote-debugging-port=9222"],
            "userDataDir": "${workspaceFolder}/chrome",
            "port": 9222
        },
    ]
}
Run Code Online (Sandbox Code Playgroud)

index.html每当我按 F5 时,我都希望看到我的页面加载到新的 Chrome 选项卡中,但它所做的只是启动一个新的空白 Chrome 窗口,然后间隔大约 15 秒弹出两个错误。

我不太关心第一个错误,它说Google Chrome cannot read and write to its data directory: <VALID-DIRECTORY-ON-MY-MACHINE>. 过去一天半我一直试图解决的是第二个错误,它说

Cannot connect to runtime process, timeout after 10000 ms - (reason: Cannot connect to the target: connect ECONNREFUSED 127.0.0.1:9222)

我在 Stack、GitHub、VS Code 开发站点等上尝试了很多解决方案,但没有任何帮助。在我的 Chrome 浏览器上,http://localhost:9222/json抛出了一些内容,我理解这意味着浏览器应该可用于连接:

[ {
   "description": "",
   "devtoolsFrontendUrl": "/devtools/inspector.html?ws=localhost:9222/devtools/page/E7E1DFE661F744BE79A572564251BC39",
   "id": "E7E1DFE661F744BE79A572564251BC39",
   "title": "New Tab",
   "type": "page",
   "url": "http://localhost:9222/json",
   "webSocketDebuggerUrl": "ws://localhost:9222/devtools/page/E7E1DFE661F744BE79A572564251BC39"
}, {
   "description": "",
   "devtoolsFrontendUrl": "/devtools/inspector.html?ws=localhost:9222/devtools/page/C089932CAB5A26F4409B78F887C84A50",
   "id": "C089932CAB5A26F4409B78F887C84A50",
   "title": "about:blank",
   "type": "page",
   "url": "about:blank",
   "webSocketDebuggerUrl": "ws://localhost:9222/devtools/page/C089932CAB5A26F4409B78F887C84A50"
} ]
Run Code Online (Sandbox Code Playgroud)

此外,我还设置了我的settings.json:"remote.extensionKind": {"msjsdiag.debugger-for-chrome": "workspace"}基于此推荐。我还重新启动了我的机器,启动了 VS Code,然后启动(没有打开任何其他 Chrome 窗口)。

似乎所有应该工作的东西都没有,这意味着我可能在这里误解了一些东西。我的问题是,我在这里做错了什么吗?

小智 0

这是vscode的一个bug。可以通过将扩展“JavaScript 调试器”替换为“JavaScript 调试器(夜间) ”来解决此问题。请参阅: https: //github.com/microsoft/vscode/issues/120227