diff --git a/browser-service/src/core/browser.py b/browser-service/src/core/browser.py index d2e8539..8a5eccf 100644 --- a/browser-service/src/core/browser.py +++ b/browser-service/src/core/browser.py @@ -61,11 +61,22 @@ if session_id in self.pages: del self.pages[session_id] if session_id in self.contexts: del self.contexts[session_id] - context = await self._browser.new_context( - viewport={'width': 1280, 'height': 800}, - user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36' - ) - page = await context.new_page() + import asyncio + for attempt in range(2): + try: + context = await asyncio.wait_for( + self._browser.new_context( + viewport={'width': 1280, 'height': 800}, + user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36' + ), timeout=20.0 + ) + page = await asyncio.wait_for(context.new_page(), timeout=20.0) + break + except Exception as e: + logger.warning(f"Browser stall during context creation: {e}. Reigniting underlying chromium daemon (Attempt {attempt+1}/2)...") + await self.init() + else: + raise Exception("CRITICAL: Repeated chromium daemon lockups halted context injection securely.") # Apply stealth (synchronous) - Disabled temporarily due to module call error # playwright_stealth.stealth(page)