question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[🐛 Bug]: A command response was not received: Network.getResponseBody C#

See original GitHub issue

What happened?

Hello, I am constantly getting an error when I try to get the response body.

One or more errors occurred. (A command response was not received: Network.getResponseBody)

StackTrace:

  at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at System.Threading.Tasks.Task`1.get_Result()
   at ConsoleApp3.Program.<>c__DisplayClass0_0.<Main>g__RequestWillBeSentHandler|0(Object sender, RequestWillBeSentEventArgs e) in C:\Users\ABC\source\repos\ConsoleApp3\ConsoleApp3\Program.cs:line 34

How can we reproduce the issue?

static async Task Main(string[] args)
        {
            var options = new ChromeOptions();

            var driver = new ChromeDriver(ChromeDriverService.CreateDefaultService(), options, TimeSpan.FromMinutes(2));

            var devTools = (IDevTools)driver;
            var session = devTools.GetDevToolsSession();
            var domains = session.GetVersionSpecificDomains<DevToolsSessionDomains>();

            void RequestWillBeSentHandler(object sender, RequestWillBeSentEventArgs e)
            {
                if (e.Request.Url.Contains("google.com"))
                {
                    try
                    {
                        var getResponseBody = domains.Network.GetResponseBody(new GetResponseBodyCommandSettings()
                        {
                            RequestId = e.RequestId
                        });

                        var body = getResponseBody.Result.Body;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                    }
                }
            }

            domains.Network.RequestWillBeSent += RequestWillBeSentHandler;
            await domains.Network.Enable(new EnableCommandSettings());

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

            driver.Quit();
        }

Relevant log output

Starting ChromeDriver 96.0.4664.45 (76e4c1bb2ab4671b8beba3444e61c0f17584b2fc-refs/branch-heads/4664@{#947}) on port 55559
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.

DevTools listening on ws://127.0.0.1:55562/devtools/browser/7a626fcd-3684-445b-9b6f-ebdb992b3712
[29984:27600:1214/114346.774:ERROR:chrome_browser_main_extra_parts_metrics.cc(226)] crbug.com/1216328: Checking Bluetooth availability started. Please report if there is no report that this ends.
[29984:27600:1214/114346.774:ERROR:chrome_browser_main_extra_parts_metrics.cc(229)] crbug.com/1216328: Checking Bluetooth availability ended.
[29984:27600:1214/114346.774:ERROR:chrome_browser_main_extra_parts_metrics.cc(232)] crbug.com/1216328: Checking default browser status started. Please report if there is no report that this ends.
[29984:27600:1214/114346.780:ERROR:chrome_browser_main_extra_parts_metrics.cc(236)] crbug.com/1216328: Checking default browser status ended.
System.AggregateException: One or more errors occurred. (A command response was not received: Network.getResponseBody)
 ---> System.InvalidOperationException: A command response was not received: Network.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.Network.NetworkAdapter.GetResponseBody(GetResponseBodyCommandSettings command, CancellationToken cancellationToken, Nullable`1 millisecondsTimeout, Boolean throwExceptionIfResponseNotReceived)
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at System.Threading.Tasks.Task`1.get_Result()
   at ConsoleApp3.Program.<>c__DisplayClass0_0.<Main>g__RequestWillBeSentHandler|0(Object sender, RequestWillBeSentEventArgs e) in C:\Users\ABC\source\repos\ConsoleApp3\ConsoleApp3\Program.cs:line 34

C:\Users\ABC\source\repos\ConsoleApp3\ConsoleApp3\bin\Debug\net5.0\ConsoleApp3.exe (process 14516) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .

Operating System

Windows 10

Selenium version

Selenium 4.1, .Net Core 5 or .NET Framework 4.7.2(C# 8)

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

Chrome 96

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

ChromeDriver 96

Are you using Selenium Grid?

no

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
amathercommented, Dec 28, 2021

I’m having the same issue, but running the CDP command directly works for me:

Dictionary<string, object> cdpParameters = new(){ { "requestId", e.RequestId} };
Dictionary<string, object> res = (Dictionary<string, object>) ((ChromeDriver)drv).ExecuteCdpCommand("Network.getResponseBody", cdpParameters);
 if (res.TryGetValue("body", out object? bodyObj))
 {
    string body = (string)bodyObj;
 }
2reactions
Dreamescapercommented, Jan 13, 2022

@lopukhDA You’re trying to retrieve response body on RequestWillBeSent event, response body not available at this point, since there is no response itself so far. You should do that on LoadingFinished event.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Remote Debugging - issues with Network.getResponseBody
I'd recommend try to receive an error for a wrong formatted message and a message with no command or id field. JFYI: The...
Read more >
How to get HTTP responseBody using Selenium, CDP ...
I use Network.loadingFinished event instead of Network.responseReceived , as the response is then completely loaded.
Read more >
771825 - DevTools: Network.getResponseBody should return ...
The protocol's method Network.getResponseBody returns a string that is decoded according to the Content-Type response header.
Read more >
Getting curl to output HTTP status code? - Super User
This should work for you if the web server is able to respond to HEAD requests (this will not perform a GET request):...
Read more >
REST Assured Tutorial: How to test API with Example - Guru99
Hence API testing was not explored by functional testing. ... In case you get an error on the browser when you try to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found