cefsharp / cefsharp/CefSharp.OutOfProcess

RequestHandler to set Proxy Auth not working

Aberta
#29 3 comentários 0 reações 0 responsáveis Ver no GitHub
Linguagem predominante
C#
Estrelas
13
Forks
5
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

for the classes:
```
public class CustomRequestContext : RequestContextHandler
{

public WebProxy CurrentProxy { get; set; }
public bool blockWebRTC { get; set; } = true;
public CustomRequestContext(bool blockRTC) : base()
{
blockWebRTC = blockRTC;


}
protected override async void OnRequestContextInitialized(IRequestContext requestContext)
{
requestContext.SetPreference("credentials_enable_service", true, out _);
if (CurrentProxy != null)
{
requestContext.SetPreference("webrtc.multiple_routes_enabled", false, out _);
requestContext.SetPreference("webrtc.nonproxied_udp_enabled", false, out _);
if (blockWebRTC)
requestContext.SetPreference("webrtc.ip_handling_policy", "disable_non_proxied_udp", out _);

requestContext.SetProxy(CurrentProxy.Address.Scheme, CurrentProxy.Address.Host, CurrentProxy.Address.Port, out string error);
requestContext.SetPreference("intl.accept_languages", "en-US,en;q=0.9,en", out string error2);
}
}

protected override IResourceRequestHandler GetResourceRequestHandler(IBrowser browser, IFrame frame, IRequest request, bool isNavigation, bool isDownload, string requestInitiator, ref bool disableDefaultHandling)
{
return base.GetResourceRequestHandler(browser, frame, request, isNavigation, isDownload, requestInitiator, ref disableDefaultHandling);
}

}

public class ProxyAuthRequestHandler : CefSharp.Handler.RequestHandler
{
public NetworkCredential Credentials { get; set; }
protected override bool GetAuthCredentials(IWebBrowser chromiumWebBrowser, IBrowser browser, string originUrl, bool isProxy, string host, int port, string realm, string scheme, IAuthCallback callback)
{
File.WriteAllText(@$"D:\html\{DateTime.Now.Ticks}.json", $@"{new { originUrl , isProxy , host , port, realm , scheme }}");

if (Credentials != null && isProxy == true)
{
callback.Continue(Credentials.UserName, Credentials.Password);
return true;
}
return false;
}
}
```

and calling in file ` BrowserProcessHandler.cs.cs` in the method `CreateBrowser`

```
Task IOutOfProcessClientRpc.CreateBrowser(IntPtr parentHwnd, string url, int id)
{
//Debugger.Break();

return CefThread.ExecuteOnUiThread(() =>
{
var requestContextSettings = new RequestContext(new CustomRequestContext( false) { CurrentProxy = this.Proxy });
var browser = new OutOfProcessChromiumWebBrowser(_outOfProcessServer, id, url, requestContextSettings);
browser.RequestHandler = new ProxyAuthRequestHandler() { Credentials = (NetworkCredential)Proxy.Credentials };
var windowInfo = new WindowInfo();
windowInfo.WindowName = "BrowserProcess";
windowInfo.SetAsChild(parentHwnd);
//Disable Window activation by default
//https://bitbucket.org/chromiumembedded/cef/issues/1856/branch-2526-cef-activates-browser-window
windowInfo.ExStyle |= OutOfProcessChromiumWebBrowser.WS_EX_NOACTIVATE;
browser.CreateBrowser(windowInfo);
_browsers.TryAdd(id, browser);

return true;
});
}

```
CustomRequestContext is set and the proxy is done but it promps as is show in the image for a proxy credentials the GetAuthCredentials method is never called. on non auth proxies it works all fine cause CustomRequestContext sets correctly the proxy.
Image

probably I'm missing something on my understanding of the project but I'm unable to make the Request Handler to work.

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Direção de pesquisa

Inspecione CreateBrowser em BrowserProcessHandler.cs.cs junto com CustomRequestContext e ProxyAuthRequestHandler para rastrear como o RequestHandler do navegador e o proxy são anexados. Reproduza com um proxy autenticado, confirme se GetAuthCredentials é invocado e verifique se o prompt do proxy é substituído pelas credenciais fornecidas.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
csharp
Domínio
desktop
Tipo de issue
Bug
Dificuldade
4/5
Tempo estimado
3-5 dias
Status de atividade
Estagnada
Clareza
Razoavelmente clara
Facilidade para iniciantes
38/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.