fysh711426 / UndetectedChromeDriver

GNU General Public License v3.0
166 stars 60 forks source link

Extension added but not working properly #77

Closed kker4m closed 3 months ago

kker4m commented 3 months ago

Hi, I have some experience working with uc on Python before, but can't handle this situation. Here's my code and what I've tried:

Everything works fine, and the driver starts, but the extension never gets installed. (I tried with a .crx format file, but it's still the same)

 public class Driver
 {
    int minimumAPIKeyLength;
    int PageLoadTimeout;
    public Driver()
    {
        this.minimumAPIKeyLength = 10;
        this.PageLoadTimeout = 500;
    }

    public static async Task<IWebDriver> CallUndetectedDriver(bool useHeadless, string pageLoadStrategy, string profileName)
    {
        //Create a new instance of the Chrome driver, allow pop-ups and maximize the window
        ChromeOptions options = new ChromeOptions();

        var extension1 = (@"extensions\adblock");
        options.AddArgument($"--load-extension={extension1}");

        if (useHeadless)
        {
            options.AddArgument("--headless");
        }
        options.AddArgument("--disable-notifications");
        options.AddArgument("--disable-popup-blocking");
        options.AddArgument("--lang=en");
        options.PageLoadStrategy = (PageLoadStrategy)Enum.Parse(typeof(PageLoadStrategy), pageLoadStrategy);
        if (profileName != null)
        {
            options.AddArgument("--user-data-dir=driver\\chromeLog\\" + profileName);
            options.AddArgument("--profile-directory=" + profileName);
        }
        options.AddArgument("--disable-extensions");
        options.AddArgument("--disable-gpu");
        options.AddArgument("--disable-dev-shm-usage");
        options.AddArgument("--no-sandbox");
        options.AddArgument("--disable-software-rasterizer");
        options.AddArgument("--disable-features=VizDisplayCompositor");
        options.AddArgument("--disable-features=IsolateOrigins,site-per-process");
        options.AddArgument("--disable-features=site-per-process");
        options.AddArgument("--disable-features=CrossSiteDocumentBlockingIfIsolating");
        options.AddArgument("--disable-features=CrossSiteDocumentBlockingAlways");
        options.AddArgument("--disable-features=CrossSiteDocumentBlockingIfIsolating");
        options.AddArgument("--disable-features=CrossSiteDocumentBlockingAlways");
        options.AddArgument("--disable-features=AudioServiceOutOfProcess");

        //create undetected driver
        IWebDriver driver = UndetectedChromeDriver.Create(options, driverExecutablePath: await new ChromeDriverInstaller().Auto());
        driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(2);
        return driver;

    }

}

Edited: omissions and spelling errors

kker4m commented 3 months ago

Well, it looks like I'm really stupid. Extensions were not working because I forgot to delete this line;

options.AddArgument("--disable-extensions");