"""Utility functions for the Cloud Browser API.""" import logging import asyncio import psutil from typing import Dict, Any, List # Configure logging logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) def setup_logger(): """Set up and return the logger.""" return logger async def get_loop_time(): """Get the current event loop time.""" return asyncio.get_event_loop().time() def get_memory_usage(): """Get the current system memory usage as a percentage.""" return psutil.virtual_memory().percent def clean_browser_references( browser_id: str, browser_instances: Dict[str, Any], browser_contexts: Dict[str, Any], browser_pages: Dict[str, Any], browser_clients: Dict[str, List], ): """Remove all references to a browser instance.""" if browser_id in browser_instances: del browser_instances[browser_id] for collection in [browser_contexts, browser_pages, browser_clients]: if browser_id in collection: del collection[browser_id] # Fixed: changed 'bid' to 'browser_id'