Skip to content

Commit 70b973d

Browse files
committed
add fallback of playwright locator screenshot
1 parent e9109b9 commit 70b973d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

dataframe_image/converter/browser/playwright_converter.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ def screenshot(self, html):
8282
)
8383
pass
8484
page.wait_for_timeout(200)
85-
screenshot_bytes = locator.screenshot(timeout=1000)
85+
try:
86+
screenshot_bytes = locator.screenshot(timeout=1000)
87+
except Error:
88+
logger.warning("Locator screenshot timed out. Taking full page screenshot instead.")
89+
screenshot_bytes = page.screenshot(timeout=1000)
8690
im = Image.open(BytesIO(screenshot_bytes))
8791
return im
8892

@@ -168,6 +172,10 @@ async def screenshot(self, html):
168172
)
169173
pass
170174
page.wait_for_timeout(200)
171-
screenshot_bytes = await locator.screenshot(timeout=1000)
175+
try:
176+
screenshot_bytes = await locator.screenshot(timeout=1000)
177+
except Error:
178+
logger.warning("Locator screenshot timed out. Taking full page screenshot instead.")
179+
screenshot_bytes = await page.screenshot(timeout=1000)
172180
im = Image.open(BytesIO(screenshot_bytes))
173181
return im

0 commit comments

Comments
 (0)