Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I reuse a single WebView2 environment for multiple webview instances?

I have implemented a WebView2 component in our software, using C++/Win32. There can be multiple of these webviews. Should I create a new WebView2 environment for each one, or reuse it?

Currently I'm making a new environment for each view (using CreateCoreWebView2EnvironmentWithOptions). It "seems" fine, but I wondered if it wastes resources e.g extra browser processes. I couldn't find any guidance in the help.

Edit to clarify: the data folder for all of the webviews will be the same.

like image 268
O'Rooney Avatar asked Dec 14 '25 22:12

O'Rooney


1 Answers

If you create multiple CoreWebView2Environment objects with the same parameters, they are all connected to the same user data folder, browser process, and other associated renderer and utility processes. You can create webview2s from any of those CoreWebView2Environment objects to get the same result. If you have a CoreWebView2Environment with different parameters (a different user data folder specifically) it will be connected to the different user data folder, a different browser process, and different other associated renderer and utility processes.

You can read more about the WebView2 process model.

like image 106
David Risney Avatar answered Dec 16 '25 21:12

David Risney



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!