Search code examples
javaseleniumautomation

Hide Automation Browser from detecting as bot


Is there any way to hide the chrome instances launched by the chrome driver to be undetectable by the web apps like Stripe payments, FedEx tracking, etc?

I've tried with the following chrome options:

            Map<String, Object> prefs = new HashMap<String, Object>();
            prefs.put("profile.default_content_setting_values.notifications", 2);
            prefs.put("credentials_enable_service", false);
            prefs.put("profile.password_manager_enabled", false);
            prefs.put("useAutomationExtension", false);
            ChromeOptions options = new ChromeOptions();
            options.setExperimentalOption("prefs", prefs);
            String agentString = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36";
            options.addArguments("--user-agent=" + agentString);
            options.addArguments("--disable-extensions");
            options.addArguments("--disable-infobars");
            options.addArguments("window-size=1920,1080");
            //options.addArguments("--headless");
            options.addArguments("--no-sandbox", "--disable-dev-shm-usage");
            options.addArguments("--disable-gpu");
            //options.addArguments("enable-automation");
            options.addArguments("--dns-prefetch-disable");
            options.addArguments("--disable-browser-side-navigation");
            options.addArguments("--disable-blink-features");
            options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
            options.addArguments("--disable-blink-features=AutomationControlled");
            options.setPageLoadStrategy(PageLoadStrategy.NORMAL);

Solution

  • The solution I figure out is using Profile in Selenium webdriver.

    here are the steps for using a profile

    Create a chrome profile manually Set chrome options as: for Python

    options.add_arguments('--user-data=C:\Users\User\AppData\local\Google\Chrome\User Data\Profile\')
    

    for Java

    options.addArguments("user-data=C:\Users\User\AppData\local\Google\Chrome\UserData\Profile\");