Eilon / MauiHybridWebView

MIT License
203 stars 41 forks source link

How to enable cors in HybirdWebview #4

Open ndq2002 opened 1 year ago

ndq2002 commented 1 year ago

How to enable cors in HybirdWebview?

Eilon commented 1 year ago

@ndq2002 for the most part there shouldn't be a need to enable CORS because there are no web requests going on in typical scenarios. All the resources are static and loaded locally.

Can you show a code example of what you'd like to do, but doesn't work?

mnazers734 commented 6 months ago

We are getting CORs errors when trying to access user information from AWS and when trying to load map data from Google Maps. We implemented a traditional hybrid webview for XF and do not see these errors.

Eilon commented 5 months ago

Can you share a snippet about what code is running when the CORS error happens? Is it JS code that is part of the MAUI HybridWebView app doing a fetch() to an AWS location?

peterblazejewicz commented 5 months ago

@ndq2002 @mnasers afaik all request are done with 0.0.0.0 domain in header, when using Blazor/Hybrid web view. This can be behind problems you're facing. hth

mnasers77 commented 5 months ago

Hello,

Thanks for the response. I thought I was getting CORs errors due to the AppOrigin being set to 0.0.0.0 but I believe the CORs error I am receiving is due to the JavaScript code trying to call Google Maps directly. I think if we change it so our server makes the call to Google Maps instead, it will resolve the error. There were other resources not loading that I thought were also due to CORs errors but it was because their mime type (.svg) wasn't included in the case statement inside CoreWebView2_WebResourceRequested.