summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH Lohaus <hlohaus@users.noreply.github.com>2024-01-29 00:15:49 +0100
committerGitHub <noreply@github.com>2024-01-29 00:15:49 +0100
commit3bb6560fcec5afcf6c537355635689e2e249b4be (patch)
tree7f98c96e3e4cc9d5ae9cc6f640edc6e8e30d64b5
parentMerge pull request #1522 from houtarchat-cyber/patch-1 (diff)
parent1. Discover chromedriver dynamically with "which". 2. Use "finally" in WebDriverSession.__exit__ (diff)
downloadgpt4free-3bb6560fcec5afcf6c537355635689e2e249b4be.tar
gpt4free-3bb6560fcec5afcf6c537355635689e2e249b4be.tar.gz
gpt4free-3bb6560fcec5afcf6c537355635689e2e249b4be.tar.bz2
gpt4free-3bb6560fcec5afcf6c537355635689e2e249b4be.tar.lz
gpt4free-3bb6560fcec5afcf6c537355635689e2e249b4be.tar.xz
gpt4free-3bb6560fcec5afcf6c537355635689e2e249b4be.tar.zst
gpt4free-3bb6560fcec5afcf6c537355635689e2e249b4be.zip
-rw-r--r--g4f/webdriver.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/g4f/webdriver.py b/g4f/webdriver.py
index ee03ff66..44765402 100644
--- a/g4f/webdriver.py
+++ b/g4f/webdriver.py
@@ -15,6 +15,7 @@ except ImportError:
has_requirements = False
import time
+from shutil import which
from os import path
from os import access, R_OK
from .errors import MissingRequirementsError
@@ -55,7 +56,9 @@ def get_browser(
if proxy:
options.add_argument(f'--proxy-server={proxy}')
# Check for system driver in docker
- driver = '/usr/bin/chromedriver'
+ driver = which('chromedriver')
+ if not driver:
+ driver = '/usr/bin/chromedriver'
if not path.isfile(driver) or not access(driver, R_OK):
driver = None
return Chrome(
@@ -218,7 +221,8 @@ class WebDriverSession:
except Exception as e:
if debug.logging:
print(f"Error closing WebDriver: {e}")
- self.default_driver.quit()
+ finally:
+ self.default_driver.quit()
if self.virtual_display:
self.virtual_display.stop()