Background - trying to get ChromeDriver to log so that I can start using Lighthouse.
I'm trying to get a C# Selenium.Webdriver equivalent of this
DesiredCapabilities cap = DesiredCapabilities.chrome();
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.PERFORMANCE, Level.ALL);
cap.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
Map<String, Object> perfLogPrefs = new HashMap<String, Object>();
perfLogPrefs.put("traceCategories", "browser,devtools.timeline,devtools"); // comma-separated trace categories
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("perfLoggingPrefs", perfLogPrefs);
caps.setCapability(ChromeOptions.CAPABILITY, options);
RemoteWebDriver driver = new RemoteWebDriver(new URL("http://127.0.0.1:9515"), cap);
I can't figure out the right combination. Anyone know what the correct recipe is, or have an example, or both?
My attempt
var chromeOptions = new Dictionary<string, object>();
List<string> args = new List<string>();
foreach (string ma in myArgs) //yes, myArgs is created beforehand
args.Add(ma);
chromeOptions.Add("args", args);
var options = new Dictionary<string, object>();
var loggingPrefs = new Dictionary<string, object>();
loggingPrefs.Add("PERFORMANCE", "ALL" );
var perfLoggingPrefs = new Dictionary<string, object>();
perfLoggingPrefs.Add("enableNetwork", true);
perfLoggingPrefs.Add("enablePage", true);
perfLoggingPrefs.Add("traceCategories", "toplevel,disabled-by-default-devtools.timeline.frame,blink.console,disabled-by-default-devtools.timeline,benchmark");
options.Add("chromeOptions", chromeOptions);
options.Add("loggingPrefs", loggingPrefs);
options.Add("perfLoggingPrefs", perfLoggingPrefs);
var capabilities = new DesiredCapabilities(options);
Driver = new RemoteWebDriver(new Uri("http://localhost:9515"), capabilities);
Result: No logging
Not sure what is wrong with your example, but this worked for me:
This is how you get the logs afterwards:
There was a bug in selenium that was fixed in version 3.14 that wouldn't allow this to work. If you're getting a "unrecognized performance logging option: enableTimeline" error try updating selenium.
This worked on my end for local
and for remote
to get the logs