Spaces:
Running
Running
Download src/browser_automation_agent/browser/selenium_firefox_probe.py from sitcod3/dracull-agent: direct link, hf CLI and curl.
- Browser
- Download file 2.83 kB
-
https://huggingface.co/spaces/sitcod3/dracull-agent/resolve/main/src/browser_automation_agent/browser/selenium_firefox_probe.py
- Command line
-
hf download hf://spaces/sitcod3/dracull-agent/src/browser_automation_agent/browser/selenium_firefox_probe.py
-
curl -L -o selenium_firefox_probe.py https://huggingface.co/spaces/sitcod3/dracull-agent/resolve/main/src/browser_automation_agent/browser/selenium_firefox_probe.py
2.83 kB
| """One-shot experiment: does Selenium-driven Firefox survive on this machine? | |
| Playwright's juggler-piped Firefox aborts ~2.6s after launch (denied child | |
| spawns -> 0xC0000005). Selenium launches Firefox through geckodriver with a | |
| normal startup path — same binary, no juggler. There is no installed Mozilla | |
| Firefox on this box, so the experiment points Selenium at the Playwright- | |
| downloaded firefox.exe (same engine build). | |
| """ | |
| from __future__ import annotations | |
| import time | |
| from pathlib import Path | |
| FIREFOX_BIN = ( | |
| Path(__file__).resolve().parents[3] | |
| / ".browser-runtime" / "playwright-browsers" / "firefox-1555" / "firefox" / "firefox.exe" | |
| ) | |
| MOZ_ENV = { | |
| "MOZ_DISABLE_CONTENT_SANDBOX": "1", | |
| "MOZ_DISABLE_GFX_SANDBOX": "1", | |
| "MOZ_DISABLE_RDD_SANDBOX": "1", | |
| "MOZ_DISABLE_SOCKET_PROCESS_SANDBOX": "1", | |
| } | |
| def main() -> int: | |
| import os | |
| from selenium import webdriver | |
| # Selenium Manager caches drivers under ~/.cache/selenium and extracts its | |
| # helper under %TEMP% — both access-denied for this account. Redirect both | |
| # into the app runtime root (same workaround as the Playwright manager). | |
| runtime = FIREFOX_BIN.parents[2] | |
| cache_dir = runtime / "selenium-cache" | |
| temp_dir = runtime / "tmp" | |
| for directory in (cache_dir, temp_dir): | |
| directory.mkdir(parents=True, exist_ok=True) | |
| os.environ["SE_CACHE_DIRECTORY"] = str(cache_dir) | |
| os.environ["TMP"] = str(temp_dir) | |
| os.environ["TEMP"] = str(temp_dir) | |
| if not FIREFOX_BIN.exists(): | |
| print(f"firefox binary missing: {FIREFOX_BIN}") | |
| return 2 | |
| options = webdriver.FirefoxOptions() | |
| options.binary_location = str(FIREFOX_BIN) | |
| options.add_argument("-headless") | |
| options.set_preference("layers.gpu-process.enabled", False) | |
| options.set_preference("gfx.webrender.software", True) | |
| driver = webdriver.Firefox(options=options) | |
| try: | |
| driver.get("https://example.com/") | |
| title = driver.title | |
| time.sleep(6) # outlive the ~2.6s playwright-path bomb | |
| alive = "no exception on any command" | |
| driver.get("https://example.com/") # second navigation after the window | |
| title2 = driver.title | |
| body = driver.find_element("css selector", "body").text[:60] | |
| print(f"ALIVE after 6s | title={title!r}/{title2!r} | body={body!r} | {alive}") | |
| return 0 | |
| except Exception as exc: # noqa: BLE001 | |
| print(f"DIED: {type(exc).__name__}: {str(exc)[:150]}") | |
| return 1 | |
| finally: | |
| try: | |
| driver.quit() | |
| except Exception as exc: # noqa: BLE001 — teardown must never mask the result | |
| print(f"quit failed: {type(exc).__name__}: {str(exc)[:80]}") | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |