diff --git a/seleniumbase/core/browser_launcher.py b/seleniumbase/core/browser_launcher.py
index f94c14be..8d3e019e 100644
--- a/seleniumbase/core/browser_launcher.py
+++ b/seleniumbase/core/browser_launcher.py
@@ -18,6 +18,7 @@ from selenium.webdriver.safari.service import Service as SafariService
from seleniumbase import drivers # webdriver storage folder for SeleniumBase
from seleniumbase import extensions # browser extensions storage folder
from seleniumbase.config import settings
+from seleniumbase.core import detect_b_ver
from seleniumbase.core import download_helper
from seleniumbase.core import proxy_helper
from seleniumbase.fixtures import constants
@@ -190,8 +191,10 @@ def has_cf(text):
if (
"
Just a moment..." in text
or "403 Forbidden" in text
+ or "Permission Denied" in text
or 'id="challenge-error-text"' in text
or 'action="/?__cf_chl_f_tk' in text
+ or 'src="chromedriver.js"' in text
or 'id="challenge-form"' in text
or "window._cf_chl_opt" in text
):
@@ -312,7 +315,7 @@ def get_valid_binary_names_for_browser(browser):
else:
raise Exception("Could not determine OS, or unsupported!")
else:
- raise Exception("Invalid combination for os browser binaries!")
+ raise Exception("Invalid combination for OS browser binaries!")
def _repair_chromedriver(chrome_options, headless_options, mcv=None):
@@ -870,7 +873,12 @@ def _set_chrome_options(
)
except Exception:
pass
- if len(chromium_arg_item) >= 3:
+ if "set-binary" in chromium_arg_item and not binary_location:
+ br_app = "google-chrome"
+ binary_loc = detect_b_ver.get_binary_location(br_app)
+ if os.path.exists(binary_loc):
+ binary_location = binary_loc
+ elif len(chromium_arg_item) >= 3:
chrome_options.add_argument(chromium_arg_item)
if devtools and not headless:
chrome_options.add_argument("--auto-open-devtools-for-tabs")
@@ -1166,6 +1174,8 @@ def get_driver(
"that includes the driver filename at the end of it!"
"\n(Will use default settings...)\n" % binary_location
)
+ # Example of a valid binary location path - MacOS:
+ # "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
binary_location = None
else:
binary_name = binary_location.split("/")[-1].split("\\")[-1]
@@ -2251,8 +2261,6 @@ def get_local_driver(
use_version = "latest"
major_edge_version = None
try:
- from seleniumbase.core import detect_b_ver
-
if binary_location:
try:
major_edge_version = (
@@ -2480,8 +2488,6 @@ def get_local_driver(
)
edge_options.add_argument("--disable-browser-side-navigation")
edge_options.add_argument("--disable-translate")
- if binary_location:
- edge_options.binary_location = binary_location
if not enable_ws:
edge_options.add_argument("--disable-web-security")
edge_options.add_argument("--homepage=about:blank")
@@ -2585,8 +2591,15 @@ def get_local_driver(
chromium_arg_item = "-" + chromium_arg_item
else:
chromium_arg_item = "--" + chromium_arg_item
- if len(chromium_arg_item) >= 3:
+ if "set-binary" in chromium_arg_item and not binary_location:
+ br_app = "edge"
+ binary_loc = detect_b_ver.get_binary_location(br_app)
+ if os.path.exists(binary_loc):
+ binary_location = binary_loc
+ elif len(chromium_arg_item) >= 3:
edge_options.add_argument(chromium_arg_item)
+ if binary_location:
+ edge_options.binary_location = binary_location
if selenium4_or_newer:
try:
service = EdgeService(
@@ -2884,8 +2897,6 @@ def get_local_driver(
major_chrome_version = None
if selenium4_or_newer:
try:
- from seleniumbase.core import detect_b_ver
-
if binary_location:
try:
major_chrome_version = (
diff --git a/seleniumbase/core/detect_b_ver.py b/seleniumbase/core/detect_b_ver.py
index b269133b..08ebcbb2 100644
--- a/seleniumbase/core/detect_b_ver.py
+++ b/seleniumbase/core/detect_b_ver.py
@@ -106,6 +106,68 @@ def windows_browser_apps_to_cmd(*apps):
return '%s -NoProfile "%s"' % (powershell, script)
+def get_binary_location(browser_type):
+ cmd_mapping = {
+ ChromeType.GOOGLE: {
+ OSType.LINUX: linux_browser_apps_to_cmd(
+ "google-chrome-stable",
+ "google-chrome",
+ "chrome",
+ "chromium",
+ "chromium-browser",
+ "google-chrome-beta",
+ "google-chrome-dev",
+ "google-chrome-unstable",
+ ),
+ OSType.MAC: r"/Applications/Google Chrome.app"
+ r"/Contents/MacOS/Google Chrome",
+ OSType.WIN: windows_browser_apps_to_cmd(
+ r'(Get-Item -Path "$env:PROGRAMFILES\Google\Chrome'
+ r'\Application\chrome.exe")',
+ r'(Get-Item -Path "$env:PROGRAMFILES (x86)\Google\Chrome'
+ r'\Application\chrome.exe")',
+ r'(Get-Item -Path "$env:LOCALAPPDATA\Google\Chrome'
+ r'\Application\chrome.exe")',
+ ),
+ },
+ ChromeType.MSEDGE: {
+ OSType.LINUX: linux_browser_apps_to_cmd(
+ "microsoft-edge-stable",
+ "microsoft-edge",
+ "microsoft-edge-beta",
+ "microsoft-edge-dev",
+ ),
+ OSType.MAC: r"/Applications/Microsoft Edge.app"
+ r"/Contents/MacOS/Microsoft Edge",
+ OSType.WIN: windows_browser_apps_to_cmd(
+ # stable edge
+ r'(Get-Item -Path "$env:PROGRAMFILES\Microsoft\Edge'
+ r'\Application\msedge.exe")',
+ r'(Get-Item -Path "$env:PROGRAMFILES (x86)\Microsoft'
+ r'\Edge\Application\msedge.exe")',
+ # beta edge
+ r'(Get-Item -Path "$env:LOCALAPPDATA\Microsoft\Edge Beta'
+ r'\Application\msedge.exe")',
+ r'(Get-Item -Path "$env:PROGRAMFILES\Microsoft\Edge Beta'
+ r'\Application\msedge.exe")',
+ r'(Get-Item -Path "$env:PROGRAMFILES (x86)\Microsoft\Edge Beta'
+ r'\Application\msedge.exe")',
+ # dev edge
+ r'(Get-Item -Path "$env:LOCALAPPDATA\Microsoft\Edge Dev'
+ r'\Application\msedge.exe")',
+ r'(Get-Item -Path "$env:PROGRAMFILES\Microsoft\Edge Dev'
+ r'\Application\msedge.exe")',
+ r'(Get-Item -Path "$env:PROGRAMFILES (x86)\Microsoft\Edge Dev'
+ r'\Application\msedge.exe")',
+ # canary edge
+ r'(Get-Item -Path "$env:LOCALAPPDATA\Microsoft\Edge SxS'
+ r'\Application\msedge.exe")',
+ ),
+ },
+ }
+ return cmd_mapping[browser_type][os_name()]
+
+
def get_browser_version_from_binary(binary_location):
try:
if binary_location.count(r"\ ") != binary_location.count(" "):
@@ -118,18 +180,19 @@ def get_browser_version_from_binary(binary_location):
return None
-def get_browser_version_from_os(browser_type=None):
+def get_browser_version_from_os(browser_type):
"""Return installed browser version."""
cmd_mapping = {
ChromeType.GOOGLE: {
OSType.LINUX: linux_browser_apps_to_cmd(
- "google-chrome",
"google-chrome-stable",
+ "google-chrome",
"chrome",
"chromium",
+ "chromium-browser",
"google-chrome-beta",
"google-chrome-dev",
- "chromium-browser",
+ "google-chrome-unstable",
),
OSType.MAC: r"/Applications/Google\ Chrome.app"
r"/Contents/MacOS/Google\ Chrome --version",
@@ -149,8 +212,8 @@ def get_browser_version_from_os(browser_type=None):
},
ChromeType.MSEDGE: {
OSType.LINUX: linux_browser_apps_to_cmd(
- "microsoft-edge",
"microsoft-edge-stable",
+ "microsoft-edge",
"microsoft-edge-beta",
"microsoft-edge-dev",
),
diff --git a/seleniumbase/fixtures/constants.py b/seleniumbase/fixtures/constants.py
index b91d32e1..3494b136 100644
--- a/seleniumbase/fixtures/constants.py
+++ b/seleniumbase/fixtures/constants.py
@@ -360,23 +360,25 @@ class ValidBrowsers:
class ValidBinaries:
valid_chrome_binaries_on_linux = [
- "google-chrome",
"google-chrome-stable",
+ "google-chrome",
"chrome",
"chromium",
+ "chromium-browser",
"google-chrome-beta",
"google-chrome-dev",
- "chromium-browser",
+ "google-chrome-unstable",
]
valid_edge_binaries_on_linux = [
- "microsoft-edge",
"microsoft-edge-stable",
+ "microsoft-edge",
"microsoft-edge-beta",
"microsoft-edge-dev",
]
valid_chrome_binaries_on_macos = [
"Google Chrome",
"Chromium",
+ "Google Chrome for Testing",
]
valid_edge_binaries_on_macos = [
"Microsoft Edge",
diff --git a/seleniumbase/undetected/__init__.py b/seleniumbase/undetected/__init__.py
index 34ae3ba8..b1dcd745 100644
--- a/seleniumbase/undetected/__init__.py
+++ b/seleniumbase/undetected/__init__.py
@@ -506,13 +506,14 @@ def find_chrome_executable():
if IS_POSIX:
for item in os.environ.get("PATH").split(os.pathsep):
for subitem in (
- "google-chrome",
"google-chrome-stable",
+ "google-chrome",
"chrome",
"chromium",
+ "chromium-browser",
"google-chrome-beta",
"google-chrome-dev",
- "chromium-browser",
+ "google-chrome-unstable",
):
candidates.add(os.sep.join((item, subitem)))
if "darwin" in sys.platform: