XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

1. Discover chromedriver dynamically with "which". 2. Use "finally" in WebDriverSession.__exit__

4c1708d7
technicca <cake3327@gmail.com>
提交于

代码差异

1 个文件 +6 -2
Modified g4f/webdriver.py +6 -2
@@ -15,6 +15,7 @@ except ImportError:
15 15 has_requirements = False
16 16
17 17 import time
18 from shutil import which
18 19 from os import path
19 20 from os import access, R_OK
20 21 from .errors import MissingRequirementsError
@@ -55,7 +56,9 @@ def get_browser(
55 56 if proxy:
56 57 options.add_argument(f'--proxy-server={proxy}')
57 58 # Check for system driver in docker
58 driver = '/usr/bin/chromedriver'
59 driver = which('chromedriver')
60 if not driver:
61 driver = '/usr/bin/chromedriver'
59 62 if not path.isfile(driver) or not access(driver, R_OK):
60 63 driver = None
61 64 return Chrome(
@@ -218,7 +221,8 @@ class WebDriverSession:
218 221 except Exception as e:
219 222 if debug.logging:
220 223 print(f"Error closing WebDriver: {e}")
221 self.default_driver.quit()
224 finally:
225 self.default_driver.quit()
222 226 if self.virtual_display:
223 227 self.virtual_display.stop()
224 228