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. 錯誤。