Home > Back-end >  Why can I not open some website with C# web browser?
Why can I not open some website with C# web browser?

Time:06-02

I'm trying to create a simple WPF window in C# with a web browser inside. It works with some common website like Google or Youtube. However, there are some cases that errors occurs when I change the Source. Here is the error

Here is my xaml code:

<Window x:Class="WEB0.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:WEB0"
    mc:Ignorable="d"
    Title="VKP opens Website" Height="600" Width="1000" Background="Gray">
<Grid>
    <WebBrowser Source="https://pythonparts.allplan.com/" Margin="10,10,10,10"/>

</Grid>

I don't how to solve this error or where it come from. So, I need some help here.

CodePudding user response:

If you point the control to https://www.whatsmybrowser.org/ you'll notice it gets reported as IE11, that's because WebBrowser uses an old ActiveX control. A lot of modern web sites simply don't support browsers that old.

If you want to embed Chromium then you'll need to look into one of the 3rd-party solutions for doing so. If your target OS supports Edge then you can instead simply replace WebBrowser with WebView2 by installing Microsoft.Web.WebView2 via NuGet and using the WPF control it provides:

<wv:WebView2 xmlns:wv="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
    Source="https://www.somewebsite.com/" />
  • Related