diff --git a/splinter/browser.py b/splinter/browser.py index 53f578263..9dd6c39f3 100644 --- a/splinter/browser.py +++ b/splinter/browser.py @@ -28,6 +28,7 @@ _DRIVERS: Dict[str, Union[None, Type[DriverAPI]]] = { 'chrome': None, + 'undetected_chrome': None, 'edge': None, 'firefox': None, 'remote': None, @@ -38,10 +39,12 @@ try: from splinter.driver.webdriver.chrome import WebDriver as ChromeWebDriver + from splinter.driver.webdriver.undetected_chrome import WebDriver as undetected_ChromeWebDriver from splinter.driver.webdriver.firefox import WebDriver as FirefoxWebDriver from splinter.driver.webdriver.remote import WebDriver as RemoteWebDriver _DRIVERS['chrome'] = ChromeWebDriver + _DRIVERS['undetected_chrome'] = undetected_ChromeWebDriver _DRIVERS['firefox'] = FirefoxWebDriver _DRIVERS['remote'] = RemoteWebDriver except ImportError as e: diff --git a/splinter/driver/webdriver/undetected_chrome.py b/splinter/driver/webdriver/undetected_chrome.py new file mode 100644 index 000000000..874797a60 --- /dev/null +++ b/splinter/driver/webdriver/undetected_chrome.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- + +# Copyright 2012 splinter authors. All rights reserved. +# Use of this source code is governed by a BSD-style +# license that can be found in the LICENSE file. + +import undetected_chromedriver as uc +from splinter.driver.webdriver import BaseWebDriver + + +class WebDriver(BaseWebDriver): + + driver_name = "undetected_Chrome" + + def __init__( + self, + options=None, + user_agent=None, + wait_time=2, + fullscreen=False, + incognito=False, + headless=False, + **kwargs + ): + + options = uc.ChromeOptions() + + if user_agent is not None: + options.add_argument("--user-agent=" + user_agent) + + if incognito: + options.add_argument("--incognito") + + if fullscreen: + options.add_argument("--kiosk") + + if headless: + options.add_argument("--headless") + options.add_argument("--disable-gpu") + + driver = uc.Chrome(options=options, **kwargs) + + super(WebDriver, self).__init__(driver, wait_time)