Chrome DevTools Logging Features
Logging features using CDP.
Page being translated from English to Japanese. Do you speak Japanese? Help us to translate it by sending us pull requests!
While Selenium 4 provides direct access to the Chrome DevTools Protocol, these methods will eventually be removed when WebDriver BiDi implemented.
Console Logs
((HasLogEvents) driver).onLogEvent(consoleEvent(e -> messages.add(e.getMessages().get(0))));
async with driver.bidi_connection() as session:
async with Log(driver, session).add_listener(Console.ALL) as messages:
using IJavaScriptEngine monitor = new JavaScriptEngine(driver);
var messages = new List<string>();
monitor.JavaScriptConsoleApiCalled += (_, e) =>
{
messages.Add(e.MessageContent);
};
await monitor.StartEventMonitoring();
driver.on_log_event(:console) { |log| logs << log.args.first }
JavaScript Exceptions
async with driver.bidi_connection() as session:
async with Log(driver, session).add_js_error_listener() as messages:
using IJavaScriptEngine monitor = new JavaScriptEngine(driver);
var messages = new List<string>();
monitor.JavaScriptExceptionThrown += (_, e) =>
{
messages.Add(e.Message);
};
await monitor.StartEventMonitoring();
driver.on_log_event(:exception) { |exception| exceptions << exception }