简体   繁体   中英

http responses not being intercepted while in headless mode on chrome

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 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM