SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
30.42k stars 8.15k forks source link

[🐛 Bug]: CommandResponseException: Fetch.getResponseBody: Invalid InterceptionId #14050

Closed saymon-jm closed 2 months ago

saymon-jm commented 4 months ago

What happened?

It throws this exception when I try to get the body of a response using fetch.GetResponseBody. The code works if the proxy is not enabled.

How can we reproduce the issue?

using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.DevTools;
using DevTools = OpenQA.Selenium.DevTools.V125;

var options = new ChromeOptions();
options.AddArgument("--proxy-server=PROXY_ADDRESS");

var service = ChromeDriverService.CreateDefaultService();
var driver = new ChromeDriver(service, options);

var networkAuthenticationHandler = new NetworkAuthenticationHandler
{
    UriMatcher = uri => true,
    Credentials = new PasswordCredentials("USERNAME", "PASSWORD"),
};

var networkInterceptor = driver.Manage().Network;
networkInterceptor.AddAuthenticationHandler(networkAuthenticationHandler);
await networkInterceptor.StartMonitoring();

IDevTools devTools = driver;
var session = devTools.GetDevToolsSession();
var fetch = session.GetVersionSpecificDomains<DevTools.DevToolsSessionDomains>().Fetch;

var requestPattern = new DevTools.Fetch.RequestPattern
{
    RequestStage = DevTools.Fetch.RequestStage.Response
};

var enableCommandSettings = new DevTools.Fetch.EnableCommandSettings
{
    Patterns = new DevTools.Fetch.RequestPattern[]
    {
        requestPattern
    },
};

await fetch.Enable(enableCommandSettings);
fetch.RequestPaused += (s, e) =>
{
    var responseBody = fetch.GetResponseBody(new DevTools.Fetch.GetResponseBodyCommandSettings()
    {
        RequestId = e.RequestId
    });

    // Throws exception here
    var body = responseBody.Result.Body;
};

driver.Navigate().GoToUrl("http://lumtest.com/myip.json");
driver.Quit();

Relevant log output

System.AggregateException
  HResult=0x80131500
  Message=One or more errors occurred. (Fetch.getResponseBody: Invalid InterceptionId.)
  Source=System.Private.CoreLib
  StackTrace:
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at Program.<>c__DisplayClass0_0.<<Main>$>b__0(Object s, RequestPausedEventArgs e) in D:\Lab\SeleniumBug\SeleniumBug\Program.cs:line 48
   at OpenQA.Selenium.DevTools.V125.Fetch.FetchAdapter.OnRequestPaused(Object rawEventArgs)
   at OpenQA.Selenium.DevTools.V125.Fetch.FetchAdapter.OnDevToolsEventReceived(Object sender, DevToolsEventReceivedEventArgs e)
   at OpenQA.Selenium.DevTools.DevToolsSession.OnDevToolsEventReceived(DevToolsEventReceivedEventArgs e)
   at OpenQA.Selenium.DevTools.DevToolsSession.<>c__DisplayClass51_0.<ProcessMessage>b__0()
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)

  This exception was originally thrown at this call stack:
    [External Code]

Inner Exception 1:
CommandResponseException: Fetch.getResponseBody: Invalid InterceptionId

Operating System

Windows 10

Selenium version

.NET 8.0 and Selenium 4.21.0

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

Chrome 125.0.6422.78

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

ChromeDriver 125.0.6422.78

Are you using Selenium Grid?

No

github-actions[bot] commented 4 months ago

@saymon-jm, 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, MSEdgeDriver, 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!

titusfortner commented 4 months ago

This is probably a chromedriver limitation (the way chromedriver manages proxies might not work with CDP)

saymon-jm commented 4 months ago

This is probably a chromedriver limitation (the way chromedriver manages proxies might not work with CDP)

I understand, so I'll try to do what I need without using Chrome DevTools. Thanks for your response.

titusfortner commented 4 months ago

I should clarify that I'm not exactly an expert in this piece. Also useful info is that the Chrome DevTools implementation is kind of a stop gap while we figure out the WebDriver BiDi spec (https://w3c.github.io/webdriver-bidi/). We're working to be able to replace the functionality with a cros-browser supported solution.

diemol commented 2 months ago

I am closing this due to the lack of activity.

github-actions[bot] commented 1 month ago

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