Skip to content

Commit f46cca9

Browse files
committed
Fix PyAutoGUI targeting issue on Linux
1 parent 69f6ae8 commit f46cca9

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

seleniumbase/core/browser_launcher.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,13 +580,16 @@ def uc_open_with_cdp_mode(driver, url=None, **kwargs):
580580
headless = False
581581
headed = None
582582
xvfb = None
583+
xvfb_metrics = None
583584
binary_location = None
584585
if hasattr(sb_config, "headless"):
585586
headless = sb_config.headless
586587
if hasattr(sb_config, "headed"):
587588
headed = sb_config.headed
588589
if hasattr(sb_config, "xvfb"):
589590
xvfb = sb_config.xvfb
591+
if hasattr(sb_config, "xvfb_metrics"):
592+
xvfb_metrics = sb_config.xvfb_metrics
590593
if hasattr(sb_config, "binary_location"):
591594
binary_location = sb_config.binary_location
592595

@@ -599,6 +602,7 @@ def uc_open_with_cdp_mode(driver, url=None, **kwargs):
599602
headless=headless,
600603
headed=headed,
601604
xvfb=xvfb,
605+
xvfb_metrics=xvfb_metrics,
602606
browser_executable_path=binary_location,
603607
)
604608
)
@@ -963,6 +967,11 @@ def __install_pyautogui_if_missing():
963967
backend="xvfb",
964968
use_xauth=True,
965969
)
970+
if "--debug-display" in sys.argv:
971+
print(
972+
"Starting VDisplay from browser_launcher: (%s, %s)"
973+
% (xvfb_width, xvfb_height)
974+
)
966975
_xvfb_display.start()
967976
sb_config._virtual_display = _xvfb_display
968977
sb_config.headless_active = True

seleniumbase/core/sb_cdp.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,6 +1439,10 @@ def __install_pyautogui_if_missing(self):
14391439
shared_utils.is_linux()
14401440
and (not sb_config.headed or sb_config.xvfb)
14411441
and not driver.config.headless
1442+
and (
1443+
not hasattr(sb_config, "_virtual_display")
1444+
or not sb_config._virtual_display
1445+
)
14421446
):
14431447
from sbvirtualdisplay import Display
14441448
xvfb_width = 1366
@@ -1466,6 +1470,11 @@ def __install_pyautogui_if_missing(self):
14661470
backend="xvfb",
14671471
use_xauth=True,
14681472
)
1473+
if "--debug-display" in sys.argv:
1474+
print(
1475+
"Starting VDisplay from sb_cdp: (%s, %s)"
1476+
% (xvfb_width, xvfb_height)
1477+
)
14691478
xvfb_display.start()
14701479

14711480
def __get_configured_pyautogui(self, pyautogui_copy):

seleniumbase/fixtures/base_case.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14164,7 +14164,13 @@ def __activate_virtual_display(self):
1416414164
backend="xvfb",
1416514165
use_xauth=True,
1416614166
)
14167+
if "--debug-display" in sys.argv:
14168+
print(
14169+
"Starting VDisplay from base_case: (%s, %s)"
14170+
% (self._xvfb_width, self._xvfb_height)
14171+
)
1416714172
self._xvfb_display.start()
14173+
sb_config._virtual_display = self._xvfb_display
1416814174
if "DISPLAY" not in os.environ.keys():
1416914175
print(
1417014176
"\nX11 display failed! Will use regular xvfb!"

seleniumbase/undetected/cdp_driver/cdp_util.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,14 @@ def __activate_virtual_display_as_needed(
5151
headless, headed, xvfb, xvfb_metrics
5252
):
5353
"""This is only needed on Linux."""
54-
if IS_LINUX and (not headed or xvfb):
54+
if (
55+
IS_LINUX
56+
and (not headed or xvfb)
57+
and (
58+
not hasattr(sb_config, "_virtual_display")
59+
or not sb_config._virtual_display
60+
)
61+
):
5562
from sbvirtualdisplay import Display
5663
pip_find_lock = fasteners.InterProcessLock(
5764
constants.PipInstall.FINDLOCK
@@ -87,6 +94,11 @@ def __activate_virtual_display_as_needed(
8794
backend="xvfb",
8895
use_xauth=True,
8996
)
97+
if "--debug-display" in sys.argv:
98+
print(
99+
"Starting VDisplay from cdp_util: (%s, %s)"
100+
% (_xvfb_width, _xvfb_height)
101+
)
90102
_xvfb_display.start()
91103
if "DISPLAY" not in os.environ.keys():
92104
print(

0 commit comments

Comments
 (0)