Home > other >  How to start ChromeDriver in headless mode when loading a Chrome Extension
How to start ChromeDriver in headless mode when loading a Chrome Extension

Time:01-27

This is the C# code I have. When I run it it starts in headless mode but it seems to have an issue with the Chrome extension.

 [Test]
        public async Task Start()
        {
            var chromeDriverService = ChromeDriverService.CreateDefaultService();
            var option = new ChromeOptions();


            option.AddExtension(MainPageElements.extensionPath);
            option.AddArguments("headless");
            using (var browser = new ChromeDriver(option))
            {
                WebDriver webDriver = new ChromeDriver(chromeDriverService, option);
                webDriver.Manage().Window.Maximize();
                //more code
            }
         }  

This is the error I get when I run it:

OpenQA.Selenium.WebDriverException : unknown error: failed to wait for extension background page to load: chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.html from unknown error: page could not be found: chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.html

The extension is MetaMask. It's a crypto wallet.

It could be not possible at all using headless mode when loading this Chrome extension since it opens a new pop up window of its own...

edit: Version of ChromeDriver - 108.0.5359.7100

CodePudding user response:

You have to put

option.AddArguments("--headless=new")

just before the command option.AddExtension(MainPageElements.extensionPath);

source https://bugs.chromium.org/p/chromium/issues/detail?id=706008#c36

  • Related