async def connect_to_chrome(self, 
                              timeout: float = 30,
                              retries: int = 3) -> Tuple[async_playwright, Browser, BrowserContext]:
        """Connect to existing Chrome instance with retry logic"""
        self._playwright = await async_playwright().start()
        
        print("Starting Chrome with remote debugging...")
        chrome_process = await self.launch_chrome_with_remote_debugging()
        
        await asyncio.sleep(3)  # Wait for Chrome to start
        
        print("Attempting to connect to Chrome...")
        for attempt in range(retries):
            try:
                # Connect to the existing Chrome instance
                ws_endpoint = None
                print("Getting browser websocket URL")
                # Get the WebSocket endpoint from Chrome's debugging API
                async with aiohttp.ClientSession() as session:
                    # Then get the browser websocket URL
                    print("Getting browser websocket URL")
                    async with session.get("http://127.0.0.1:9222/json/version") as response:
                        data = await response.json()
                        ws_endpoint = data.get('webSocketDebuggerUrl')
                
                if not ws_endpoint:
                    raise RuntimeError("Could not get WebSocket debugger URL")
                
                print(f"Connecting to WebSocket endpoint: {ws_endpoint}")
                self._browser = await self._playwright.chromium.connect_over_cdp(
                    ws_endpoint
                )


                print("Connected to browser:", self._browser)
                
                # Use the first available context instead of creating a new one
                contexts = self._browser.contexts
                if not contexts:
                    raise RuntimeError("No browser contexts available after connection")
                self._context = contexts[0]
                print("Context: ", self._context)
                
                print("Successfully connected to Chrome")
                return self._browser, self._context
            
            except Exception as e:
                print(f"Connection attempt {attempt + 1} failed: {str(e)}")
                if attempt == retries - 1:
                    raise RuntimeError(f"Failed to connect to Chrome after {retries} attempts: {str(e)}")
                await asyncio.sleep(2 ** attempt)
Connect to existing Chrome instance with retry logic
backend/Browser/webrover_browser.py