I'm using ASP.NET Core 6 with Selenium 4.1. When I run my code regularly, it works fine, but when I set it to headless, I don't think any of the options work including the Guest, inPrivate, or incognito mode because I keep getting 2FA prompts as if it is logging in with my cached credentials.
Here are my options with EdgeDriver:
var options = new EdgeOptions();
options.AddArgument("-guest");
options.AddArgument("disable-gpu");
options.AddArgument("headless");
using (var driver = new EdgeDriver(DRIVERS_PATH, options))
{
driver.Manage().Window.Maximize();
driver.Manage().Cookies.DeleteAllCookies();
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(45));
driver.Navigate().GoToUrl(recordUrl);
// get a 2FA prompt here
}
Or when using ChromeOptions
var options = new ChromeOptions();
options.AddArguments("--headless");
options.AddArguments("--window-size=1920,1080");
options.AddArguments("--disable-gpu");
options.AddArguments("--disable-extensions");
options.AddArguments("--proxy-server='direct://'");
options.AddArguments("--proxy-bypass-list=*");
options.AddArguments("--start-maximized");
options.AddArguments("--no-first-run");
options.AddArguments("--no-default-browser-check");
options.AddArguments("--ignore-certificate-errors");
options.AddArguments("--test-type");
options.AddArguments("--user-agent=\"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36\"");
//options.AddArguments("--guest");
options.AddArguments("--incognito");
Once again, if I remove the headless option, then it works fine, but with headless, I don't think any of the options are taking. When I take a screenshot of the page:
var screenshot = driver.GetScreenshot();
screenshot.SaveAsFile($"{filePath}.jpg", ScreenshotImageFormat.Jpeg);
It shows the message saying it sent me a 2FA notice which I then receive on my phone. Why would it be doing this if I was in incognito mode?
Any help is appreciated. Thanks.