working patch
This commit is contained in:
parent
17e1f0e584
commit
8baa61990f
2
setup.py
2
setup.py
|
@ -16,7 +16,7 @@ from setuptools import setup
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="undetected-chromedriver",
|
name="undetected-chromedriver",
|
||||||
version="1.4.0",
|
version="1.4.2",
|
||||||
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",
|
||||||
|
|
|
@ -49,10 +49,16 @@ class Chrome:
|
||||||
kwargs["options"] = ChromeOptions()
|
kwargs["options"] = ChromeOptions()
|
||||||
instance = object.__new__(_Chrome)
|
instance = object.__new__(_Chrome)
|
||||||
instance.__init__(*args, **kwargs)
|
instance.__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
instance._orig_get = instance.get
|
||||||
|
|
||||||
|
def _get_wrapped(*args, **kwargs):
|
||||||
|
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, {
|
||||||
has: (target, key) => (key === 'webdriver' ? false : key in target),
|
has: (target, key) => (key === 'webdriver' ? false : key in target),
|
||||||
|
@ -64,11 +70,16 @@ class Chrome:
|
||||||
: target[key]
|
: target[key]
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
"""
|
|
||||||
+ "console.dir = console.log = function(){};"
|
(function () {
|
||||||
if not enable_console_log else ''
|
}) ();
|
||||||
},
|
|
||||||
|
""" + ("console.log = console.dir = console.error = function(){};" if not enable_console_log else '' ) }
|
||||||
)
|
)
|
||||||
|
return instance._orig_get(*args, **kwargs)
|
||||||
|
|
||||||
|
instance.get = _get_wrapped
|
||||||
|
|
||||||
original_user_agent_string = instance.execute_script(
|
original_user_agent_string = instance.execute_script(
|
||||||
"return navigator.userAgent"
|
"return navigator.userAgent"
|
||||||
)
|
)
|
||||||
|
@ -92,6 +103,7 @@ class ChromeOptions:
|
||||||
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_experimental_option("useAutomationExtension", False)
|
||||||
|
instance.add_argument("--disable-blink-features=AutomationControlled");
|
||||||
logger.info(f"starting undetected_chromedriver.ChromeOptions({args}, {kwargs})")
|
logger.info(f"starting undetected_chromedriver.ChromeOptions({args}, {kwargs})")
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue