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 3 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 <[email protected]>
6 changes: 6 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ Selenium Wire has limited support for using the remote webdriver client. When yo

If the machine running the browser needs to use a different address to talk to the machine running Selenium Wire you need to configure the browser manually. `This issue <https://github.com/wkeeling/selenium-wire/issues/220>`_ goes into more detail.

If you need to completely disable the use of selenium-wire:

.. code:: python

driver = webdriver.Chrome(use_seleniumwire=False)

SunnyCapt marked this conversation as resolved.
Show resolved Hide resolved
Accessing Requests
~~~~~~~~~~~~~~~~~~

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
SunnyCapt marked this conversation as resolved.
Show resolved Hide resolved
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