Replies: 7 comments
-
I'm guessing you're using the WebView2 APIs via the WinAppSDK which means you are using the WinRT WebView2 APIs not the .NET WebView2 APIs (the documentation you linked to is the .NET docs). Here is the WinRT CoreWebView2Environment documentation. It looks like there's a difference in the naming for WinRT where .NET has an overload for CreateAsync and WinRT uses a different name for that method CreateWithOptionsAsync. More details: There are two places you could be getting WebView2 APIs from: the WebView2 SDK nuget package or the WinAppSDK. If its the WinAppSDK then you're using the WinRT WebView2 APIs and which version of WinAppSDK you have determines which version of the WinRT WebView2 APIs you're using. If its the WebView2 SDK nuget package then you could be using the COM, .NET or WinRT WebView2 APIs and which version of the WebView2 SDK you're using determines which version of the WebView2 APIs you're using. Your pasted code is C# so its either .NET or WinRT WebView2 APIs. It sounds like you didn't go and find the Webview2 SDK so you're probably using WinApp SDK which only supports WinRT so that's my guess. |
Beta Was this translation helpful? Give feedback.
-
thanks so much for the quick response! this is the hello world for webview2 I used, since i am trying to make a UWP app for the win app store https://learn.microsoft.com/en-us/microsoft-edge/webview2/get-started/winui2 it looks like i used the WinUI2 for UWP setup i will have to see if i can figure how this maps to your detailed answer here. if you have any further advice along those lines, please let me know. also on a slightly related question, should i be using WinUI3 instead of WinUI2 for a new store app (targeting desktops/laptops/tablets)? code was planned to be a simple C# wrapper around a WebView2, most of app UI & logic within the web view. actually tablets are not so required but is a nice to have. are there limits to where WinUI3 can run (e.g. only on Win 11 or something?) |
Beta Was this translation helpful? Give feedback.
-
WinUI3 is where they are investing new work and bug fixes and such and is the best option going forward. I don't know what sorts of things are supported or not supported though. FYI, WinUI3 is via WinApp SDK which currently bundles a version of the WebView2 SDK and so gets WebView2 SDK updates slower than using WinUI2/WPF/WinForms and doesn't let you choose your own version or try out experimental APIs. |
Beta Was this translation helpful? Give feedback.
-
Thanks again, I did find the doc you mentioned. Still no go. The issue seems to be me loading a local-to-the-app html file (with javascript in it) [this works, and the javascript executes], then using JS fetch() in the javascript to call out to any web service. The fetch() call fails with a Type Error. I have narrowed it down to a simple case... pulling from https://bing.com or any basic web site in the JS fetch() , even that fails with a Type Error. I have attached my setup which is based upon a simple WebView2 wrapper that your docs suggested to set up (C# UWP WinUI2). I am unsure why it would be a Type Error unless something is erroring out internally in the fetch() code. I have attached both the html code w/ javascript and the C# which sets up the web view the web view is defined in the XAML per your examples, but in the C# , the source for the web view is re-set since apparently ms-appx-web is no longer supported (?) from what I can tell from various links:
|
Beta Was this translation helpful? Give feedback.
-
Yes, WebView2 will follow normal browser cross origin request rules. If you call |
Beta Was this translation helpful? Give feedback.
-
Yes agreed, ms-appx type urls were from old doc, I am not using them. I am using the host name mapping as you noted, which works. I was having trouble getting the javascript console to show to see if any messages were showing from JS fetch (using VS Community Edition 2022). The doc to find this console seems to be written for a different edition of VS. I had another ticket out on this item but haven't heard back yet. I had fixed some CORS issues w/ my API server when developing this JS code for a regular browser (e.g. firefox chrome etc). I guess I could check if there are issues w/ Edge browser in particular, outside this WebView2 environment as a next step. It does seem kind of like a CORS issue. I think there is a "cors" key/value setting in fetch options arg too. Going to check into that. I thought I had tried that before but maybe not in this particular context. |
Beta Was this translation helpful? Give feedback.
-
Ok I found how to open the JS dev tools for WebView2: ctrl shift i The js console msg pointed out the error: I loading the main page from in-app with https: but my sever still has http: , so it throws an error telling this. Side note, my server is already set up for CORS. Seems to work now after I fixed this https/http mismatch. So... good progress, thanks for the discussion! Now I will try to put in my real JS app code and see how it works! |
Beta Was this translation helpful? Give feedback.
-
based upon some advice online, am trying to use
var op = new CoreWebView2EnvironmentOptions();
op.AdditionalBrowserArguments = "--disable-web-security";
CoreWebView2Environment.CreateAsync(null, null, op); // this line errors on compile
compiler saying: CS1501: No overload method 'CreateAsync' take 3 arguments
however, the doc clearly states that CreateAsync takes 3 arguments, vis:
public static System.Threading.Tasks.Task<Microsoft.Web.WebView2.Core.CoreWebView2Environment> CreateAsync (
string browserExecutableFolder = default,
string userDataFolder = default,
Microsoft.Web.WebView2.Core.CoreWebView2EnvironmentOptions options = default
);
doc link is:
https://learn.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2environment?view=webview2-dotnet-1.0.1462.37
is there a way to properly find the the doc for the version of webview2 that is installed for VisualStudio 2022 builds?
as far as i know, i installed the latest WebView2 setup based on an official WebView2 "hello world" example from MS
Beta Was this translation helpful? Give feedback.
All reactions