Skip to content

Commit 3f5515b

Browse files
authored
Merge pull request #1493 from seleniumbase/undetected-chromedriver-updates
Undetected-Chromedriver Mode updates
2 parents e496832 + 39fa674 commit 3f5515b

File tree

8 files changed

+65
-25
lines changed

8 files changed

+65
-25
lines changed

examples/verify_undetected.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ class UndetectedTest(BaseCase):
1010
def test_browser_is_undetected(self):
1111
self.open("https://nowsecure.nl")
1212
try:
13-
self.assert_text("OH YEAH, you passed!", "h1", timeout=6.6)
14-
self.post_message("Browser wasn't detected!", duration=1.6)
15-
self._print("\n Success! Website did not detect Selenium!")
13+
self.assert_text("OH YEAH, you passed!", "h1", timeout=6.75)
14+
self.post_message("Selenium wasn't detected!", duration=1.6)
15+
self._print("\n Success! Website did not detect Selenium! ")
1616
except Exception:
17-
self.fail('Browser was detected! Try using: "pytest --uc"')
17+
self.fail('Selenium was detected! Try using: "pytest --uc"')

mkdocs_build/requirements.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,19 @@
22
# Minimum Python version: 3.7
33

44
regex>=2022.8.17
5-
tqdm>=4.64.0
65
docutils==0.19
76
python-dateutil==2.8.2
87
livereload==2.6.3
98
joblib==1.1.0
109
Markdown==3.3.7
1110
MarkupSafe==2.1.1
12-
keyring==23.9.0
11+
keyring==23.9.1
1312
pkginfo==1.8.3
1413
Jinja2==3.1.2
1514
click==8.1.3
1615
zipp==3.8.1
1716
ghp-import==2.1.0
18-
readme-renderer==37.0
17+
readme-renderer==37.1
1918
pymdown-extensions==9.5
2019
importlib-metadata==4.12.0
2120
bleach==5.0.1

requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ setuptools>=59.6.0;python_version>="3.6" and python_version<"3.7"
88
setuptools>=65.3.0;python_version>="3.7"
99
tomli>=1.2.3;python_version>="3.6" and python_version<"3.7"
1010
tomli>=2.0.1;python_version>="3.7"
11+
tqdm>=4.64.1
1112
wheel>=0.37.1
1213
attrs>=21.4.0;python_version<"3.6"
1314
attrs>=22.1.0;python_version>="3.6"
@@ -68,7 +69,7 @@ py==1.8.1;python_version<"3.6"
6869
py==1.11.0;python_version>="3.6"
6970
pytest==4.6.11;python_version<"3.6"
7071
pytest==7.0.1;python_version>="3.6" and python_version<"3.7"
71-
pytest==7.1.2;python_version>="3.7"
72+
pytest==7.1.3;python_version>="3.7"
7273
pytest-forked==1.3.0;python_version<"3.6"
7374
pytest-forked==1.4.0;python_version>="3.6"
7475
pytest-html==1.22.1;python_version<"3.6"
@@ -96,7 +97,7 @@ cryptography==37.0.4;python_version>="3.7"
9697
pygments==2.5.2;python_version<"3.6"
9798
pygments==2.13.0;python_version>="3.6"
9899
prompt-toolkit==1.0.18;python_version<"3.6"
99-
prompt-toolkit==3.0.30;python_version>="3.6"
100+
prompt-toolkit==3.0.31;python_version>="3.6"
100101
decorator==4.4.2;python_version<"3.6"
101102
decorator==5.1.1;python_version>="3.6"
102103
ipython==5.10.0;python_version<"3.6"

seleniumbase/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# seleniumbase package
2-
__version__ = "4.3.1"
2+
__version__ = "4.3.2"

