cefsharp / cefsharp/CefSharp.OutOfProcess

RequestHandler to set Proxy Auth not working

オープン
#29 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
C#
スター
13
フォーク
5
PR マージ指標
30日以内にマージされた PR はありません

説明

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.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

BrowserProcessHandler.cs.cs の CreateBrowser を CustomRequestContext および ProxyAuthRequestHandler と併せて調査し、ブラウザーの RequestHandler とプロキシがどのようにアタッチされているかを追跡してください。認証済みプロキシで再現し、GetAuthCredentials が呼び出されるかを確認し、プロキシのプロンプトが指定された認証情報に置き換えられることを検証してください。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
csharp
領域
desktop
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
38/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。