Home > other >  http responses not being intercepted while in headless mode on chrome
http responses not being intercepted while in headless mode on chrome

Time:12-23

This code works fine while using non headless mode on chrome.

I initiated an instance of INetwork

_networkInterceptor = _driver.Manage().Network;

setup a network response handler and listening for a specific path once the path is found it basically logs the information and adds the response to a list of responses and start monitoring for the responses.

if (interceptedResponse.StatusCode != 200 || !interceptedResponse.Url.Contains(path)) return false;
_logger.LogInformation($"Network interceptor intercepted the response with path - {path}:"  
                  $"\nStatus: {interceptedResponse.StatusCode.ToString()}"  
                  $"\nURL: {interceptedResponse.Url.ToString()}"  
                  $"\nBody: {interceptedResponse.Body}");
var response = JsonConvert.DeserializeObject<TResponse>(interceptedResponse.Body);
_responses.Add(path,response);


_networkInterceptor.AddResponseHandler(responseHandler);
_networkInterceptor.StartMonitoring().Wait();

If i use the chrome argument --headless the above code does not output the results as while using non headless mode.

I tried to setup remote debugging by using the below arguments

chromeOptions.AddArgument("--remote-debugging-port=9222");
chromeOptions.AddArgument("--remote-debugging-address=0.0.0.0");

Am i missing any arguments to enable devtools while using chrome in headless mode or such a feature is not supported?

CodePudding user response:

Instead of using --headless, use --headless=chrome.

Regular headless mode in Chrome has restrictions, but the Chromium developers recently added a 2nd headless mode that functions the same way as normal Chrome.

There's more info on that here: https://bugs.chromium.org/p/chromium/issues/detail?id=706008#c36

In summary, use --headless=chrome

(The OLD way was: --headless)

  • Related