{"record":{"id":"7eec6eaec83f311a","repo":"feder-cr/Jobs_Applier_AI_Agent_AIHawk","slug":"failed-to-initialize-browser-str-e","errorCode":null,"errorMessage":"Failed to initialize browser: {str(e)}","messagePattern":"Failed to initialize browser: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"critical","filePath":"src/utils/chrome_utils.py","lineNumber":47,"sourceCode":"    options.add_argument(\"--disable-animations\")\n    options.add_argument(\"--disable-cache\")\n    options.add_argument(\"--incognito\")\n    options.add_argument(\"--allow-file-access-from-files\")  # Consente l'accesso ai file locali\n    options.add_argument(\"--disable-web-security\")         # Disabilita la sicurezza web\n    logger.debug(\"Using Chrome in incognito mode\")\n    \n    return options\n\ndef init_browser() -> webdriver.Chrome:\n    try:\n        options = chrome_browser_options()\n        # Use webdriver_manager to handle ChromeDriver\n        driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), options=options)\n        logger.debug(\"Chrome browser initialized successfully.\")\n        return driver\n    except Exception as e:\n        logger.error(f\"Failed to initialize browser: {str(e)}\")\n        raise RuntimeError(f\"Failed to initialize browser: {str(e)}\")\n\n\n\ndef HTML_to_PDF(html_content, driver):\n    \"\"\"\n    Converte una stringa HTML in un PDF e restituisce il PDF come stringa base64.\n\n    :param html_content: Stringa contenente il codice HTML da convertire.\n    :param driver: Istanza del WebDriver di Selenium.\n    :return: Stringa base64 del PDF generato.\n    :raises ValueError: Se l'input HTML non è una stringa valida.\n    :raises RuntimeError: Se si verifica un'eccezione nel WebDriver.\n    \"\"\"\n    # Validazione del contenuto HTML\n    if not isinstance(html_content, str) or not html_content.strip():\n        raise ValueError(\"Il contenuto HTML deve essere una stringa non vuota.\")\n\n    # Codifica l'HTML in un URL di tipo data","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/feder-cr/Jobs_Applier_AI_Agent_AIHawk/blob/79155b52faccfbd19b834680af285eac70dd2df4/src/utils/chrome_utils.py#L29-L65","documentation":"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.).","triggerScenarios":"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.","commonSituations":"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).","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=...)."],"exampleFix":"// before\noptions = webdriver.ChromeOptions()\ndriver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), options=options)\n\n# after (headless/CI-safe)\noptions = webdriver.ChromeOptions()\noptions.add_argument('--headless=new')\noptions.add_argument('--no-sandbox')\noptions.add_argument('--disable-dev-shm-usage')\ndriver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), options=options)","handlingStrategy":"retry","validationCode":"import shutil\nif not shutil.which('google-chrome') and not shutil.which('chromium') and not shutil.which('chromium-browser'):\n    raise EnvironmentError('Chrome/Chromium binary not found on PATH')","typeGuard":null,"tryCatchPattern":"from selenium.common.exceptions import WebDriverException\n\nfor attempt in range(2):\n    try:\n        driver = init_browser()\n        break\n    except RuntimeError as e:\n        logger.error(\"browser init failed (attempt %d): %s\", attempt + 1, e)\n        if attempt == 1:\n            raise\n        # clear webdriver-manager cache before retrying\n        shutil.rmtree(os.path.expanduser('~/.wdm'), ignore_errors=True)","preventionTips":["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"],"tags":["selenium","chrome","webdriver","environment","pdf"],"backgroundTag":"selenium-chrome-init-failure","analyzedSha":"79155b52faccfbd19b834680af285eac70dd2df4","analyzedAt":"2026-08-28T14:10:26.659Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}