Webview2 Uwp



In the last post I’ve shown how to use the new WebView2 control in a WPF app and said that it could be used in any Windows version and in any platform. As a matter of fact, I can create a 64 bit VCL native application with Delphi, that uses the Win32 API with the same control, offering the same functionality that the previous app did. To do that, you must have Delphi 10.4 Sydney installed in your machine. It offers the TEdgeBrowser component, that can be used to browse the web using the Chromium component.

Webview2 uwp exampleWhat is microsoft edge webview 2 runtime

In Delphi, create a new VCL application. Add the 64 bit platform to it and set it default. Add a TPanel, docked at the top. Then add a TEdgeBrowser and doc it to fill the window. In the panel, add a TLabel and change the Caption property to Search Text, add a TEdit and clear its Text property. Then, add two buttons and set their property Caption to Find and Copy. Add two more buttons at the right of the panel and set their sizes to 23×23, and their font Height to 10, Name to Segoe MDL2 Assets and their caption to the Back and Forward icons in the Character Map:

The new browser Control for Windows Apps is called WebView2 and is based on the Google Chrome (Chromium, in Microsoft as Canary) browser API. The Control replaces the old WebBrowser in WinForms and WebView in WPF and UWP and is already being used as. The WebView2 Runtime Any Insider (non-stable) Microsoft Edge (Chromium) browser channel Have anyone managed to get this running without installing a BETA release of Microsoft Edge directly as this is not an option nor is it recommended. C# uwp webview2. You can access WebView2 in your UWP applications using Win UI 3.0, currently in alpha. For more information about keeping up to date, navigate to Windows UI Library Roadmap. The Microsoft Edge WebView2 control enables you to embed web technologies (HTML, CSS, and JavaScript) in your native apps. The WebView2 control uses Microsoft Edge (Chromium) as the.

You should have something like this:

Now you can set the OnCreate event of the main form to

and run the application, but you won’t see nothing in the window. You can check the initialization of the WebViewer in the OnCreatedWebViewCompleted event and check the AResult parameter.

Webview uwp unity

You will see that there is an error code (in my machine it’s $80004005). This is due to the fact that the WebView dll is missing. The dll is in the Redist folder and you have to add a PostBuild command to the project. Go to Project/Options and select Build options and, in the command “Value from All Configurations – Windows 64 bits”, add the following command:

This will copy the dll to the output directory and will initialize the WebView correctly(you will see that there is no message in the OnCreatedWebViewCompleted event and the page is loaded. Now, we can add the event handlers for the buttons. The Find button will set up the address and call the Navigate method (You must add the NetEncoding unit to the Uses clause):

Webview2 sample application

Webview2 Wpf

The Back and Forward buttons events are very simple to implement: Samsung champ mobile game free download.

To remove the parts of the page that we don’t want, we use the OnNavigationCompleted event to inject the JavaScript code:

You can see here the same JavaScript code we used in the previous post, it also logs to the console the value of the variables. You can also open the Developer Tools of the browser component by pressing F12.

Now, there is only the Copy button to get the results and copy them to the clipboard. We will inject the code that gets all the results and send them to the application:

Webview uwp unity

This is the same code that is injected in the WPF app, with a slight difference: in the WPF program we’ve sent a message and added a listener in the JavaScript code. Here, we are running the code when the user clicks the button. This will send a message to the app, that will be processed in the OnMessageReceived event:

Now, when you run the program, you will have the same results as in the WPF program:

As you can see, with the new WebView2 component you have a lot of flexibility, you can use it in .NET or Win32 programs with almost no change. You can use this component to browse the Web and get data from the browsing, or you can use it to complement your current app: let’s say you have parts of your app that are already written for the web and you don’t want to rewrite them, but use them to interact with your app, you can add these parts and include them in your desktop app.

The full source code for this project is at https://github.com/bsonnino/WebViewDelphi

The WebView2 control enables you to embed web technologies (HTML, CSS, and JavaScript) in your native applications powered by Microsoft Edge (Chromium).
This package is necessary for Win 32 C/C++ applications. To learn more about package versions checkout https://aka.ms/wv2-packageversion. To learn best practices checkout: https://aka.ms/wv2-bestpractices.

There is a newer prerelease version of this package available.
See the version list below for details.
For projects that support PackageReference, copy this XML node into the project file to reference the package.

Microsoft Edge Webview2

The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Webview2 Uwp C#

#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Release Notes

Release notes are at https://aka.ms/webviewrelease

Dependencies

  • native 0.0

    • No dependencies.

Webview Uwp Unity

Used By

NuGet packages (18)

Showing the top 5 NuGet packages that depend on Microsoft.Web.WebView2:

PackageDownloads
Microsoft.Identity.Client
This package contains the binaries of the Microsoft Authentication Library for .NET (MSAL.NET). MSAL.NET makes it easy to obtain tokens from the Microsoft identity platform for developers (formally Azure AD v2.0) signing-in users with work & school accounts, Microsoft personal accounts and social identities Azure AD B2C. These tokens gain access to Microsoft Cloud API and any other API secured by the Microsoft identity platform. This version supports adding authentication functionality to your .NET based client on Windows desktop (.NET 4.5+), UWP, .NET Core, Xamarin iOS and Xamarin Android.
TecWare.PPSn.DesktopUI
MtrDev.WebView2.Interop
Interop for Microsoft WebView2 control
Xenial.Framework.WebView.Win
Atkins.DynamicObjects.AssetUI
NET Framework 4.7.2

GitHub repositories (11)

Showing the top 5 popular GitHub repositories that depend on Microsoft.Web.WebView2:

RepositoryStars
QL-Win/QuickLook
rocksdanister/lively
Free and open-source software that allows users to set animated desktop wallpapers and screensavers.
picoe/Eto
Cross platform GUI framework for desktop and mobile applications in .NET
BornToBeRoot/NETworkManager
A powerful tool for managing networks and troubleshoot network problems!
dotnet/MobileBlazorBindings
Experimental Mobile Blazor Bindings - Build native and hybrid mobile apps with Blazor

Webview Uwp Events

Version History

VersionDownloadsLast updated
1.0.824-prerelease 4,782 3/15/2021
1.0.818.41 169 4/21/2021
1.0.790-prerelease 5,000 2/10/2021
1.0.774.44 17,533 3/8/2021
1.0.721-prerelease 10,075 12/8/2020
1.0.705.50 22,122 1/25/2021
1.0.674-prerelease 19,104 10/19/2020
1.0.664.37 32,813 11/20/2020
1.0.622.22 9,769 10/19/2020
0.9.622.11 6,047 9/10/2020
0.9.579 8,571 7/20/2020
0.9.579-prerelease 8,709 7/20/2020
0.9.538 8,442 6/8/2020
0.9.538-prerelease 9,497 6/8/2020
0.9.515-prerelease 4,983 5/14/2020
0.9.488 5,906 4/20/2020
0.9.488-prerelease 1,155 4/20/2020

Microsoft Edge Webview2 Download

Show more