Need better way to use HTML in a C# form when WebBrowser uses outdated IE11

67 views Asked by At

I am showing HTML in a windows form where I can edit and quickly see the results. The following code works but if the "ShowString" has a reference to a site that does not allow IE11 then I get an error when the site is accessed.

public ShowPage(string ShowString)
{
   InitializeComponent();
   webBrowser1.DocumentText = "<!DOCTYPE html><html><head>" + ShowString + "</body></html>";
}

I tried several suggestions to fix WebBrowser but all they did was raise the IE to version 11 which does not help with sites rejecting 11.

I tried WebView2 but it has no DocumentText where I can pass in my html. The only other suggestion was to look at CefSharp. I was unable to get that package into my project and the example project I built did not look like it was useful.

I would like to avoid writing the HTML to a local file and shelling out a real browser. I looked at command line input to chrome but did not see a way to pipe in my HTML text.

The WebBrowser displays the HTML correctly, but if you click on a url some sites will reject the visit. Image of error Thanks for looking!

1

There are 1 answers

0
Joseph Stateson On

Using Liu's suggestion the following worked

        async void ShowStuff(string strIn)
        {
            await webView.EnsureCoreWebView2Async();
            webView.NavigateToString(strIn);
        }

        public ShowPage(string ShowString)
        {
            InitializeComponent();
            ShowStuff(ShowString);
        }

[edit] Unfortunately, WebView needs to be distributed with my app as it cannot run without it.