DEV Community

Michael Wilkinson
Michael Wilkinson

Posted on • Originally published at realworlddev.hashnode.dev on

Microsoft WebView2 blank or not working?

WebView2? What is that?

Microsoft announced a new control called 'Microsoft Edge WebView2' on October 19th 2020 (official article here) to allow a developer to display content from the web in their native Windows desktop application and to create entire desktop applications built with web technologies.

This new embedded web control is built on top of Microsoft Edge, the newer Chromium edition. When this was announced, there were many comments about how this could cause a dent in the Electron market, particularly for products that only target Windows at the moment. With multi-platform developer goodies from Microsoft (.NET MAUI) on the way, whose to say this wont make Electron sit up and notice.

Currently, if you're building Windows apps with Win32, WPF, WinForms, WinUI 2 or WinUI 3, then you can use this control in your nice new desktop app, or even add it to an existing one as a nice feature addition.

It's not working!

So, after the initial excitement of using this nice new control and see web content in your desktop app in all it's glory, suddenly you notice something a little strange in it's behaviour. Out of seemingly nowhere, it stops working. Your lovely content from the web is suddenly replaced with a blank void. Is it something you've changed? Has your code stopped it from working? Is the web content running some nasty script causing it to stop working? Well, possibly. There is however another reason and it might not be your fault at all.

After working with this control in an evaluation WinUI 3 app, I started to experience the sudden blank content. After a lot of head scratching and debugging, I just couldn't work out what the problem was. So I did the sensible thing and walked away from it with the plan to come back to it the following day. That day came...and it all worked perfectly. Although happy, this made me even more suspicious. This just doesn't happen in software development as we all know! Later that day, it stopped working again. I decided to close all other applications I had open to give it my full attention and it started working again! I haven't got much hair to pull out and my receding locks were starting to look worried.

Bring out the GIMP

I'm not talking about Pulp Fiction here, I am of course talking about the excellent GNU Image Manipulation Program (gimp.org). wilber_med.png

Wilber is looking very happy right there, but it seems that when GIMP is loaded, it's stopping the WebView2 control from working properly.

The Proof

I downloaded the WinUI 3 Controls Gallery from Microsoft that is a really nice little app that shows off the WinUI 3 controls all in one place. winUI3-opening.png

From the Media dropdown menu item, you can select a WebView2 page that displays an example of the control performing in all its glory: winUI3-webview.png

However, after loading GIMP this is what happens to the WebView2 control:

winUI3-webview-broke.png

The control will no longer display any web content at all and remains blank apart from the 'WebView2 is powered by the Chromium engine' text you can see at the top of the controls viewport. On some occasions when opening the gallery app, it crashes instantly and then closes if GIMP is already loaded. This behaviour however is not consistent.

So what's the fix?

Unfortunately, at the time of writing this there is no fix. The only consistency with it, is the control stops working no matter if you're running the app in debug mode from Visual Studio or from a compiled production version of your app. In a nutshell, it stops working everywhere. There is an open issue on GitHub that I have added my feedback to that suggests the same behaviour occurs with Inkscape as well.

Should I be using this then?

Well that's the big question. If you're creating an app to be used in your company where you can be sure GIMP or Inkscape or not being used, then there is no reason not to use it. For an app that will be on general release is a higher risk as you'll have no idea what your users will be running. I would never say you shouldn't be using it, but if the risks are too high, then I would personally wait for a fix to come along.

All this of course means that Electron is still the King when it comes to producing desktop applications created with web technologies and will be for a while I believe. WinUI 3 from Microsoft does look really nice and will definitely be used heavily in companies in the real World, but possible with the WebView2 control being avoided for a wee while...

Top comments (0)