diff --git a/dataframe_image/converter/browser/playwright_converter.py b/dataframe_image/converter/browser/playwright_converter.py index 25892ee..8e14d39 100644 --- a/dataframe_image/converter/browser/playwright_converter.py +++ b/dataframe_image/converter/browser/playwright_converter.py @@ -82,7 +82,11 @@ def screenshot(self, html): ) pass page.wait_for_timeout(200) - screenshot_bytes = locator.screenshot(timeout=1000) + try: + screenshot_bytes = locator.screenshot(timeout=1000) + except Error: + logger.warning("Locator screenshot timed out. Taking full page screenshot instead.") + screenshot_bytes = page.screenshot(timeout=1000) im = Image.open(BytesIO(screenshot_bytes)) return im @@ -168,6 +172,10 @@ async def screenshot(self, html): ) pass page.wait_for_timeout(200) - screenshot_bytes = await locator.screenshot(timeout=1000) + try: + screenshot_bytes = await locator.screenshot(timeout=1000) + except Error: + logger.warning("Locator screenshot timed out. Taking full page screenshot instead.") + screenshot_bytes = await page.screenshot(timeout=1000) im = Image.open(BytesIO(screenshot_bytes)) return im