{"record":{"id":"b72e8fac05f444a0","repo":"unclecode/crawl4ai","slug":"msvcrt-module-not-available-on-this-platform","errorCode":null,"errorMessage":"msvcrt module not available on this platform","messagePattern":"msvcrt module not available on this platform","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"warning","filePath":"crawl4ai/browser_profiler.py","lineNumber":201,"sourceCode":"    def _is_linux(self) -> bool:\n        \"\"\"Check if running on Linux platform.\"\"\"\n        return sys.platform.startswith('linux')\n    \n    def _get_quit_message(self, tag: str) -> str:\n        \"\"\"Get appropriate quit message based on context.\"\"\"\n        if tag == \"PROFILE\":\n            return \"Closing browser and saving profile...\"\n        elif tag == \"CDP\":\n            return \"Closing browser...\"\n        else:\n            return \"Closing browser...\"\n    \n    async def _listen_windows(self, user_done_event, check_browser_process, tag: str):\n        \"\"\"Windows-specific keyboard listener using msvcrt.\"\"\"\n        try:\n            import msvcrt\n        except ImportError:\n            raise ImportError(\"msvcrt module not available on this platform\")\n        \n        while True:\n            try:\n                # Check for keyboard input\n                if msvcrt.kbhit():\n                    raw = msvcrt.getch()\n                    \n                    # Handle Unicode decoding more robustly\n                    key = None\n                    try:\n                        key = raw.decode(\"utf-8\")\n                    except UnicodeDecodeError:\n                        try:\n                            # Try different encodings\n                            key = raw.decode(\"latin1\")\n                        except UnicodeDecodeError:\n                            # Skip if we can't decode\n                            continue","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/unclecode/crawl4ai/blob/7e801521428ee12509994d39151006f64055ebe3/crawl4ai/browser_profiler.py#L183-L219","documentation":"BrowserProfiler._listen_windows is the Windows keyboard listener used during interactive profiling; it imports msvcrt and converts an ImportError into this clearer ImportError. Seeing it means the method ran on a platform where msvcrt does not exist (any non-Windows OS), i.e. the wrong listener was selected for the OS.","triggerScenarios":"Calling _listen_windows() directly on Linux/macOS, or a dispatch bug/environment where sys.platform detection routed to the Windows listener on a Unix system. Normal flows call it only on win32.","commonSituations":"Monkeypatching or subclassing the profiler and calling private listeners in tests on Unix; running under WSL interop quirks where platform detection misfires; importing and invoking internal helpers directly.","solutions":["Don't call _listen_windows directly; use the profiler's public interactive flow which picks _listen_unix on non-Windows platforms.","On Unix use _listen_unix (termios-based) if you must call a listener manually.","Gate any direct call behind sys.platform == 'win32'."],"exampleFix":"# before\nawait profiler._listen_windows(event, check_proc, 'PROFILE')  # on Linux -> ImportError\n\n# after\nimport sys\nlistener = profiler._listen_windows if sys.platform == 'win32' else profiler._listen_unix\nawait listener(event, check_proc, 'PROFILE')","handlingStrategy":"validation","validationCode":"import sys\nif sys.platform != 'win32':\n    raise OSError('Windows keyboard listener requires Windows')","typeGuard":"import sys\ndef is_windows() -> bool:\n    return sys.platform == 'win32'","tryCatchPattern":null,"preventionTips":["Never call the private _listen_* helpers; use the public interactive flow.","Gate platform-specific listeners behind sys.platform checks."],"tags":["browser-profiler","windows","platform-specific"],"backgroundTag":null,"analyzedSha":"7e801521428ee12509994d39151006f64055ebe3","analyzedAt":"2026-08-14T20:46:20.673Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}