Skip to content

Commit 8fa06b7

Browse files
committed
Automatically repair chromedriver to match Chrome on Linux
1 parent 98031c5 commit 8fa06b7

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

seleniumbase/core/browser_launcher.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1704,7 +1704,46 @@ def get_local_driver(
17041704
else: # Running headless on Linux
17051705
try:
17061706
return webdriver.Chrome(options=chrome_options)
1707-
except Exception:
1707+
except Exception as e:
1708+
auto_upgrade_chromedriver = False
1709+
if "This version of ChromeDriver only supports" in e.msg:
1710+
auto_upgrade_chromedriver = True
1711+
elif "Chrome version must be between" in e.msg:
1712+
auto_upgrade_chromedriver = True
1713+
if auto_upgrade_chromedriver:
1714+
args = " ".join(sys.argv)
1715+
if (
1716+
"-n" in sys.argv
1717+
or " -n=" in args
1718+
or args == "-c"
1719+
):
1720+
import fasteners
1721+
1722+
chromedr_fixing_lock = fasteners.InterProcessLock(
1723+
constants.MultiBrowser.CHROMEDRIVER_FIXING_LOCK
1724+
)
1725+
with chromedr_fixing_lock:
1726+
if not _was_chromedriver_repaired():
1727+
try:
1728+
_repair_chromedriver(
1729+
chrome_options, chrome_options
1730+
)
1731+
_mark_chromedriver_repaired()
1732+
except Exception:
1733+
pass
1734+
else:
1735+
if not _was_chromedriver_repaired():
1736+
try:
1737+
_repair_chromedriver(
1738+
chrome_options, chrome_options
1739+
)
1740+
except Exception:
1741+
pass
1742+
_mark_chromedriver_repaired()
1743+
try:
1744+
return webdriver.Chrome(options=chrome_options)
1745+
except Exception:
1746+
pass
17081747
# Use the virtual display on Linux during headless errors
17091748
logging.debug(
17101749
"\nWarning: Chrome failed to launch in"

0 commit comments

Comments
 (0)