VSCode上带有Chrome调试器的WSL 2出现ECONNREFUSED错误



我在一台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
},
]
}

每当我按下F5键时,我都希望看到我的index.html页面加载到一个新的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"
} ]

此外,我还根据这个建议在我的settings.json:"remote.extensionKind": {"msjsdiag.debugger-for-chrome": "workspace"}中进行了设置。我还重新启动了我的机器,启动VS Code,然后启动(不打开任何其他Chrome窗口(。

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

这是vscode的一个bug。可以通过将扩展插件"JavaScript Debugger"替换为"JavaScript Debugger(Nightly("来解决此问题。请参阅:https://github.com/microsoft/vscode/issues/120227

最新更新