VSCode使用Chrome调试Html,Js(支持跨域,访问本地Json)
安装Debugger For Chrome
需要先在VSCode扩展功能中搜索安装Debugger for chrome。
配置launch.json
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请在这里插入代码片`访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "使用Chrome调试html",
"type": "chrome",
"request": "launch",
"file": "${file}", //调试当前打开的文档
// "url": "http://mysite.com/index.html", //使用外部服务器时,请注释掉 file, 改用 url, 并将 useBuildInServer 设置为 false "http://mysite.com/index.html
"runtimeExecutable": "D:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome_80.exe", // 改成您的 Chrome 安装路径
// 需要跨域的话就打开以下注释。预先在源码目录创建文件夹UserDataDir
"runtimeArgs": [
"--disable-web-security",
"--user-data-dir=${workspaceRoot}\\UserDataDir",
],
"sourceMaps": true,
"webRoot": "${workspaceRoot}",
"userDataDir": "${tmpdir}",
"port": 5433
}
]
}
开始调试
在调试窗口,选择“使用Chrome调试html”,打开需要调试的html文件,按F5即可调试。
————————————————————————————————————————————
参考:
http://blog.dreamlikes.cn/archives/993