Skip to content

Commit 04c1655

Browse files
committed
Better error-handling for headless mode on Linux
1 parent eaf64b4 commit 04c1655

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

seleniumbase/core/browser_launcher.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,18 @@ def get_local_driver(
721721
print("\nWarning: chromedriver not found. Installing now:")
722722
sb_install.main(override="chromedriver")
723723
sys.argv = sys_args # Put back the original sys args
724-
return webdriver.Chrome(options=chrome_options)
724+
if not headless or "linux" not in PLATFORM:
725+
return webdriver.Chrome(options=chrome_options)
726+
else: # Running headless on Linux
727+
try:
728+
return webdriver.Chrome(options=chrome_options)
729+
except Exception:
730+
# Use the virtual display on Linux during headless errors
731+
logging.debug("\nWarning: Chrome failed to launch in"
732+
" headless mode. Attempting to use the"
733+
" SeleniumBase virtual display on Linux...")
734+
chrome_options.headless = False
735+
return webdriver.Chrome(options=chrome_options)
725736
except Exception as e:
726737
if headless:
727738
raise Exception(e)

0 commit comments

Comments
 (0)