Skip to content

Commit 9b8f8a0

Browse files
committed
Refactor UC Mode
1 parent 4dc8ca7 commit 9b8f8a0

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

seleniumbase/undetected/__init__.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33
import os
44
import re
5+
import requests
56
import subprocess
67
import sys
78
import time
@@ -138,8 +139,6 @@ def __init__(
138139
options._session = self
139140
debug_host = "127.0.0.1"
140141
debug_port = 9222
141-
import requests
142-
143142
special_port_free = False # If the port isn't free, don't use 9222
144143
try:
145144
res = requests.get("http://127.0.0.1:9222", timeout=1)
@@ -151,7 +150,6 @@ def __init__(
151150
sys_argv = sys.argv
152151
arg_join = " ".join(sys_argv)
153152
from seleniumbase import config as sb_config
154-
155153
if (
156154
(("-n" in sys.argv) or (" -n=" in arg_join) or ("-c" in sys.argv))
157155
or (hasattr(sb_config, "multi_proxy") and sb_config.multi_proxy)
@@ -197,7 +195,6 @@ def __init__(
197195
keep_user_data_dir = True
198196
else:
199197
import tempfile
200-
201198
user_data_dir = os.path.normpath(tempfile.mkdtemp())
202199
keep_user_data_dir = False
203200
arg = "--user-data-dir=%s" % user_data_dir
@@ -206,7 +203,6 @@ def __init__(
206203
if not language:
207204
try:
208205
import locale
209-
210206
language = locale.getlocale()[0].replace("_", "-")
211207
except Exception:
212208
pass
@@ -241,7 +237,6 @@ def __init__(
241237
options.handle_prefs(user_data_dir)
242238
try:
243239
import json
244-
245240
with open(
246241
os.path.join(
247242
os.path.abspath(user_data_dir),
@@ -286,19 +281,22 @@ def __init__(
286281
)
287282
self.browser_pid = browser.pid
288283
service_ = None
284+
log_output = subprocess.PIPE
285+
if sys.version_info < (3, 8):
286+
log_output = os.devnull
289287
if patch_driver:
290288
service_ = selenium.webdriver.chrome.service.Service(
291289
executable_path=self.patcher.executable_path,
292290
service_args=["--disable-build-check"],
293291
port=port,
294-
log_output=os.devnull,
292+
log_output=log_output,
295293
)
296294
else:
297295
service_ = selenium.webdriver.chrome.service.Service(
298296
executable_path=driver_executable_path,
299297
service_args=["--disable-build-check"],
300298
port=port,
301-
log_output=os.devnull,
299+
log_output=log_output,
302300
)
303301
if hasattr(service_, "creationflags"):
304302
setattr(service_, "creationflags", creationflags)
@@ -321,7 +319,6 @@ def __getattribute__(self, item):
321319
return super().__getattribute__(item)
322320
else:
323321
import inspect
324-
325322
original = super().__getattribute__(item)
326323
if inspect.ismethod(original) and not inspect.isclass(original):
327324
def newfunc(*args, **kwargs):
@@ -455,7 +452,6 @@ def quit(self):
455452
and not self.keep_user_data_dir
456453
):
457454
import shutil
458-
459455
for _ in range(5):
460456
try:
461457
shutil.rmtree(self.user_data_dir, ignore_errors=False)
@@ -506,7 +502,6 @@ def __hash__(self):
506502

507503
def find_chrome_executable():
508504
from seleniumbase.core import detect_b_ver
509-
510505
binary_location = detect_b_ver.get_binary_location("google-chrome", True)
511506
if os.path.exists(binary_location) and os.access(binary_location, os.X_OK):
512507
return os.path.normpath(binary_location)

0 commit comments

Comments
 (0)