Selenium: C# unable to enable performance logging for ChromeDriver

Created on 27 Jun 2019  Â·  24Comments  Â·  Source: SeleniumHQ/selenium

Chrome:Version 75.0.3770.100
ChromeDriver:75.0.3770.90
Selenium:3.141.0

I'm getting the error ```
OpenQA.Selenium.WebDriverException: 'invalid argument: entry 0 of 'firstMatch' is invalid
from invalid argument: perfLoggingPrefs specified, but performance logging was not enabled'

If the work around is to use LoggingPreference, can someone please tell me how to reference it since it does not seem to be in the 3.141.0 dll. Also, I think this might relate to the changes to 75.0.3770.8 Renamed capability loggingPrefs to goog:loggingPrefs, as required by W3C standard

public Driver(ChromeDriverModel chromeDriverModel)
        {
            ChromeOptions chromeOptions = new ChromeOptions();
            enablePerformanceMonitor = chromeDriverModel.enablePerformanceMonitoring;
            if (enablePerformanceMonitor)
                chromeOptions = _ChromePerformanceOptions();

            if (!string.IsNullOrWhiteSpace(chromeDriverModel.ChromeDriverLocation))
            {
                if (enablePerformanceMonitor)
                    _webDriver = new ChromeDriver(chromeDriverModel.ChromeDriverLocation, chromeOptions);
                else
                    _webDriver = new ChromeDriver(chromeDriverModel.ChromeDriverLocation);
            }
            else
            {
                if (enablePerformanceMonitor)
                    _webDriver = new ChromeDriver(chromeOptions);
                else
                    _webDriver = new ChromeDriver();
            }
        }


private ChromeOptions _ChromePerformanceOptions()
        {
            var option = new ChromeOptions();
            var perfLogPrefs = new ChromePerformanceLoggingPreferences();
            perfLogPrefs.AddTracingCategories(new string[] { "devtools.network", "devtools.timeline" });
            option.PerformanceLoggingPreferences = perfLogPrefs;
            option.AddAdditionalCapability(CapabilityType.EnableProfiling, true, true);
            option.SetLoggingPreference("performance", LogLevel.All);
            return option;
        }

```

Sorry if repost, not sure which is the official spot.

C-dotnet D-chrome

Most helpful comment

JFYI upgrading to Chrome-76/Chromedriver-76 did not help. See the issue referenced #7390

All 24 comments

related to https://github.com/SeleniumHQ/selenium/issues/7342 CapabilityType.LOGGING_PREFS is not valid for latest versions of Chrome (75+)

Potential workaround code for C# (until the library is fixed). This will update the value of the preference string as long as it's run before you make use of the options

typeof(CapabilityType).GetField(nameof(CapabilityType.LoggingPreferences), BindingFlags.Static | BindingFlags.Public).SetValue(null, "goog:loggingPrefs");

@MatthewSteeples Thanks Matt! That did allow the browser to start. What i'm not sure of now is if that fix is breaking the logs. Up top in my ChromePerformanceOptions object you can see I'm setting my log pref like so option.SetLoggingPreference("performance", LogLevel.All);. However, when I go to grab the logs it's telling me this object is null var logs = _driver._webDriver.Manage().Logs.GetLog("performance");

We're getting the same when trying to retrieve browser logs so it would appear that this isn't a full fix yet. We'll be trying some more things tomorrow, but it may be a case of waiting for 4.0 alpha 2 to hit NuGet

Trying to follow the conversations around this. I just hit this when my chrome updated to version 76. Are there no workarounds for accessing chrome logs?
Thanks.

With version 76, Chromedriver Issue 2947 was resolved changing the endpoint to /session/:sessionId/se/log (see change).

The selenium bindings will be updated accordingly, but you'll need to patch them yourself if you need them now; or use chromedriver 75.

Scratch that, I believe this should be hitting the correct endpoints for logs in 4.0.0-alpha02

4.0.0-alpha02 still does not work because #7390

It should work with chrome 76

@lmtierney
I've also been having this issue with chrome 76 and ChromeDriver 76.
I'm not up to date on all of the bugs and things but it is for sure not working with chrome 76

Sorry, re-read things a second time, were you saying to use the following?

Selenium.WebDriver: 4.0.0-alpha02
Chrome: 76.XXX
ChromeDriver: 76.XXX

because I just checked my selenium version and I'm using 3.141.0

Yes, in order for this all to work, you need 4.0.0-alpha02, Chrome/Chromedriver 76 (or I believe a very late version of 75 had it enabled)

Is there some kind of tutorial for installing the pre-release? I attempted to install the version from nuget using the package manager console command:

Install-Package Selenium.WebDriver -Version 4.0.0-alpha02

But when I looked at the metadata I had version 0.0.0.0

JFYI upgrading to Chrome-76/Chromedriver-76 did not help. See the issue referenced #7390

Referenced issue #7390 was closed but issue seems to be still not fixed. Any update on this?

The issue has been resolved but the fix is not (yet) available on NuGet so you'll need to roll your own if you need it before the next release is out

Hi Guys,

I have tried to collect the chrome performance log using latest Selenium 4.0-alpha04 (https://www.nuget.org/packages/Selenium.WebDriver/4.0.0-alpha04) with chrome driver v79. Also renamed the capability loggingPrefs to goog:loggingPrefs, as required by W3C standard. The below C# code samples are not working and throw the error;

Code:

ChromeOptions options = new ChromeOptions();
//options.SetLoggingPreference(LogType.Performance, LogLevel.All);//LogType.Performance - Not available
options.SetLoggingPreference("goog:loggingPrefs", LogLevel.All);
var entries = driver.Manage().Logs.GetLog("performance");//Get log

Error:

OpenQA.Selenium.WebDriverArgumentException: invalid argument: log type 'performance' not found
(Session info: chrome=79.0.3945.130)
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)

Is that latest fix to enable chrome performance log is available in latest NuGet release? Any update on this?
Help us to resolve this issue.

Thanks.

Hi All,

I tried using following code with latest version of Chrome driver (80.0.3987.1699 ) and Selenium Webdriver (4.0-alpha04) but not able to retrieve the performance logs.

var perfLogPrefs = new ChromePerformanceLoggingPreferences();
perfLogPrefs.IsCollectingNetworkEvents = true;
perfLogPrefs.IsCollectingPageEvents = true;
perfLogPrefs.AddTracingCategories(new string[] { "devtools.network", "devtools.timeline" });
options.PerformanceLoggingPreferences = perfLogPrefs;
options.AddAdditionalCapability(CapabilityType.EnableProfiling, true, true);
options.SetLoggingPreference("goog:LoggingPrefs", LogLevel.All);
(or)
options.SetLoggingPreference("performance", LogLevel.All);

var logs = driver.Manage().Logs.GetLog("performance");

May I know if we have any fix for this please until we get latest version rolled out like registry settings (I know this is not a good idea) changes or so?

As a follow up, may I know if anyone can help me here pointing to an answer if it is already answered in any of the forums.

@MatthewSteeples , may I know what are the changes that we need to make if the solution is not rolled out in nuget packages pls?

Hi All,

With Selenium WebDriver (v4.0.0-alpha04) and Selenium.Chrome.WebDriver (v79.0.0) and using the following code, I am able to retrieve the Chrome performance logs.

ChromeOptions options = new ChromeOptions();

//Following helps in setting the logging preference
options.SetLoggingPreference("performance", LogLevel.All);

//Based on your need you can change the following options
options.AddUserProfilePreference("intl.accept_languages", "en-US");
options.AddUserProfilePreference("disable-popup-blocking", "true");
options.AddArgument("test-type");
options.AddArgument("--disable-gpu");
options.AddArgument("no-sandbox");
options.AddArgument("start-maximized");
options.LeaveBrowserRunning = true;

//Creating Chrome driver instance
IWebDriver driver = new ChromeDriver(options);

//Extracting the performance logs
var logs = driver.Manage().Logs.GetLog("performance");
for (int i = 0; i < logs.Count; i++)
{
Console.WriteLine(logs[i].Message);
}

Hope this helps.

Hi All,

With Selenium WebDriver (v4.0.0-alpha04) and Selenium.Chrome.WebDriver (v79.0.0) and using the following code, I am able to retrieve the Chrome performance logs.

ChromeOptions options = new ChromeOptions();

//Following helps in setting the logging preference
options.SetLoggingPreference("performance", LogLevel.All);

//Based on your need you can change the following options
options.AddUserProfilePreference("intl.accept_languages", "en-US");
options.AddUserProfilePreference("disable-popup-blocking", "true");
options.AddArgument("test-type");
options.AddArgument("--disable-gpu");
options.AddArgument("no-sandbox");
options.AddArgument("start-maximized");
options.LeaveBrowserRunning = true;

//Creating Chrome driver instance
IWebDriver driver = new ChromeDriver(options);

//Extracting the performance logs
var logs = driver.Manage().Logs.GetLog("performance");
for (int i = 0; i < logs.Count; i++)
{
Console.WriteLine(logs[i].Message);
}

Hope this helps.

未将对象引用设置到对象的实例。
the logs is null

ChromeDriver 81.0.4044.69

so
how can i get the response header?

thankyou

Hi All,
With Selenium WebDriver (v4.0.0-alpha04) and Selenium.Chrome.WebDriver (v79.0.0) and using the following code, I am able to retrieve the Chrome performance logs.
ChromeOptions options = new ChromeOptions();
//Following helps in setting the logging preference
options.SetLoggingPreference("performance", LogLevel.All);
//Based on your need you can change the following options
options.AddUserProfilePreference("intl.accept_languages", "en-US");
options.AddUserProfilePreference("disable-popup-blocking", "true");
options.AddArgument("test-type");
options.AddArgument("--disable-gpu");
options.AddArgument("no-sandbox");
options.AddArgument("start-maximized");
options.LeaveBrowserRunning = true;
//Creating Chrome driver instance
IWebDriver driver = new ChromeDriver(options);
//Extracting the performance logs
var logs = driver.Manage().Logs.GetLog("performance");
for (int i = 0; i < logs.Count; i++)
{
Console.WriteLine(logs[i].Message);
}
Hope this helps.

未将对象引用设置到对象的实例。
the logs is null

ChromeDriver 81.0.4044.69

so
how can i get the response header?

thankyou

I suggest you check the webdriver version (4.0.0-alpha05), you can find it in NuGet (checked 'Include prerelease')

Hi All,
With Selenium WebDriver (v4.0.0-alpha04) and Selenium.Chrome.WebDriver (v79.0.0) and using the following code, I am able to retrieve the Chrome performance logs.
ChromeOptions options = new ChromeOptions();
//Following helps in setting the logging preference
options.SetLoggingPreference("performance", LogLevel.All);
//Based on your need you can change the following options
options.AddUserProfilePreference("intl.accept_languages", "en-US");
options.AddUserProfilePreference("disable-popup-blocking", "true");
options.AddArgument("test-type");
options.AddArgument("--disable-gpu");
options.AddArgument("no-sandbox");
options.AddArgument("start-maximized");
options.LeaveBrowserRunning = true;
//Creating Chrome driver instance
IWebDriver driver = new ChromeDriver(options);
//Extracting the performance logs
var logs = driver.Manage().Logs.GetLog("performance");
for (int i = 0; i < logs.Count; i++)
{
Console.WriteLine(logs[i].Message);
}
Hope this helps.

未将对象引用设置到对象的实例。
the logs is null
ChromeDriver 81.0.4044.69
so
how can i get the response header?
thankyou

I suggest you check the webdriver version (4.0.0-alpha05), you can find it in NuGet (checked 'Include prerelease')

good job!


thank you for you reply

Upgrading to beta version for driver worked for me, thanks @stream1990

Was this page helpful?
0 / 5 - 0 ratings