MicrosoftEdge / WebView2Feedback

Feedback and discussions about Microsoft Edge WebView2
https://aka.ms/webview2
450 stars 54 forks source link

WebView Content Loader #3074

Closed DanZamora closed 1 year ago

DanZamora commented 1 year ago

I am using WebView2 with Win32 in C/C++. I use the sample and modified it to navigate to string instead of simple navigate, and remove the only https filter so local content can be loaded. But I am having issues loading the css and javascript content. I noticed that if I used navigateToString I needed to added myself to the string but I am requesting how to manage the content loading of css and javascript, as local path references, maybe using a local uri or if there is any way in which I can use relative paths as in normal html programming, so when they are published in a package (where I don't have the full path of the user system), the system can recognize the files as relative in the executive bundle.

As a second request, the href or src properties of images and text in html isn't working as expected neither. I am using full local and relative paths as in normal html programming, but when the string is loaded this paths aren't preprocessed and I get no images neither local hyperlinks, maybe using a local uri too (but I don't find to much uri for C/C++ information and msapp, for example, is not configure in my regular C/C++ Visual Studio Project).

What I understand as a regular html programming would be create a html file and use local relative paths included in the public bundle of any web framework: ASP.NET, Express, JavaSpring, Django, Laravel, Rocket, RubyOnRails, etc...

DanZamora commented 1 year ago

Already fixed it. Just use the navigate and not navigateToString and use a local uri: "file:///C:/...". When deploying the app, save the www directory in a fixed path a used it, inclusively with relative paths like %ProgramFiles% or other enviromental variable. Save the /www/css, /www/js, /www/img and so on and they will be loaded. When loading images or other files in html, use the html relative path, for example if index.html is in /www and you want to access an image in ./www/img, use ./img and so on.