javascript - 无法使用 Debugger for Chrome 在 Visual Studio Code 中放置断点

标签 javascript visual-studio-code

我只是想调试我的 html 页面中的一些 javascript。

我的配置如下:

但是当我调试我的 html 页面时(使用名为“启动 div.html”的第二个选项),它运行但我无法设置断点......

有什么想法吗?

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [        
        {
            "type": "chrome",
            "request": "launch",
            "name": "Launch Chrome against localhost",
            "url": "http://localhost:8080/",
            "webRoot": "${workspaceFolder}"
        },
        {
            "type": "chrome",
            "request": "launch",
            "name": "Launch the div.html",            
            "sourceMaps": true,
            "file": "${workspaceFolder}/div.html",
            "webRoot": "${workspaceFolder}"
        }

    ]
}

最佳答案

似乎不支持调试内联 JavaScript(我也无法设置断点)。你必须将你的 JS 代码分离到它自己的文件中,并将其包含到 div.html 中,如下所示:<script src="div.js"></script> 现在在你的 div.js 中设置断点并开始调试。当我第一次运行调试时遇到断点未命中/加载的问题。我可以通过单击绿色的“重新启动”调试按钮来解决这个问题。

PS:您需要安装 Debugger for Chrome 扩展程序,但您似乎已经安装好了。

关于javascript - 无法使用 Debugger for Chrome 在 Visual Studio Code 中放置断点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48990573/

相关文章:

javascript - 如何让我的文本在 Unity 中显示我的分数?

javascript - AJAX 和 SQL 重复结果

Java-VSCode错误:Cannot resolve the modulepaths/classpaths automatically,请在launch.json中指定值

linux - VS 代码 + 开发(Linux) + 目标(.net Framework) + 主机(Windows)

angular - VS Code 的多个实例

javascript - 如何完全从 JavaScript 添加新视频?

javascript - 如何将 td 的文本颜色更改为红色

git - VS Code Git,3000 多次提交

javascript - 发送警报通知时播放声音

visual-studio-code - Visual Studio代码: How to show line endings