Home > Back-end >  Should I reuse a single WebView2 environment for multiple webview instances?
Should I reuse a single WebView2 environment for multiple webview instances?

Time:08-03

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.

CodePudding user response:

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.

  • Related