feder-cr/Jobs_Applier_AI_Agent_AIHawk · critical · RuntimeError
Failed to initialize browser: {str(e)}
Error message
Failed to initialize browser: {str(e)} What it means
Raised when webdriver.Chrome() fails during initialization — ChromeDriverManager().install() or Chrome startup threw (driver not installed, Chrome binary missing, version mismatch, bad options). The original exception is logged and re-wrapped as RuntimeError. Used by the PDF-generation pipeline (create_resume_pdf, create_cover_letter, etc.).
Source
Thrown at src/utils/chrome_utils.py:47
options.add_argument("--disable-animations")
options.add_argument("--disable-cache")
options.add_argument("--incognito")
options.add_argument("--allow-file-access-from-files") # Consente l'accesso ai file locali
options.add_argument("--disable-web-security") # Disabilita la sicurezza web
logger.debug("Using Chrome in incognito mode")
return options
def init_browser() -> webdriver.Chrome:
try:
options = chrome_browser_options()
# Use webdriver_manager to handle ChromeDriver
driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), options=options)
logger.debug("Chrome browser initialized successfully.")
return driver
except Exception as e:
logger.error(f"Failed to initialize browser: {str(e)}")
raise RuntimeError(f"Failed to initialize browser: {str(e)}")
def HTML_to_PDF(html_content, driver):
"""
Converte una stringa HTML in un PDF e restituisce il PDF come stringa base64.
:param html_content: Stringa contenente il codice HTML da convertire.
:param driver: Istanza del WebDriver di Selenium.
:return: Stringa base64 del PDF generato.
:raises ValueError: Se l'input HTML non è una stringa valida.
:raises RuntimeError: Se si verifica un'eccezione nel WebDriver.
"""
# Validazione del contenuto HTML
if not isinstance(html_content, str) or not html_content.strip():
raise ValueError("Il contenuto HTML deve essere una stringa non vuota.")
# Codifica l'HTML in un URL di tipo dataView on GitHub (pinned to 79155b52fa)
Solutions
- Check the logged original exception (`logger.error` line) — it distinguishes download failure vs startup failure.
- Install/verify Chrome and matching driver: google-chrome --version, and let webdriver-manager refresh its cache (rm -rf ~/.wdm).
- If behind a proxy, export HTTPS_PROXY or pass driver config to ChromeDriverManager.
- In Docker/CI, install chromium + deps and add options.add_argument('--no-sandbox') / '--headless=new' / '--disable-dev-shm-usage'.
- Pin a known-good Chrome + ChromeDriver pair, or switch to webdriver_manager.chrome.ChromeDriverManager(driver_version=...).
Example fix
// before
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), options=options)
# after (headless/CI-safe)
options = webdriver.ChromeOptions()
options.add_argument('--headless=new')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), options=options) Defensive patterns
Strategy: retry
Validate before calling
import shutil
if not shutil.which('google-chrome') and not shutil.which('chromium') and not shutil.which('chromium-browser'):
raise EnvironmentError('Chrome/Chromium binary not found on PATH') Try / catch
from selenium.common.exceptions import WebDriverException
for attempt in range(2):
try:
driver = init_browser()
break
except RuntimeError as e:
logger.error("browser init failed (attempt %d): %s", attempt + 1, e)
if attempt == 1:
raise
# clear webdriver-manager cache before retrying
shutil.rmtree(os.path.expanduser('~/.wdm'), ignore_errors=True) Prevention
- Pre-install Chrome + matching driver in CI/Docker images
- Add --headless=new, --no-sandbox, --disable-dev-shm-usage in containers
- Clear the ~/.wdm cache when Chrome updates
- Configure proxy env vars for webdriver-manager downloads
When it happens
Trigger: webdriver.Chrome(ChromeService(ChromeDriverManager().install()), options) failing: no Chrome installed, ChromeDriver download blocked (no network/proxy), ChromeDriver != Chrome version mismatch, headless flags unsupported on the installed Chrome.
Common situations: CI/Docker images without Chrome; corporate proxies blocking the driver download from googlechromelabs; Chrome auto-updated past the cached driver; running as root without --no-sandbox; Linux missing shared libs (libnss3, libgbm).
Related errors
- You must choose a style before generating the PDF.
- Il contenuto HTML deve essere una stringa non vuota.
AI-assisted analysis of feder-cr/Jobs_Applier_AI_Agent_AIHawk@79155b52fa (2026-08-28).
Data as JSON: /api/errors/7eec6eaec83f311a.
Report an issue: GitHub.