Loading referenced files from HTML in VSCode Extension Webview

Viewed 732

I am currently trying to load a .html file which has references to .css and javascript files, and also other .html files, which again have more references to other files.

When i upload my .html and all referenced files to github pages, i can load it in an vscode extension webview and it works perfectly.

When i try to do it locally (therefore, putting all the .html, .css and javscript files in my extension directory), i can load the initial html, but none of the referenced files are loading.

The documentation (https://code.visualstudio.com/api/extension-guides/webview#loading-local-content) tells me vs code is very restrictive when it comes to local files, and those references should be converted with Webview.asWebviewUri.

This helps me to load the initial page, but how to update all those references? The way that its done in the VS code tutorial is to have the .html hardcoded in the script, load all referenced files seperatly with Webview.asWebviewUri and inject the new reference links on all needed positions. I dont think thats really a good option for me, since there are a LOT of files that have to be loaded, and again, it would not work if something has to be loaded from an .html file that was loaded from the main .html file.

Several Questions:

  1. Why is vscode so restrictive on local files, but completely unrestrictive when it comes from files from the web? Shouldnt web files be considered "more dangerous"?
  2. Is there a way to mark a folder as "files from this folder are fine, just load them"? I know there is WebviewOptions.localResourceRoots but as far as i understand it, i still have to convert the references with Webview.asWebviewUri, and then injecting it into the html, in order to load referenced files.
  3. Any solution i am not seeing?
0 Answers
Related