I would like to intercept the error messages from network Fetch/XHR
. Which method should I take or how can I make a connection and intercept this information? I know this is necessary code base:
driver = new ChromeDriver();
driver.Manage().Window.Maximize();
devTools = driver as IDevTools;
session = devTools.GetDevToolsSession();
devToolsSession = session.GetVersionSpecificDomains<DevToolsSessionDomains>();
devToolsSession.Network.Enable(new Network.EnableCommandSettings());
I tried to create an EventHandler but unfortunately, this requestID
of event doesn't match with requestID
of the DevTools parameter. How should I get requestID
and what method do I need to intercept errors which appear on the preview page of the Network
All errors should log to console domain. Maybe you looking for this
devToolsSession.Domains.JavaScript.ConsoleApiCalled += (sender, e) =>
{
Console.WriteLine("Log: {0} {1}", e.Timestamp, e.Type);
e.Arguments.ToList().ForEach(x => Console.WriteLine($"Type: {x.Type},
Value: {x.Value}"));
};
or intercept the traffic(not tested)
List<long> httpStatuses = new List<long>() { 500, 501, 502, 503, 504 };
_driver.GetDevToolsSession().Domains.Network.ResponsePaused += (o, args) =>
{
if (httpStatuses.Contains(args.ResponseData.StatusCode))
//log something...
};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.