Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The CoreWebView2Environment, CoreWebView2Controller, and CoreWebView2 classes (or equivalent interfaces) work together so your app can host a WebView2 browser control and access its browser features. These three large classes expose a wide range of APIs that your host app can access to provide many categories of browser-related features for your users.
The
CoreWebView2Environmentclass represents a group of WebView2 controls that share the same WebView2 browser process, user data folder, and renderer. From thisCoreWebView2Environmentclass, you create pairs ofCoreWebView2ControllerandCoreWebView2instances.The
CoreWebView2Controllerclass is responsible for hosting-related functionality such as window focus, visibility, size, and input, where your app hosts the WebView2 control.The
CoreWebView2class is for the web-specific parts of the WebView2 control, including networking, navigation, script, and parsing and rendering HTML.
Cross-platform API implementation
Most of the WebView2 APIs are initially developed for C++, and then most of the C++ APIs are wrapped as C# APIs. This way, there is a consistent parallelism and equivalence across platforms and programming languages.
Overview of the top-level classes
Overview of:
CoreWebView2EnvironmentCoreWebView2CoreWebView2Controllervs.WebView2classes (UI framework-specific WebView2 element class like the WPF, WinForms, or WinUIWebView2classes).
or, equivalently:
ICoreWebView2EnvironmentICoreWebView2ICoreWebView2Controller
CoreWebView2Environment represents a group of WebView2 controls that all share the following:
- They share the same WebView2 browser process.
- They share the same user data folder.
- They potentially share WebView2 renderer and other WebView2 processes.
From the CoreWebView2Environment, you create CoreWebView2Controller and CoreWebView2 pairs. They always come together as a CoreWebView2Controller and a corresponding CoreWebView2.
- The
CoreWebView2Controlleris responsible for all hosting-related functionality such as focus, visibility, size, and input. - The
CoreWebView2is for the web-specific parts of the WebView2 control, including networking, navigation, script, and parsing and rendering HTML.
UI framework-specific WebView2 element class such as WPF, WinForms, or WinUI WebView2 classes
It's different if you are using a UI framework-specific WebView2 element class such as the WPF, WinForms, or WinUI WebView2 classes.
Then, the WebView2 class can optionally take a CoreWebView2Environment to use; otherwise, it creates a default CoreWebView2Environment. Internally, the WebView2 class creates its CoreWebView2Controller and CoreWebView2 from the CoreWebView2Environment.
The WebView2 exposes its CoreWebView2 as a CoreWebView2 property, but the CoreWebView2Controller is kept private to the WebView2 class. This is because the WebView2 class is responsible for connecting all of the CoreWebView2Controller functionality to the UI framework.