Replies: 4 comments 4 replies
-
also i am trying to filter traffic as if i were on browser but i can't. |
Beta Was this translation helpful? Give feedback.
-
You can browse/search the DevTools API using https://chromedevtools.github.io/devtools-protocol/tot/Network/ I believe request/response are event based. There's currently no strongly typed wrapper for the events. You can parse the raw JSON yourself. http://cefsharp.github.io/api/91.1.x/html/M_CefSharp_Callback_IDevToolsMessageObserver_OnDevToolsEvent.htm |
Beta Was this translation helpful? Give feedback.
-
Here is a small example for logging requests / responses via the DevTools events based on the work in #3669. using (var browser = new ChromiumWebBrowser("about:blank", automaticallyCreateBrowser: false))
{
await browser.CreateBrowserAsync();
using (var devToolsClient = browser.GetDevToolsClient())
{
await devToolsClient.Network.EnableAsync(); // enable network events
devToolsClient.Network.RequestWillBeSent += (sender, args) =>
{
Console.WriteLine("--- RequestWillBeSent ---");
Console.WriteLine("Request: " + args.RequestId);
Console.WriteLine(args.Request.Method + " " + args.Request.Url + args.Request.UrlFragment);
foreach (var header in args.Request.Headers)
{
Console.WriteLine("Request Header: " + header.Key + " = " + header.Value);
}
Console.WriteLine("--------------------------------");
};
devToolsClient.Network.RequestWillBeSentExtraInfo += (sender, args) =>
{
Console.WriteLine("--- RequestWillBeSentExtraInfo ---");
Console.WriteLine("Request: " + args.RequestId);
foreach (var header in args.Headers)
{
Console.WriteLine("Request Header: " + header.Key + " = " + header.Value);
}
Console.WriteLine("--------------------------------");
};
devToolsClient.Network.ResponseReceived += (sender, args) =>
{
Console.WriteLine("--- ResponseReceived ---");
Console.WriteLine("Request: " + args.RequestId);
if (args.Response.RequestHeaders != null)
{
foreach (var header in args.Response.RequestHeaders)
{
Console.WriteLine("Request Header: " + header.Key + " = " + header.Value);
}
}
Console.WriteLine("Response: " + args.Response.Url + " " + args.Response.Status + " " + args.Response.StatusText);
Console.WriteLine("Connection: " + args.Response.RemoteIPAddress + ":" + args.Response.RemotePort);
foreach (var header in args.Response.Headers)
{
Console.WriteLine("Response Header: " + header.Key + " = " + header.Value);
}
Console.WriteLine("--------------------------------");
};
devToolsClient.Network.ResponseReceivedExtraInfo += (sender, args) =>
{
Console.WriteLine("--- ResponseReceivedExtraInfo ---");
Console.WriteLine("Request: " + args.RequestId);
foreach (var header in args.Headers)
{
Console.WriteLine("Response Header: " + header.Key + " = " + header.Value);
}
Console.WriteLine("--------------------------------");
};
await browser.LoadUrlAsync("www.google.com");
}
} This just logs a few fields, there is a lot more data especially in the responses like timings. You can use I haven't figured out how request interception works with the DevTools yet. A lot of the types / events are currently experimental or already deprecated. |
Beta Was this translation helpful? Give feedback.
-
RequestWillBeSent undefine |
Beta Was this translation helpful? Give feedback.
-
I'm try to get request / response from devtoolclient
using (var devToolsClient = _browser.GetDevToolsClient())
devToolsClient.Network [...]
But i didnt find anything to collect http request/response from browser, i checked also here http://cefsharp.github.io/api/91.1.x/html/N_CefSharp_DevTools_Network.htm no clue
Can you provide a small example? thanks.
Beta Was this translation helpful? Give feedback.
All reactions