Visual Studio Code配置Edge/Chrome直接加载本地文件

Visual Studio Code配置Edge/Chrome直接加载本地文件

  1. 仅本地测试使用
  2. Edge为Microsoft Edge (Chromium),不是Microsoft Edge (EdgeHTML)
  3. 下述内容使用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. 错误。

发布了76 篇原创文章 · 获赞 131 · 访问量 39万+

猜你喜欢

转载自blog.csdn.net/qq_21397217/article/details/104642691