I'm creating a custom internet browser using winforms and webview2 and whenever I search for something when using say a school internet it has a proxy box asks for my username and password. How can I autofill this box every time it opens
Asked
Active
Viewed 2,964 times
0
-
Ideally you should be able to the proxy in options, but it doesn't seem to have been fixed yet: https://github.com/MicrosoftEdge/WebView2Feedback/issues/193#issuecomment-663046277 – Poul Bak Feb 18 '21 at 17:19
-
Is the dialog that pops up a javascript dialog? – Poul Bak Feb 18 '21 at 17:19
-
not completely sure if its Javascript, It only pops up if I 1. Haven't connected to that internet today. or 2. I reconnected to it. – Redstone145 Feb 19 '21 at 06:04
2 Answers
0
There are command-line options for proxy settings. You can set those options through AdditionalBrowserArguments property of an instance of CoreWebView2EnvironmentOptions and pass to CoreWebView2Environment.CreateAsync when creating the CoreWebView2.
For example:
WebView2 webView21 = new Microsoft.Web.WebView2.WinForms.WebView2();
private async void Form1_Load(object sender, EventArgs e)
{
var options = new CoreWebView2EnvironmentOptions();
options.AdditionalBrowserArguments = "--proxy-server=\"proxyhostname:8000\"";
var env = await CoreWebView2Environment.CreateAsync(null, null, options);
await webView21.EnsureCoreWebView2Async(env);
webView21.Dock = DockStyle.Fill;
this.Controls.Add(webView21);
webView21.Source = new Uri("Https://stackoverflow.com");
}
Here are the options that you can use:
--no-proxy-server
: Not to use proxy.--proxy-auto-detect
: Automatically detect proxy configuration.--proxy-server=<scheme>=<uri>[:<port>][;...] | <uri>[:<port>] | "direct://"
: Use custom configurations.--proxy-bypass-list=(<trailing_domain>|<ip-address>)[:<port>][;...]
: Bypass any specified proxy for the specified semicolon-separated list of hosts.--proxy-pac-url=<pac-file-url>
: To use the PAC file at the specified URL.
To see more description and example about those options see:

Reza Aghaei
- 120,393
- 18
- 203
- 398
-
-
I guess the username/password box which is being asked in the OP's question is a basic authentication/authentication challenge window, or may be a HTML login page. OP needs to provide more details/MCVE (if possible) for the question. – Reza Aghaei Feb 18 '21 at 19:08
0
WebView2 webView21 = new Microsoft.Web.WebView2.WinForms.WebView2();
var options = new CoreWebView2EnvironmentOptions();
options.AdditionalBrowserArguments = "--proxy-server=\"" + proxy.Address.Host + ":" + proxy.Address.Port + "\"";
var env = await CoreWebView2Environment.CreateAsync(null, null, options);
await webView21.EnsureCoreWebView2Async(env);
webView21.CoreWebView2.BasicAuthenticationRequested += new EventHandler<CoreWebView2BasicAuthenticationRequestedEventArgs>(delegate (object? sender, CoreWebView2BasicAuthenticationRequestedEventArgs e)
{
var _credential = proxy == null ? null : proxy?.Credentials as NetworkCredential;
if (_credential != null)
{
e.Response.UserName = _credential.UserName;
e.Response.Password = _credential.Password;
}
});

ggeorge
- 1,496
- 2
- 13
- 19