CekaSoft
CekaSoft

Reputation: 21

How to disable Automation Controlled for firefox in java Playwright

I am making an automation with playwright in Java. You will log in to accounts by going to an e-commerce site. A process repeated many times.

With Chromium, by setting the --disable-blink-features=AutomationControlled option, it does not understand that there is automation and does not get stuck in security. But if I do it with Firefox, my automation gets stuck in security after 15 accounts. Even though I added prefs for firefox, I couldn't fix this. What is the equivalent of the --disable-blink-features=AutomationControlled setting in Chrome in Firefox? I want to continue with Firefox. Because the page.waitForResponse() method does not work properly in Chrome. It cannot catch the response. When I setHeadless(true), it cannot find the locators. When I hide the browser in Firefox, it works fine. It captures all the returning responses. There's only one problem: I can't disable AutomationControlled...

enter image description here

    if (browser == null) {
        List<String> optionsAddList = new ArrayList<>();
        // * chromium
        optionsAddList.add("--disable-blink-features=AutomationControlled");
        optionsAddList.add("--enable-automation");
        optionsAddList.add("--disable-blink-features");
        // * firefox
        Map<String, Object> prefs = new HashMap<>();
        //prefs.put("browser.startup.homepage", "https://www.example.com");
        prefs.put("browser.tabs.remote.autostart", false);
        prefs.put("security.fileuri.strict_origin_policy", true);
        prefs.put("useAutomationExtension", false);
        prefs.put("blink-settings", "enable-automation");
        prefs.put("blink-features", "enable-automation");
        prefs.put("excludeSwitches", "-private");//useAutomationExtension
        prefs.put("browser.privatebrowsing.autostart", true);

        BrowserType.LaunchOptions browserLaunchOptions = (new BrowserType.LaunchOptions()
                .setHeadless(myHeadless)
              //  .setArgs(optionsAddList)
                .setFirefoxUserPrefs(prefs)
        );
        browser = playwright.firefox().launch(browserLaunchOptions);
    }
    if (browserContext == null) {
        Browser.NewContextOptions newContextOptions=new Browser.NewContextOptions()
                //.setColorScheme(ColorScheme.DARK)  // .setDeviceScaleFactor(2) //.setViewportSize(new ViewportSize(500,500))
                .setProxy(new Proxy(proxyUrl).setPassword(proxyPassword).setUsername(proxyPassword)
        );
        browserContext = browser.newContext(newContextOptions);
        browserContext.clearCookies();
    }

Upvotes: 2

Views: 807

Answers (0)

Related Questions