summaryrefslogtreecommitdiffstats
path: root/g4f/webdriver.py
diff options
context:
space:
mode:
authorH Lohaus <hlohaus@users.noreply.github.com>2024-01-26 07:54:13 +0100
committerGitHub <noreply@github.com>2024-01-26 07:54:13 +0100
commitfeb83c168b0a57ecd8c511aa654209c5f40da30e (patch)
tree84ef9a576064b7480e339426d9966b17a3102cad /g4f/webdriver.py
parentMerge pull request #1510 from hlohaus/sort (diff)
downloadgpt4free-feb83c168b0a57ecd8c511aa654209c5f40da30e.tar
gpt4free-feb83c168b0a57ecd8c511aa654209c5f40da30e.tar.gz
gpt4free-feb83c168b0a57ecd8c511aa654209c5f40da30e.tar.bz2
gpt4free-feb83c168b0a57ecd8c511aa654209c5f40da30e.tar.lz
gpt4free-feb83c168b0a57ecd8c511aa654209c5f40da30e.tar.xz
gpt4free-feb83c168b0a57ecd8c511aa654209c5f40da30e.tar.zst
gpt4free-feb83c168b0a57ecd8c511aa654209c5f40da30e.zip
Diffstat (limited to 'g4f/webdriver.py')
-rw-r--r--g4f/webdriver.py24
1 files changed, 17 insertions, 7 deletions
diff --git a/g4f/webdriver.py b/g4f/webdriver.py
index 85d6d695..d2009ddc 100644
--- a/g4f/webdriver.py
+++ b/g4f/webdriver.py
@@ -1,12 +1,20 @@
from __future__ import annotations
-from platformdirs import user_config_dir
-from selenium.webdriver.remote.webdriver import WebDriver
-from undetected_chromedriver import Chrome, ChromeOptions
-from selenium.webdriver.common.by import By
-from selenium.webdriver.support.ui import WebDriverWait
-from selenium.webdriver.support import expected_conditions as EC
+
+try:
+ from platformdirs import user_config_dir
+ from selenium.webdriver.remote.webdriver import WebDriver
+ from undetected_chromedriver import Chrome, ChromeOptions
+ from selenium.webdriver.common.by import By
+ from selenium.webdriver.support.ui import WebDriverWait
+ from selenium.webdriver.support import expected_conditions as EC
+ has_requirements = True
+except ImportError:
+ WebDriver = type
+ has_requirements = False
+
from os import path
from os import access, R_OK
+from .errors import MissingRequirementsError
from . import debug
try:
@@ -33,6 +41,8 @@ def get_browser(
Returns:
WebDriver: An instance of WebDriver configured with the specified options.
"""
+ if not has_requirements:
+ raise MissingRequirementsError('Install "undetected_chromedriver" and "platformdirs" package')
if user_data_dir is None:
user_data_dir = user_config_dir("g4f")
if user_data_dir and debug.logging:
@@ -144,7 +154,7 @@ class WebDriverSession:
Returns:
WebDriver: The reopened WebDriver instance.
"""
- user_data_dir = user_data_data_dir or self.user_data_dir
+ user_data_dir = user_data_dir or self.user_data_dir
if self.default_driver:
self.default_driver.quit()
if not virtual_display and self.virtual_display: