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?
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
)
January 2023 UPDATE:
Starting with Chrome 109, the Chromium team renamed the option to --headless=new
. See https://github.com/chromium/chromium/commit/e9c516118e2e1923757ecb13e6d9fff36775d1f4 for details.