seleniumbase/core/browser_launcher.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def _add_chrome_proxy_extension(
227227
chrome_options = add_chrome_ext_dir(chrome_options, PROXY_DIR_PATH)
228228

229229
else:
230-
# Pytest multi-threaded test
230+
# Pytest multithreaded test
231231
if zip_it:
232232
proxy_zip_lock = fasteners.InterProcessLock(PROXY_ZIP_LOCK)
233233
with proxy_zip_lock:
@@ -2007,6 +2007,8 @@ def get_local_driver(
20072007
)
20082008
driver = Edge(service=service, options=edge_options)
20092009
except Exception as e:
2010+
if not hasattr(e, "msg"):
2011+
raise
20102012
auto_upgrade_edgedriver = False
20112013
edge_version = None
20122014
if (
@@ -2063,6 +2065,8 @@ def get_local_driver(
20632065
capabilities=capabilities,
20642066
)
20652067
except Exception as e:
2068+
if not hasattr(e, "msg"):
2069+
raise
20662070
auto_upgrade_edgedriver = False
20672071
edge_version = None
20682072
if (
@@ -2114,7 +2118,7 @@ def get_local_driver(
21142118
arg_join = " ".join(sys.argv)
21152119
if ("-n" in sys.argv) or (" -n=" in arg_join) or (arg_join == "-c"):
21162120
# Skip if multithreaded
2117-
raise Exception("Can't run Safari tests in multi-threaded mode!")
2121+
raise Exception("Can't run Safari tests in multithreaded mode!")
21182122
warnings.simplefilter("ignore", category=DeprecationWarning)
21192123
return webdriver.safari.webdriver.WebDriver(quiet=False)
21202124
elif browser_name == constants.Browser.OPERA:
@@ -2343,21 +2347,36 @@ def get_local_driver(
23432347
or is_using_uc(undetectable, browser_name)
23442348
):
23452349
if selenium4_or_newer:
2350+
if headless and "linux" not in PLATFORM:
2351+
undetectable = False # No support for headless
23462352
if undetectable:
23472353
from seleniumbase import undetected
23482354
from urllib.error import URLError
23492355

23502356
if "linux" in PLATFORM:
2351-
chrome_options.headless = False # Use xvfb
2357+
chrome_options.headless = False # Use Xvfb
2358+
if "--headless" in (
2359+
chrome_options.arguments
2360+
):
2361+
chrome_options.arguments.remove(
2362+
"--headless"
2363+
)
23522364
cert = "unable to get local issuer certificate"
2365+
uc_chrome_version = None
2366+
if (
2367+
use_version.isnumeric
2368+
and int(use_version) >= 72
2369+
):
2370+
uc_chrome_version = int(use_version)
23532371
uc_lock = fasteners.InterProcessLock(
23542372
constants.MultiBrowser.DRIVER_FIXING_LOCK
23552373
)
2356-
with uc_lock:
2374+
with uc_lock: # No UC multithreaded tests
23572375
try:
23582376
driver = undetected.Chrome(
23592377
options=chrome_options,
2360-
headless=headless,
2378+
headless=False, # Xvfb needed
2379+
version_main=uc_chrome_version,
23612380
)
23622381
except URLError as e:
23632382
if (
@@ -2371,7 +2390,8 @@ def get_local_driver(
23712390
)
23722391
driver = undetected.Chrome(
23732392
options=chrome_options,
2374-
headless=headless,
2393+
headless=False, # Xvfb needed
2394+
version_main=uc_chrome_version,
23752395
)
23762396
else:
23772397
raise
@@ -2402,6 +2422,8 @@ def get_local_driver(
24022422
service_log_path=os.devnull,
24032423
)
24042424
except Exception as e:
2425+
if not hasattr(e, "msg"):
2426+
raise
24052427
auto_upgrade_chromedriver = False
24062428
if "This version of ChromeDriver only supports" in e.msg:
24072429
auto_upgrade_chromedriver = True
@@ -2513,6 +2535,8 @@ def get_local_driver(
25132535
try:
25142536
return webdriver.Chrome(options=chrome_options)
25152537
except Exception as e:
2538+
if not hasattr(e, "msg"):
2539+
raise
25162540
auto_upgrade_chromedriver = False
25172541
if "This version of ChromeDriver only supports" in e.msg:
25182542
auto_upgrade_chromedriver = True

seleniumbase/undetected/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,8 @@ def __init__(
117117
suppress_welcome: (default: True)
118118
Suppress the Chrome welcome screen that appears on first-time runs.
119119
120-
use_subprocess:
121-
False (default) Give Chrome its own process,
122-
rather than subprocessing chromedriver or python.
120+
use_subprocess: (default: False)
121+
Subprocess chromedriver/python: Don't make Chrome a parent process.
123122
"""
124123
self.debug = debug
125124
patcher = Patcher(
@@ -238,7 +237,10 @@ def __init__(
238237
mode="r+",
239238
) as fs:
240239
config = json.load(fs)
241-
if config["profile"]["exit_type"] is not None:
240+
if (
241+
"exit_type" not in config["profile"].keys()
242+
or config["profile"]["exit_type"] is not None
243+
):
242244
config["profile"]["exit_type"] = None
243245
fs.seek(0, 0)
244246
json.dump(config, fs)

seleniumbase/undetected/options.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ def _undot_key(key, value):
2626
value = ChromeOptions._undot_key(rest, value)
2727
return {key: value}
2828

29+
@staticmethod
30+
def _merge_nested(a, b):
31+
"""Merges b into a, overwriting duplicate leaf values using b."""
32+
for key in b:
33+
if key in a:
34+
if isinstance(a[key], dict) and isinstance(b[key], dict):
35+
ChromeOptions._merge_nested(a[key], b[key])
36+
continue
37+
a[key] = b[key]
38+
return a
39+
2940
def handle_prefs(self, user_data_dir):
3041
prefs = self.experimental_options.get("prefs")
3142
if prefs:
@@ -34,11 +45,13 @@ def handle_prefs(self, user_data_dir):
3445
os.makedirs(default_path, exist_ok=True)
3546
undot_prefs = {}
3647
for key, value in prefs.items():
37-
undot_prefs.update(self._undot_key(key, value))
48+
undot_prefs = self._merge_nested(
49+
undot_prefs, self._undot_key(key, value)
50+
)
3851
prefs_file = os.path.join(default_path, "Preferences")
3952
if os.path.exists(prefs_file):
4053
with open(prefs_file, encoding="latin1", mode="r") as f:
41-
undot_prefs.update(json.load(f))
54+
undot_prefs = self._merge_nested(json.load(f), undot_prefs)
4255
with open(prefs_file, encoding="latin1", mode="w") as f:
4356
json.dump(undot_prefs, f)
4457
# Remove experimental_options to avoid errors

setup.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
print("\n*** Installing twine: *** (Required for PyPI uploads)\n")
5252
os.system("python -m pip install --upgrade 'twine>=4.0.1'")
5353
print("\n*** Installing tqdm: *** (Required for PyPI uploads)\n")
54-
os.system("python -m pip install --upgrade 'tqdm>=4.64.0'")
54+
os.system("python -m pip install --upgrade tqdm")
5555
print("\n*** Rebuilding distribution packages: ***\n")
5656
os.system("python -m build") # Create new tar/wheel
5757
print("\n*** Publishing The Release to PyPI: ***\n")
@@ -134,6 +134,7 @@
134134
'setuptools>=65.3.0;python_version>="3.7"',
135135
'tomli>=1.2.3;python_version>="3.6" and python_version<"3.7"',
136136
'tomli>=2.0.1;python_version>="3.7"',
137+
"tqdm>=4.64.1",
137138
"wheel>=0.37.1",
138139
'attrs>=21.4.0;python_version<"3.6"',
139140
'attrs>=22.1.0;python_version>="3.6"',
@@ -193,7 +194,7 @@
193194
'py==1.11.0;python_version>="3.6"',
194195
'pytest==4.6.11;python_version<"3.6"',
195196
'pytest==7.0.1;python_version>="3.6" and python_version<"3.7"',
196-
'pytest==7.1.2;python_version>="3.7"',
197+
'pytest==7.1.3;python_version>="3.7"',
197198
'pytest-forked==1.3.0;python_version<"3.6"',
198199
'pytest-forked==1.4.0;python_version>="3.6"',
199200
'pytest-html==1.22.1;python_version<"3.6"',
@@ -221,7 +222,7 @@
221222
'pygments==2.5.2;python_version<"3.6"',
222223
'pygments==2.13.0;python_version>="3.6"',
223224
'prompt-toolkit==1.0.18;python_version<"3.6"',
224-
'prompt-toolkit==3.0.30;python_version>="3.6"',
225+
'prompt-toolkit==3.0.31;python_version>="3.6"',
225226
'decorator==4.4.2;python_version<"3.6"',
226227
'decorator==5.1.1;python_version>="3.6"',
227228
'ipython==5.10.0;python_version<"3.6"',

0 commit comments

Comments
 (0)