diff --git a/Dockers/puppeteer-api/app/utils/browser_utils.py b/Dockers/puppeteer-api/app/utils/browser_utils.py index 4e7d8b1..0a1a9d7 100644 --- a/Dockers/puppeteer-api/app/utils/browser_utils.py +++ b/Dockers/puppeteer-api/app/utils/browser_utils.py @@ -11,6 +11,8 @@ async def safe_browser_operation(url, operation_func): browser = None context = None page = None + playwright = None + try: # Get or create playwright instance playwright = await async_playwright().start() @@ -64,4 +66,10 @@ async def safe_browser_operation(url, operation_func): await browser.close() except Exception as e: print(f"Error closing browser: {e}") - # We don't re-raise here to avoid masking the original error \ No newline at end of file + + # Ensure playwright is closed properly - THIS IS THE KEY FIX + if playwright: + try: + await playwright.stop() + except Exception as e: + print(f"Error closing playwright: {e}") \ No newline at end of file