'UWP WebView2 ERR_NETWORK_ACESS_DENIED when loading an IP address (your internet access is blocked)
After installing the WebView2 components for UWP and creating a project using these instructions, the web view cannot load a local IP Source="http://10.20.30.59/".
- The same URL works in WPF WebView, however I need to migrate because of other issues.
- The same URL works in other browsers, just not in WebView2. "Normal" URLs like https://bing.com work fine in the WebView2.
- Turning the firewall off still doesn't allow the content to load.
- Turning off the Windows antivirus under Virus & threat protection settings does not help.
- The
CoreWebView2NavigationCompletedEventArgs.IsSuccessvalue isfalseandWebErrorStatusisConnectionAborted. - Under DevTools > Network > Headers, the failed page has the value Referrer Policy: strict-origin-when-cross-origin. A visit to https://developer.chrome.com/blog/referrer-policy-new-chrome-default/ shows that this can be modified with Chrome flags, but I don't know how to run those flags to verify this is not the problem.
- The feedback area has some similar issues like https://github.com/MicrosoftEdge/WebView2Feedback/issues/2145, but not one that shows how to debug it.
- In the Package.appxmanifest, adding Internet (Client & Server), Internet (Client), Private Networks (Client & Server), and Remote System capabilities does not help.
- Using Node JS + Node Package Manager to run a local server works on
Source="http://10.20.30.106:8080/". This leads me to believe the problem is with the source itself. https://devpractical.com/host-a-html-page-on-localhost/#nodejs-section - The UWP sample WebView2Samples-master\SampleApps\webview2_sample_uwp from https://github.com/MicrosoftEdge/WebView2Samples works fine using the problematic address. Why?
Below is the minimal reproducible example from the instructions:
<Page
x:Class="WebView2_Test.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:WebView2_Test"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:control="using:Microsoft.UI.Xaml.Controls"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<control:WebView2 x:Name="wv2"
Source="http://10.20.30.59/"/>
</Grid>
This involves first installing Edge Canary as recommended; installing the .NET desktop, C++ desktop, and UWP development tools in Visual Studio; and installing the Microsoft.Web.WebView2 and Microsoft.UI.Xaml prerelease NuGet packages.
How to debug what is preventing the source from loading?
Solution 1:[1]
By comparing to the Microsoft sample, I found the missing capability, called Private Networks (Client & Server) in Package.appxmanifest. This is the only requirement for my project.
For whatever reason, when getting back to the project, this capability had gotten unchecked, so maybe restart Visual Studio or otherwise ensure that this capability has really been registered.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Denis G. Labrecque |

