Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C# unable to enable performance logging for ChromeDriver #7335

Closed
JL1234567 opened this issue Jun 27, 2019 · 25 comments
Closed

C# unable to enable performance logging for ChromeDriver #7335

JL1234567 opened this issue Jun 27, 2019 · 25 comments

Comments

@JL1234567
Copy link

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. 
@SlavikCA
Copy link

SlavikCA commented Jun 28, 2019

related to #7342 CapabilityType.LOGGING_PREFS is not valid for latest versions of Chrome (75+)

@MatthewSteeples
Copy link

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");

@JL1234567
Copy link
Author

@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");

@MatthewSteeples
Copy link

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

@joelransom
Copy link

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.

@lmtierney
Copy link
Member

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.

@lmtierney
Copy link
Member

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

@alex-jitbit
Copy link

4.0.0-alpha02 still does not work because #7390

@lmtierney
Copy link
Member

It should work with chrome 76

@kjknepp
Copy link

kjknepp commented Aug 1, 2019

@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

@kjknepp
Copy link

kjknepp commented Aug 1, 2019

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

@lmtierney
Copy link
Member

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)

@kjknepp
Copy link

kjknepp commented Aug 1, 2019

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

@alex-jitbit
Copy link

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

@szamacz
Copy link

szamacz commented Sep 25, 2019

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

@MatthewSteeples
Copy link

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

@SKumar-777
Copy link

SKumar-777 commented Feb 7, 2020

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.

@GitSuC
Copy link

GitSuC commented Feb 10, 2020

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?

@GitSuC
Copy link

GitSuC commented Feb 22, 2020

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?

@GitSuC
Copy link

GitSuC commented Mar 5, 2020

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.

@stream1990
Copy link

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

@GrantTem
Copy link

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')

@stream1990
Copy link

stream1990 commented Apr 12, 2020

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

@yahya99223
Copy link

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

@SeleniumHQ SeleniumHQ locked as resolved and limited conversation to collaborators Dec 14, 2020
@diemol
Copy link
Member

diemol commented Feb 10, 2022

Closing this as several comments show that it works with recent versions of Selenium.

@diemol diemol closed this as completed Feb 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

16 participants