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

[🐛 Bug]: .NET - Fetch.getResponseBody error when Network monitoring enabled #10248

Closed
Dreamescaper opened this issue Jan 13, 2022 · 15 comments
Labels
C-devtools BiDi or Chrome DevTools related issues C-dotnet I-defect

Comments

@Dreamescaper
Copy link

Dreamescaper commented Jan 13, 2022

What happened?

We use Network monitoring to log requests and responses for failed tests.

            var network = _driver.Manage().Network;
            await network.StartMonitoring();
            network.NetworkRequestSent += NetworkRequestSent;
            network.NetworkResponseReceived += NetworkResponseReceived;

Unfortunately, sometimes we receive the following errors:

System.InvalidOperationException: A command response was not received: Fetch.getResponseBody

It happens it random places, and we cannot reproduce that consistently.
Even worse that it makes the whole test run crash.

How can we reproduce the issue?

Unfortunately, I don't know how to reproduce this issue consistently. Sometimes it happens, sometimes it doesn't.
I'll update this issue if I am able to find a repro case

Relevant log output

The active test run was aborted. Reason: Test host process crashed :

Unhandled exception. System.InvalidOperationException: A command response was not received: Fetch.getResponseBody
   at OpenQA.Selenium.DevTools.DevToolsSession.SendCommand(String commandName, JToken commandParameters, CancellationToken cancellationToken, Nullable`1 millisecondsTimeout, Boolean throwExceptionIfResponseNotReceived)
   at OpenQA.Selenium.DevTools.DevToolsSession.SendCommand[TCommand,TCommandResponse](TCommand command, CancellationToken cancellationToken, Nullable`1 millisecondsTimeout, Boolean throwExceptionIfResponseNotReceived)
   at OpenQA.Selenium.DevTools.V96.Fetch.FetchAdapter.GetResponseBody(GetResponseBodyCommandSettings command, CancellationToken cancellationToken, Nullable`1 millisecondsTimeout, Boolean throwExceptionIfResponseNotReceived)
   at OpenQA.Selenium.DevTools.V96.V96Network.AddResponseBody(HttpResponseData responseData)
   at OpenQA.Selenium.NetworkManager.OnResponsePaused(Object sender, ResponsePausedEventArgs e)
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__139_1(Object state)
   at System.Threading.QueueUserWorkItemCallback.<>c.<.cctor>b__6_0(QueueUserWorkItemCallback quwi)
   at System.Threading.ExecutionContext.RunForThreadPoolUnsafe[TState](ExecutionContext executionContext, Action`1 callback, TState& state)
   at System.Threading.QueueUserWorkItemCallback.Execute()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()

Operating System

Windows 10, Linux

Selenium version

.NET 4.1.0

What are the browser(s) and version(s) where you see this issue?

Chrome 97

What are the browser driver(s) and version(s) where you see this issue?

ChromeDriver 97.0.4692.7100

Are you using Selenium Grid?

No

@github-actions
Copy link

@Dreamescaper, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@Dreamescaper
Copy link
Author

Today I was able to get another similar error. This one is very rare though, I've seen it only once so far.

