Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

completely disable the use of selenium wire #275

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ Development Lead
Contributors
------------

None yet. Why not be the first?
* Sunny Capt <sunny.capt@tuta.io>
7 changes: 7 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
69 changes: 53 additions & 16 deletions seleniumwire/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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.

Expand Down