Skip to content

Commit 4624edd

Browse files
committed
Refactor UC Mode
1 parent 83d08d1 commit 4624edd

File tree

2 files changed

+50
-25
lines changed

2 files changed

+50
-25
lines changed

seleniumbase/core/browser_launcher.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,29 @@ def install_pyautogui_if_missing(driver):
586586
shared_utils.pip_install(
587587
"pyautogui", version=constants.PyAutoGUI.VER
588588
)
589+
try:
590+
import pyautogui
591+
except Exception:
592+
if (
593+
IS_LINUX
594+
and hasattr(sb_config, "xvfb")
595+
and hasattr(sb_config, "headed")
596+
and hasattr(sb_config, "headless")
597+
and hasattr(sb_config, "headless2")
598+
and (not sb_config.headed or sb_config.xvfb)
599+
and not (sb_config.headless or sb_config.headless2)
600+
):
601+
from sbvirtualdisplay import Display
602+
try:
603+
xvfb_display = Display(
604+
visible=True,
605+
size=(1366, 768),
606+
backend="xvfb",
607+
use_xauth=True,
608+
)
609+
xvfb_display.start()
610+
except Exception:
611+
pass
589612

590613

591614
def get_configured_pyautogui(pyautogui_copy):

seleniumbase/fixtures/base_case.py

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13788,31 +13788,33 @@ def __activate_virtual_display_as_needed(self):
1378813788
which is the default mode on Linux unless using another arg."""
1378913789
if "linux" in sys.platform and (not self.headed or self.xvfb):
1379013790
from sbvirtualdisplay import Display
13791-
if self.undetectable and not (self.headless or self.headless2):
13792-
import Xlib.display
13793-
try:
13794-
self._xvfb_display = Display(
13795-
visible=True,
13796-
size=(1366, 768),
13797-
backend="xvfb",
13798-
use_xauth=True,
13799-
)
13800-
self._xvfb_display.start()
13801-
if "DISPLAY" not in os.environ.keys():
13791+
pip_find_lock = fasteners.InterProcessLock(
13792+
constants.PipInstall.FINDLOCK
13793+
)
13794+
with pip_find_lock: # Prevent issues with multiple processes
13795+
if self.undetectable and not (self.headless or self.headless2):
13796+
import Xlib.display
13797+
try:
13798+
self._xvfb_display = Display(
13799+
visible=True,
13800+
size=(1366, 768),
13801+
backend="xvfb",
13802+
use_xauth=True,
13803+
)
13804+
self._xvfb_display.start()
13805+
if "DISPLAY" not in os.environ.keys():
13806+
print(
13807+
"\nX11 display failed! Will use regular xvfb!"
13808+
)
13809+
self.__activate_standard_virtual_display()
13810+
except Exception as e:
13811+
if hasattr(e, "msg"):
13812+
print("\n" + str(e.msg))
13813+
else:
13814+
print(e)
1380213815
print("\nX11 display failed! Will use regular xvfb!")
1380313816
self.__activate_standard_virtual_display()
13804-
except Exception as e:
13805-
if hasattr(e, "msg"):
13806-
print("\n" + str(e.msg))
13807-
else:
13808-
print(e)
13809-
print("\nX11 display failed! Will use regular xvfb!")
13810-
self.__activate_standard_virtual_display()
13811-
return
13812-
pip_find_lock = fasteners.InterProcessLock(
13813-
constants.PipInstall.FINDLOCK
13814-
)
13815-
with pip_find_lock: # Prevent issues with multiple processes
13817+
return
1381613818
pyautogui_is_installed = False
1381713819
try:
1381813820
import pyautogui
@@ -13854,8 +13856,8 @@ def __activate_virtual_display_as_needed(self):
1385413856
print("\n" + str(e.msg))
1385513857
else:
1385613858
print(e)
13857-
else:
13858-
self.__activate_standard_virtual_display()
13859+
else:
13860+
self.__activate_standard_virtual_display()
1385913861

1386013862
def __ad_block_as_needed(self):
1386113863
"""This is an internal method for handling ad-blocking.

0 commit comments

Comments
 (0)