diff --git a/AUTHORS.rst b/AUTHORS.rst index 094925e..35862e1 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -10,4 +10,4 @@ Development Lead Contributors ------------ -None yet. Why not be the first? +* Sunny Capt diff --git a/README.rst b/README.rst index 6672d50..5b5bded 100644 --- a/README.rst +++ b/README.rst @@ -835,6 +835,13 @@ A summary of all options that can be passed to Selenium Wire via the ``seleniumw } driver = webdriver.Chrome(seleniumwire_options=options) +``request_storage_base_dir`` + Completely disable the use of selenium-wire. The default is ``True``. + +.. code:: python + + driver = webdriver.Chrome(use_seleniumwire=False) + ``verify_ssl`` Whether SSL certificates should be verified. The default is ``False`` which prevents errors with self-signed certificates. diff --git a/seleniumwire/webdriver.py b/seleniumwire/webdriver.py index 9c1ddb3..ad5c306 100644 --- a/seleniumwire/webdriver.py +++ b/seleniumwire/webdriver.py @@ -14,6 +14,12 @@ from seleniumwire import backend from seleniumwire.inspect import InspectRequestsMixin +try: + # noinspection PyUnresolvedReferences + from undetected_chromedriver import ChromeOptions # noqa +except ImportError: + pass + class DriverCommonMixin: """Operations common to all webdriver types.""" @@ -46,7 +52,7 @@ def quit(self): super().quit() -class Firefox(InspectRequestsMixin, DriverCommonMixin, _Firefox): +class _SeleniumWireFirefox(InspectRequestsMixin, DriverCommonMixin, _Firefox): """Extends the Firefox webdriver to provide additional methods for inspecting requests.""" def __init__(self, *args, seleniumwire_options=None, **kwargs): @@ -75,7 +81,7 @@ def __init__(self, *args, seleniumwire_options=None, **kwargs): super().__init__(*args, **kwargs) -class Chrome(InspectRequestsMixin, DriverCommonMixin, _Chrome): +class _SeleniumWireChrome(InspectRequestsMixin, DriverCommonMixin, _Chrome): """Extends the Chrome webdriver to provide additional methods for inspecting requests.""" def __init__(self, *args, seleniumwire_options=None, **kwargs): @@ -114,18 +120,7 @@ def __init__(self, *args, seleniumwire_options=None, **kwargs): super().__init__(*args, **kwargs) -try: - # If we find undetected_chromedriver in the environment, we - # assume the user intends for us to use it. - import undetected_chromedriver - undetected_chromedriver._Chrome = Chrome - Chrome = undetected_chromedriver.Chrome - ChromeOptions = undetected_chromedriver.ChromeOptions # noqa: F811 -except ImportError: - pass - - -class Safari(InspectRequestsMixin, DriverCommonMixin, _Safari): +class _SeleniumWireSafari(InspectRequestsMixin, DriverCommonMixin, _Safari): """Extends the Safari webdriver to provide additional methods for inspecting requests.""" def __init__(self, seleniumwire_options=None, *args, **kwargs): @@ -151,7 +146,7 @@ def __init__(self, seleniumwire_options=None, *args, **kwargs): super().__init__(*args, **kwargs) -class Edge(InspectRequestsMixin, DriverCommonMixin, _Edge): +class _SeleniumWireEdge(InspectRequestsMixin, DriverCommonMixin, _Edge): """Extends the Edge webdriver to provide additional methods for inspecting requests.""" def __init__(self, seleniumwire_options=None, *args, **kwargs): @@ -177,7 +172,7 @@ def __init__(self, seleniumwire_options=None, *args, **kwargs): super().__init__(*args, **kwargs) -class Remote(InspectRequestsMixin, DriverCommonMixin, _Remote): +class _SeleniumWireRemote(InspectRequestsMixin, DriverCommonMixin, _Remote): """Extends the Remote webdriver to provide additional methods for inspecting requests.""" def __init__(self, *args, seleniumwire_options=None, **kwargs): @@ -207,6 +202,48 @@ def __init__(self, *args, seleniumwire_options=None, **kwargs): super().__init__(*args, **kwargs) +class Firefox(InspectRequestsMixin, DriverCommonMixin, _Firefox): + def __new__(cls, *args, use_seleniumwire=True, **kwargs): + clazz = _SeleniumWireFirefox if use_seleniumwire else _Firefox + return clazz(*args, **kwargs) + + +class Chrome(InspectRequestsMixin, DriverCommonMixin, _Chrome): + def __new__(cls, *args, use_seleniumwire=True, **kwargs): + clazz = _SeleniumWireChrome if use_seleniumwire else _Chrome + + try: + # noinspection PyUnresolvedReferences + import undetected_chromedriver as uc + + if 'chrome2use' not in kwargs: + kwargs['chrome2use'] = clazz + + clazz = uc.Chrome + except ImportError: + pass + + return clazz(*args, **kwargs) + + +class Safari(InspectRequestsMixin, DriverCommonMixin, _Safari): + def __new__(cls, *args, use_seleniumwire=True, **kwargs): + clazz = _SeleniumWireSafari if use_seleniumwire else _Safari + return clazz(*args, **kwargs) + + +class Edge(InspectRequestsMixin, DriverCommonMixin, _Edge): + def __new__(cls, *args, use_seleniumwire=True, **kwargs): + clazz = _SeleniumWireEdge if use_seleniumwire else _Edge + return clazz(*args, **kwargs) + + +class Remote(InspectRequestsMixin, DriverCommonMixin, _Remote): + def __new__(cls, *args, use_seleniumwire=True, **kwargs): + clazz = _SeleniumWireRemote if use_seleniumwire else _Remote + return clazz(*args, **kwargs) + + def urlsafe_address(address): """Make an address safe to use in a URL.