cefsharp / cefsharp/CefSharp.OutOfProcess

RequestHandler to set Proxy Auth not working

Đang mở
#29 3 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
C#
Star
13
Fork
5
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Hướng nghiên cứu

Kiểm tra CreateBrowser trong BrowserProcessHandler.cs.cs cùng với CustomRequestContext và ProxyAuthRequestHandler để theo dõi cách RequestHandler của trình duyệt và proxy được gắn vào. Tái hiện với một proxy đã xác thực, xác nhận xem GetAuthCredentials có được gọi hay không và xác minh rằng lời nhắc proxy được thay thế bằng thông tin xác thực được cung cấp.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
csharp
Lĩnh vực
desktop
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
38/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.