Skip to content

Commit

Permalink
allow customizing selenium driver/opts
Browse files Browse the repository at this point in the history
  • Loading branch information
thehunmonkgroup committed Apr 28, 2023
1 parent 1772a01 commit 8fad55b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ OPENAI_API_KEY=your-openai-api-key
# BROWSE_CHUNK_MAX_LENGTH=3000
## BROWSE_SPACY_LANGUAGE_MODEL is used to split sentences. Install additional languages via pip, and set the model name here. Example Chinese: python -m spacy download zh_core_web_sm
# BROWSE_SPACY_LANGUAGE_MODEL=en_core_web_sm
# DRIVER_EXECUTABLE_PATH - Path to the browser driver executable (e.g. chromedriver)
# Leave blank for default driver.
# DRIVER_EXECUTABLE_PATH=
# DRIVER_EXTRA_OPTIONS - Extra options to pass to the browser driver (e.g. --no-sandbox)
# Separate mutiple options with a space.
# DRIVER_EXTRA_OPTIONS=""

### GOOGLE
## GOOGLE_API_KEY - Google API key (Example: my-google-api-key)
Expand Down
13 changes: 7 additions & 6 deletions autogpt/commands/web_selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,30 +76,31 @@ def scrape_text_with_selenium(url: str) -> tuple[WebDriver, str]:
options.add_argument(
"user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.5615.49 Safari/537.36"
)
for opt in CFG.driver_extra_options.split():
options.add_argument(opt)

if CFG.selenium_web_browser == "firefox":
if CFG.selenium_headless:
options.headless = True
options.add_argument("--disable-gpu")
executable_path = CFG.driver_executable_path or GeckoDriverManager().install()
driver = webdriver.Firefox(
executable_path=GeckoDriverManager().install(), options=options
executable_path=executable_path, options=options
)
elif CFG.selenium_web_browser == "safari":
# Requires a bit more setup on the users end
# See https://developer.apple.com/documentation/webkit/testing_with_webdriver_in_safari
driver = webdriver.Safari(options=options)
else:
options.add_argument("--no-sandbox")
if platform == "linux" or platform == "linux2":
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--remote-debugging-port=9222")

options.add_argument("--no-sandbox")
if CFG.selenium_headless:
options.add_argument("--headless=new")
options.add_argument("--disable-gpu")

chromium_driver_path = Path("/usr/bin/chromedriver")

driver_executable_path = CFG.driver_executable_path or "/usr/bin/chromedriver"
chromium_driver_path = Path(driver_executable_path)
driver = webdriver.Chrome(
executable_path=chromium_driver_path
if chromium_driver_path.exists()
Expand Down
2 changes: 2 additions & 0 deletions autogpt/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ def __init__(self) -> None:
# Selenium browser settings
self.selenium_web_browser = os.getenv("USE_WEB_BROWSER", "chrome")
self.selenium_headless = os.getenv("HEADLESS_BROWSER", "True") == "True"
self.driver_executable_path = os.getenv("DRIVER_EXECUTABLE_PATH", "")
self.driver_extra_options = os.getenv("DRIVER_EXTRA_OPTIONS", "")

# User agent header to use when making HTTP requests
# Some websites might just completely deny request with an error code if
Expand Down

0 comments on commit 8fad55b

Please sign in to comment.