Webview2 change proxy settings multiple times like a rotating proxy

Taner-5171 20 Reputation points
2023-03-11T12:41:51.0233333+00:00

Hi,

I can make the proxy settings of Webview2 at the first initialize but I need to change them multiple time during runtime, when I try to do it again I get this error

System.ArgumentException: 'WebView2 was already initialized with a different CoreWebView2Environment. Check to see if the Source property was already set or EnsureCoreWebView2Async was previously called with different values.'

How can I do that? My code is:

        Dim options As CoreWebView2EnvironmentOptions = New CoreWebView2EnvironmentOptions With {.Language = "en-GB"}
        options.AdditionalBrowserArguments = "--proxy-server=geo.xxxxx.com:12345"
        Dim webView2Environment As CoreWebView2Environment = Nothing
        webView2Environment = Await CoreWebView2Environment.CreateAsync(Nothing, Nothing, options)
        Await WebView21.EnsureCoreWebView2Async(webView2Environment)
Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,826 questions
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,367 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,569 questions
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 26,426 Reputation points Microsoft Vendor
    2023-03-13T03:01:21.56+00:00

    Hi, welcome to Microsoft Q&A.

    After initialization, CoreWebView2EnvironmentOptions cannot be modified.

    It is recommended that you create a new instance of WebView2 to use the new CoreWebView2EnvironmentOptions.

    Best Regards.
    Jiachen Li
    ----------
    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Geeth Cooray 0 Reputation points
    2023-03-13T01:37:46.6533333+00:00

    Good work and enjoy your time

    0 comments No comments