Merge pull request #35 from ultrafunkamsterdam/1.5.0

1.5.0
This commit is contained in:
Leon 2020-10-13 04:08:39 +02:00 committed by GitHub
commit e8d4050f3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 962 additions and 962 deletions

View File

@ -16,7 +16,7 @@ from setuptools import setup
setup( setup(
name="undetected-chromedriver", name="undetected-chromedriver",
version="1.4.2", version="1.5.0",
packages=["undetected_chromedriver"], packages=["undetected_chromedriver"],
install_requires=["selenium",], install_requires=["selenium",],
url="https://github.com/ultrafunkamsterdam/undetected_chromedriver", url="https://github.com/ultrafunkamsterdam/undetected_chromedriver",

View File

@ -19,6 +19,7 @@ by UltrafunkAmsterdam (https://github.com/ultrafunkamsterdam)
import io import io
import logging import logging
import os import os
import re
import sys import sys
import zipfile import zipfile
from distutils.version import LooseVersion from distutils.version import LooseVersion
@ -30,7 +31,6 @@ from selenium.webdriver import ChromeOptions as _ChromeOptions
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
__IS_PATCHED__ = 0
TARGET_VERSION = 0 TARGET_VERSION = 0
@ -55,9 +55,9 @@ class Chrome:
def _get_wrapped(*args, **kwargs): def _get_wrapped(*args, **kwargs):
if instance.execute_script("return navigator.webdriver"): if instance.execute_script("return navigator.webdriver"):
instance.execute_cdp_cmd( instance.execute_cdp_cmd(
"Page.addScriptToEvaluateOnNewDocument", "Page.addScriptToEvaluateOnNewDocument",
{"source": """ {
"source": """
Object.defineProperty(window, 'navigator', { Object.defineProperty(window, 'navigator', {
value: new Proxy(navigator, { value: new Proxy(navigator, {
@ -70,11 +70,13 @@ class Chrome:
: target[key] : target[key]
}) })
}); });
"""
(function () { + (
}) (); "console.log = console.dir = console.error = function(){};"
if not enable_console_log
""" + ("console.log = console.dir = console.error = function(){};" if not enable_console_log else '' ) } else ""
)
},
) )
return instance._orig_get(*args, **kwargs) return instance._orig_get(*args, **kwargs)
@ -102,9 +104,7 @@ class ChromeOptions:
instance.__init__() instance.__init__()
instance.add_argument("start-maximized") instance.add_argument("start-maximized")
instance.add_experimental_option("excludeSwitches", ["enable-automation"]) instance.add_experimental_option("excludeSwitches", ["enable-automation"])
instance.add_experimental_option("useAutomationExtension", False) instance.add_argument("--disable-blink-features=AutomationControlled")
instance.add_argument("--disable-blink-features=AutomationControlled");
logger.info(f"starting undetected_chromedriver.ChromeOptions({args}, {kwargs})")
return instance return instance
@ -120,12 +120,16 @@ class ChromeDriverManager(object):
_platform = sys.platform _platform = sys.platform
if TARGET_VERSION: # user override using global if TARGET_VERSION:
# use global if set
self.target_version = TARGET_VERSION self.target_version = TARGET_VERSION
if target_version: if target_version:
# use explicitly passed target
self.target_version = target_version # user override self.target_version = target_version # user override
if not self.target_version: if not self.target_version:
# if target_version still not set, fetch the current major release version # none of the above (default) and just get current version
self.target_version = self.get_release_version_number().version[ self.target_version = self.get_release_version_number().version[
0 0
] # only major version int ] # only major version int
@ -173,7 +177,8 @@ class ChromeDriverManager(object):
""" """
if not os.path.exists(self.executable_path): if not os.path.exists(self.executable_path):
self.fetch_chromedriver() self.fetch_chromedriver()
self.patch_binary() if not self.__class__.installed:
if self.patch_binary():
self.__class__.installed = True self.__class__.installed = True
if patch_selenium: if patch_selenium:
@ -220,20 +225,15 @@ class ChromeDriverManager(object):
:return: False on failure, binary name on success :return: False on failure, binary name on success
""" """
if self.__class__.installed: linect = 0
return with io.open(self.executable_path, "r+b") as fh:
for line in iter(lambda: fh.readline(), b""):
with io.open(self.executable_path, "r+b") as binary:
for line in iter(lambda: binary.readline(), b""):
if b"cdc_" in line: if b"cdc_" in line:
binary.seek(-len(line), 1) fh.seek(-len(line), 1)
line = b" var key = '$azc_abcdefghijklmnopQRstuv_';\n" newline = re.sub(b"cdc_.{22}", b"xxx_undetectedchromeDRiver", line)
binary.write(line) fh.write(newline)
__IS_PATCHED__ = 1 linect += 1
break return linect
else:
return False
return True
def install(executable_path=None, target_version=None, *args, **kwargs): def install(executable_path=None, target_version=None, *args, **kwargs):