The Most Exciting Part of Microsoft Edge is WebView2

Finally there’s a consistent way to host the Chromium engine in your Windows applications

Matthew MacDonald
Aug 24, 2020 · 4 min read
Image for post
Image for post

In the ancient days of the 1990s, when the internet was a new and trendy invention, programmers wondered if it might be a good vehicle for applications. So we tried to take the desktop technology of the time and wedge that into our web browsers. We used tools like ActiveX plugins and Java applets. We used embarrassingly bad, proprietary plugins like Office Web Components and FrontPage Extensions. Most sensible programmers stayed far away.

Eventually people realized these strategies were never going to work at the scale of the web and for the incredible variety of web-connected computers and devices. There was too much install, too many security risks, too little support across different platforms. Instead, it turned out that the right model was the reverse. Instead of putting a native app into a browser, Trojan horse style, we needed to sneak web apps into our desktop applications. Today, this type of approach is called a hybrid application and it runs the gamut from a simple web page shown alongside native content to a complete JavaScript app in Electron.

Despite the popularity of hybrid applications, modern solutions for rolling your own are a bit of a patchwork. If you don’t want to use a full framework like Electron, you need to rely on a system control like WebBrowser (the original, IE-powered window for hosting web content) or the newer WebView (based on Edge, but limited to Windows 10). In the best case scenario, you’re managing a fallback to IE on older computers, and dealing the creaky Internet Explorer browser long past its expiration date. As a side effect, you never know what level of standards compliance you’ll get, which makes it impossible to take advantage of the most modern JavaScript and CSS features.

Microsoft has been promising a fix for a while. They demonstrated a successor to WebView for C++ applications at last year’s Build conference. Now this successor,WebView2, is finally arriving and finally supports all types of Windows applications.

Here’s the big picture. WebView2 runs on any version of Windows, reaching back to Windows 7. Microsoft also claims that it works on versions of Windows Server all the way back to the preposterously old Windows Server 2008 R2 (a fact that’s both incredible and mostly useless).

More importantly, WebView2 is guaranteed to use the Edge browser’s implementation of the good old industry standard Chromium engine. On pre-Windows 10 computers, there’s a small distributable that you may need to include (essentially, a componentized version of Edge). Once you do you’re guaranteed the latest version of the Edge rendering engine, in perpetuity. There’s also a “fixed” mode that lets you lock your application down to the version of Edge you built it with. But if you go this route, it’s up to you to manage the distribution of Edge updates, and accept the security risk of old versions.

The wide compatibility and lightweight nature of WebView2 is impressive. It’s enough to make me forgive Edge for its aggressive attempts to sneak into my task bar and take over the default browser setting. (For the record, I think that Edge is a dramatically better browser than IE, but still plagued by some quirks. It’s best features are the ones copied from Chrome, and — although I won’t judge anyone who picks it for their daily driver — Edge still hasn’t become my favorite browser.)

WebView2 also has expansive application support. Its first early preview version was for C++ only. Now it runs on the .NET Framework both new and old (from .NET Framework 4.6 and .NET Core 3, to the future, .NET 5). And your choice of applications isn’t limited, because WebView2 works seamlessly in every important type of Windows application, including WPF, the new version of WinUI, Windows Forms, and even old-school Win32, as you would expect.

In other words, you can take a legacy application, touch none of its application code, but insert a Chromium-powered window that hosts add-on content. You could use that window for a documentation system, news content, or add-on features. If you want to extend your application and blur the boundaries between desktop and web, there’s the usual message-passing ability (you can call a custom JavaScript function in your hosted web page, or your web page can notify you by posting a string or maybe some JSON). The WebView2 is already turning up all over Office, including in the desktop version of Outlook, where it hosts the Room Finder panel.

Although WebView2 still isn’t finished, it’s finally graduated to a preview release, and Microsoft has plenty of documentation and sample content. General availability for all application types is slated for the end of the year.

The future of WebView2 could be even brighter. It’s easy to imagine WebView2 facilitating a lightweight alternate to Electron with none of the Node.js overhead. And it’s particularly relevant now that Microsoft is experimenting with approaches that can lower the desktop hosting footprint for Blazor. In fact, given the popularity of Electron and all types of hybrid applications, it’s surprising how long it’s taken Microsoft to get this working. And it makes their decision to abandon IE and adopt Chromium even easier to understand.

For Microsoft news, programming deep dives, and occasional humor, subscribe to the monthly Young Coder newsletter.

Young Coder

Hack. Code. Think. Stories about science, tech, and programming.

Matthew MacDonald

Written by

Teacher, coder, long-ago Microsoft MVP. Author of heavy books. Join Young Coder for a creative take on science and technology. Queries: matthew@prosetech.com

Young Coder

Hack. Code. Think. Stories about science, tech, and programming.

Matthew MacDonald

Written by

Teacher, coder, long-ago Microsoft MVP. Author of heavy books. Join Young Coder for a creative take on science and technology. Queries: matthew@prosetech.com

Young Coder

Hack. Code. Think. Stories about science, tech, and programming.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store