The active test run was aborted. Reason: Test host process crashed : Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at OpenQA.Selenium.DevTools.V96.V96Network.AddResponseBody(HttpResponseData responseData)
   at OpenQA.Selenium.NetworkManager.OnResponsePaused(Object sender, ResponsePausedEventArgs e)
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__139_1(Object state)
   at System.Threading.QueueUserWorkItemCallback.<>c.<.cctor>b__6_0(QueueUserWorkItemCallback quwi)
   at System.Threading.ExecutionContext.RunForThreadPoolUnsafe[TState](ExecutionContext executionContext, Action`1 callback, TState& state)
   at System.Threading.QueueUserWorkItemCallback.Execute()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()

@Dreamescaper Dreamescaper changed the title [🐛 Bug]: Fetch.getResponseBody error when Network monitoring enabled [🐛 Bug]: .NET - Fetch.getResponseBody error when Network monitoring enabled Jan 13, 2022
@titusfortner titusfortner added C-devtools BiDi or Chrome DevTools related issues C-dotnet and removed needs-triaging labels Jan 13, 2022
@mialeska
Copy link

mialeska commented Jan 21, 2022

Just got the same error during the execution on ADO Windows agent and Chrome 97:
https://dev.azure.com/aquality-automation/aquality-automation/_build/results?buildId=1757&view=logs&s=859b8d9a-8fd6-5a5c-6f5e-f84f1990894e&j=16f81312-b5db-5d03-2d86-5b7533053f9f

Starting ChromeDriver 97.0.4692.71 (adefa7837d02a07a604c1e6eff0b3a09422ab88d-refs/branch-heads/4692@{#1247}) on port 51623
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
The active test run was aborted. Reason: Test host process crashed : [1642789686.599][SEVERE]: Timed out receiving message from renderer: 1.000
[1642789686.605][SEVERE]: Timed out receiving message from renderer: -0.003
[1642789686.621][SEVERE]: Timed out receiving message from renderer: -0.003
Unhandled exception. System.InvalidOperationException: A command response was not received: Fetch.getResponseBody
   at OpenQA.Selenium.DevTools.DevToolsSession.SendCommand(String commandName, JToken commandParameters, CancellationToken cancellationToken, Nullable`1 millisecondsTimeout, Boolean throwExceptionIfResponseNotReceived)
   at OpenQA.Selenium.DevTools.DevToolsSession.SendCommand[TCommand,TCommandResponse](TCommand command, CancellationToken cancellationToken, Nullable`1 millisecondsTimeout, Boolean throwExceptionIfResponseNotReceived)
   at OpenQA.Selenium.DevTools.V96.Fetch.FetchAdapter.GetResponseBody(GetResponseBodyCommandSettings command, CancellationToken cancellationToken, Nullable`1 millisecondsTimeout, Boolean throwExceptionIfResponseNotReceived)
   at OpenQA.Selenium.DevTools.V96.V96Network.AddResponseBody(HttpResponseData responseData)
   at OpenQA.Selenium.NetworkManager.OnResponsePaused(Object sender, ResponsePausedEventArgs e)
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__140_1(Object state)
   at System.Threading.QueueUserWorkItemCallback.<>c.<.cctor>b__6_0(QueueUserWorkItemCallback quwi)
   at System.Threading.ExecutionContext.RunForThreadPoolUnsafe[TState](ExecutionContext executionContext, Action`1 callback, TState& state)
   at System.Threading.QueueUserWorkItemCallback.Execute()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()

@rhamblin
Copy link

rhamblin commented Feb 22, 2022

I am getting this error as well @mialeska or @Dreamescaper, were you able to resolve this?

@Dreamescaper
Copy link
Author

@rhamblin
I ended up ditching WebDriver's Network classes, and used ChromeDevTools directly:

            _devTools = ((IDevTools)_driver).GetDevToolsSession().GetVersionSpecificDomains<DevToolsSessionDomains>();

            await _devTools.Network.Enable(new EnableCommandSettings());
            _devTools.Network.RequestWillBeSent += RequestWillBeSent;
            _devTools.Network.ResponseReceived += ResponseReceived;
            _devTools.Network.LoadingFinished += LoadingFinished;

@diemol
Copy link
Member

diemol commented Aug 12, 2022

Just to check if this is still valid, is this happening also with the most recent version (4.4.0)?

@amandalangley
Copy link

amandalangley commented Oct 3, 2022

yes, it is happening for me as well on both 4.4.0 and 4.5.0

@teqow
Copy link

teqow commented Apr 6, 2023

still happening - anyone has a workaround for it?

@Intrusion
Copy link

Intrusion commented Apr 14, 2023

I can also confirm that it's still happening with the latest version

@titusfortner
Copy link
Member

The current DevTools implementation in .NET is not ideal, and we are looking for people who are interested in making it better.

@teqow
Copy link

teqow commented Apr 14, 2023

Intrusion

I have changed Selenium to Playwright and everything works well.

@michasacuer
Copy link

Have same issues, random exceptions going through:

            using IWebDriver driver = new ChromeDriver(chromeOptions);
            _manager = new NetworkManager(driver);
            _manager.NetworkResponseReceived += ResponseHandler;
            _manager.StartMonitoring();
            driver.Navigate().GoToUrl(url);

My usings:

    <PackageReference Include="Selenium.Chrome.WebDriver" Version="85.0.0" />
    <PackageReference Include="Selenium.WebDriver" Version="4.8.1" />
    <PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="111.0.5563.6400" />
    <PackageReference Include="Selenium.WebDriver.Extensions" Version="4.1.0" />

@sagihgithub
Copy link

sagihgithub commented Aug 25, 2023

Hi
I'm using selenium (c#) with proxy:

Proxy proxy = new Proxy();
string proxyAddress = "http://ip:port";
proxy.HttpProxy = proxyAddress;
proxy.SslProxy = proxyAddress;

ChromeOptions options = new ChromeOptions();
options.Proxy = proxy;

ChromeDriver driver = new ChromeDriver(options);

NetworkAuthenticationHandler handler = new NetworkAuthenticationHandler()
{
    UriMatcher = _ => true,
    Credentials = new PasswordCredentials("admin", "password")
};

INetwork networkInterceptor = driver.Manage().Network;
networkInterceptor.AddAuthenticationHandler(handler);
networkInterceptor.StartMonitoring().Wait();

driver.Navigate().GoToUrl("https://exampleurl.com");

networkInterceptor.StopMonitoring().Wait();
driver.Quit();

I'll add that I'm running this code in a loop with intervals of 30 seconds and every time the following exception is thrown after different amount of iterations:

DevTools listening on ws://127.0.0.1:50303/devtools/browser/367n89mk-ii5e-41a4-5867-8p1f56b8524l
Unhandled exception. System.InvalidOperationException: A command response was not received: Fetch.getResponseBody
   at OpenQA.Selenium.DevTools.DevToolsSession.SendCommand(String commandName, JToken commandParameters, CancellationToken cancellationToken, Nullable`1 millisecondsTimeout, Boolean throwExceptionIfResponseNotReceived)
   at OpenQA.Selenium.DevTools.DevToolsSession.SendCommand[TCommand,TCommandResponse](TCommand command, CancellationToken cancellationToken, Nullable`1 millisecondsTimeout, Boolean throwExceptionIfResponseNotReceived)
   at OpenQA.Selenium.DevTools.V114.Fetch.FetchAdapter.GetResponseBody(GetResponseBodyCommandSettings command, CancellationToken cancellationToken, Nullable`1 millisecondsTimeout, Boolean throwExceptionIfResponseNotReceived)
   at OpenQA.Selenium.DevTools.V114.V114Network.AddResponseBody(HttpResponseData responseData)
   at OpenQA.Selenium.NetworkManager.OnResponsePaused(Object sender, ResponsePausedEventArgs e)
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_1(Object state)
   at System.Threading.QueueUserWorkItemCallback.Execute()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()

This error is a showstopper (application crash).
Does anybody succeeded to find a solution to this error ?
Or alternatively, Is there any other way to use proxy with selenium (c#) without the Network classes ?
Thanks

@nvborisenko
Copy link
Member

Fixed by #12486, try the latest v4.12.2

Copy link

github-actions bot commented Dec 6, 2023

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
C-devtools BiDi or Chrome DevTools related issues C-dotnet I-defect
Projects
None yet
Development

No branches or pull requests