Search code examples
javascriptreactjswpfwpf-controlswebbrowser-control

Is there any way to launch entire React application with all JS files through Web Browser control in WPF? Java scripts are not gettin loaded correctly


I am using .NET WPF WebBrowser control in our application to launch the whole react application in web browser control. But when I run the WPF application It shows me the dialog box with javascript error and if you press yes-yes to all the questions then also It ended up showing nothing on the screen but the blank screen

This is my code

public MainWindow()
{
   InitializeComponent();

   webBrowser1.Navigate("http://localhost:3000/");
}

Where my react application is running on port 3000(Checked everything and running properly)

This is the dialog box shown when I run the application When I press yes , It opens another dialog box with different java script file error

Second error for "2.aeaacf2c.chunk.js" file

Third error for "main.a60e0400.chunk.js " file

When I press "yes" for all , It ended up showing blank screen with no loaded JS


Solution

  • WPF's legacy WebBrowser control uses Internet Explorer which is pretty much a dead product. It will not display a React page better than IE, which is to say, badly or not at all.

    Please take a look at WebView2 or better yet CEFSharp. (FYI I have no affiliation with either product). Either will suit your needs but I like CEFSharp better as it doesn't require the end user to install any dependencies. This is a big gotcha with WebView2.