{"record":{"id":"37fe3ec87d6f3540","repo":"unclecode/crawl4ai","slug":"psutil-not-available-cannot-clean-old-browser","errorCode":null,"errorMessage":"psutil not available, cannot clean old browser","messagePattern":"psutil not available, cannot clean old browser","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"crawl4ai/browser_manager.py","lineNumber":204,"sourceCode":"\n        # Create temp dir if needed\n        if not self.user_data_dir:\n            self.temp_dir = tempfile.mkdtemp(prefix=\"browser-profile-\")\n            self.user_data_dir = self.temp_dir\n\n        # Get browser path and args based on OS and browser type\n        # browser_path = self._get_browser_path()\n        args = await self._get_browser_args()\n        \n        if self.browser_config.extra_args:\n            args.extend(self.browser_config.extra_args)\n            \n\n        # ── make sure no old Chromium instance is owning the same port/profile ──\n        try:\n            if sys.platform == \"win32\":\n                if psutil is None:\n                    raise RuntimeError(\"psutil not available, cannot clean old browser\")\n                for p in psutil.process_iter([\"pid\", \"name\", \"cmdline\"]):\n                    cl = \" \".join(p.info.get(\"cmdline\") or [])\n                    if (\n                        f\"--remote-debugging-port={self.debugging_port}\" in cl\n                        and f\"--user-data-dir={self.user_data_dir}\" in cl\n                    ):\n                        p.kill()\n                        p.wait(timeout=5)\n            else:  # macOS / Linux\n                # kill any process listening on the same debugging port\n                try:\n                    pids = (\n                        subprocess.check_output(\n                            shlex.split(f\"lsof -t -i:{self.debugging_port}\"),\n                            stderr=subprocess.DEVNULL,\n                        )\n                        .decode()\n                        .strip()","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/unclecode/crawl4ai/blob/7e801521428ee12509994d39151006f64055ebe3/crawl4ai/browser_manager.py#L186-L222","documentation":"On Windows only, BrowserManager kills stale Chromium processes that hold the same --remote-debugging-port/--user-data-dir before launching a new browser. That cleanup requires psutil; if psutil was not installed (it is an optional dependency), it raises this RuntimeError instead of proceeding.","triggerScenarios":"Windows + browser_config.use_managed_browser (or a fixed debugging_port) + psutil missing from the environment. The check is explicit: sys.platform == 'win32' and psutil is None.","commonSituations":"Installing crawl4ai without extras on Windows; slim Docker/CI images based on windows containers lacking psutil; uninstalling psutil after install; using headless=False with a persistent user-data-dir on Windows.","solutions":["pip install psutil (or reinstall crawl4ai with the recommended extras).","Alternatively change browser_config so no stale-process cleanup is needed: use a different debugging_port and/or a fresh user_data_dir per run.","Kill the leftover Chrome/Chromium process manually (taskkill) that owns the port/profile, though the error will persist until psutil is installed."],"exampleFix":"# before (env lacking psutil)\n# RuntimeError: psutil not available, cannot clean old browser\n\n# after\n# pip install psutil\nbrowser_config = BrowserConfig(use_managed_browser=True, debugging_port=9222)","handlingStrategy":"validation","validationCode":"import sys\nif sys.platform == 'win32':\n    try:\n        import psutil  # noqa: F401\n    except ImportError:\n        raise SystemExit('pip install psutil before using managed browser on Windows')","typeGuard":null,"tryCatchPattern":"try:\n    async with AsyncWebCrawler(config=browser_config) as c:\n        ...\nexcept Exception as e:\n    if 'psutil not available' in str(e):\n        subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'psutil'])\n        raise SystemExit('psutil installed; rerun the program')\n    raise","preventionTips":["Add psutil to your requirements on Windows deployments.","Use unique debugging_port/user_data_dir per run to avoid stale-process cleanup.","Pin crawl4ai extras in Dockerfiles for Windows containers."],"tags":["windows","browser-manager","dependencies","psutil"],"backgroundTag":null,"analyzedSha":"7e801521428ee12509994d39151006f64055ebe3","analyzedAt":"2026-08-14T20:46:20.673Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}