Skip to content

Commit

Permalink
Merge pull request #60 from hhslepicka/fix-screenshot
Browse files Browse the repository at this point in the history
FIX: Handle failure at get_screenshot when driver is not ready.
  • Loading branch information
hhslepicka committed Jul 5, 2022
2 parents d046e88 + 7facb89 commit e34c6b8
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions botcity/web/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,14 +312,18 @@ def get_screen_image(self, region=None):
if not region:
region = (0, 0, 0, 0)

data = self._driver.get_screenshot_as_base64()
image_data = base64.b64decode(data)
img = Image.open(io.BytesIO(image_data))

x = region[0]
y = region[1]
width = region[2] or self._get_page_size()[0]
height = region[3] or self._get_page_size()[1]

try:
data = self._driver.get_screenshot_as_base64()
image_data = base64.b64decode(data)
img = Image.open(io.BytesIO(image_data))
except: # noqa: E722
img = Image.new("RGB", (width, height))

img = img.crop((x, y, x + width, y + height))
return img

Expand Down

0 comments on commit e34c6b8

Please sign in to comment.