selenium icon indicating copy to clipboard operation
selenium copied to clipboard

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

Open Dreamescaper opened this issue 4 years ago • 6 comments

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

Dreamescaper avatar Jan 13 '22 11:01 Dreamescaper

@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!

github-actions[bot] avatar Jan 13 '22 11:01 github-actions[bot]

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 avatar Jan 13 '22 11:01 Dreamescaper

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

mialeska avatar Jan 21 '22 18:01 mialeska

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

rhamblin avatar Feb 22 '22 00:02 rhamblin

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

Dreamescaper avatar Feb 22 '22 09:02 Dreamescaper

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

diemol avatar Aug 12 '22 05:08 diemol

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

amandalangley avatar Oct 03 '22 22:10 amandalangley

still happening - anyone has a workaround for it?

teqow avatar Apr 06 '23 17:04 teqow

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

Intrusion avatar Apr 14 '23 04:04 Intrusion

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

titusfortner avatar Apr 14 '23 16:04 titusfortner

Intrusion

I have changed Selenium to Playwright and everything works well.

teqow avatar Apr 14 '23 16:04 teqow

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" />

michasacuer avatar Jul 16 '23 13:07 michasacuer

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

sagihgithub avatar Aug 25 '23 10:08 sagihgithub

Fixed by https://github.com/SeleniumHQ/selenium/pull/12486, try the latest v4.12.2

nvborisenko avatar Sep 02 '23 14:09 nvborisenko

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[bot] avatar Dec 06 '23 00:12 github-actions[bot]