Visual Studio Code配置Edge/Chrome直接加载本地文件
- 仅本地测试使用
- Edge为Microsoft Edge (Chromium),不是Microsoft Edge (EdgeHTML)
- 下述内容使用Edge配置,如果使用Chrome,把扩展换成 Debugger for Chrome 即可
首先为VSCode安装 Debugger for Microsoft Edge 扩展,然后为项目创建 launch.json 配置文件,在配置文件中增加配置项:
"configurations": [
{
"type": "edge",
"request": "launch",
"name": "Edge (localhost)",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}",
"file": "${file}",
"runtimeArgs": [
"--allow-file-access-from-files"
]
}
]
配置项中的 file
字段设置点击运行按钮时,直接使用Edge浏览器打开当前在VSCode中打开的文件。
配置项中的 runtimeArgs
数组中的元素是Edge浏览器的启动参数,--allow-file-access-from-files
参数使Edge允许跨文件加载文件内容,可以解决加载文件时出现的 Cross origin requests are only supported for protocol schemes: http, data, chrome-extension, edge, https. 错误。