我正在尝试使用 Selenium 4 在手动使用 Chrome 浏览器期间记录请求。
问题是请求拦截在使用大约 40 秒后停止(大约)。
我试图改变 commandTimeout 但它没有改变任何东西。我也尝试查看 chromedriver 日志,但我没有在那里找到任何东西。
这是我的代码:
static void Main(string[] args)
{
// Enable chromedriver logging
var service = ChromeDriverService.CreateDefaultService();
service.LogPath = AppDomain.CurrentDomain.BaseDirectory + "chromedriver.log";
service.EnableVerboseLogging = true;
var options = new ChromeOptions();
var webDriver = new ChromeDriver(service, options);
var devToolsSession = webDriver.CreateDevToolsSession();
devToolsSession.Network.Enable(new EnableCommandSettings());
EventHandler<RequestInterceptedEventArgs> requestIntercepted = (sender, e) =>
{
Console.WriteLine(e.Request.Url);
};
RequestPattern requestPattern = new RequestPattern();
requestPattern.InterceptionStage = InterceptionStage.Request;
requestPattern.ResourceType = ResourceType.Image;
var setRequestInterceptionCommandSettings = new SetRequestInterceptionCommandSettings();
setRequestInterceptionCommandSettings.Patterns = new RequestPattern[] { requestPattern };
devToolsSession.Network.SetRequestInterception(setRequestInterceptionCommandSettings);
devToolsSession.Network.RequestIntercepted += requestIntercepted;
while (true)
{
webDriver.Url = "https://translate.google.com/";
Thread.Sleep(5000);
webDriver.Navigate().Refresh();
}
}