Skip to content

Commit

Permalink
[apps/browser] desktop size and improved error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
javierluraschi committed Sep 16, 2024
1 parent 21b4850 commit 237c687
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions apps/browser/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from siteuse import site_use

async def take_screenshot(page):
await asyncio.sleep(3)
await asyncio.sleep(5)
await page.screenshot({'path': "screenshot.png"})
shutil.copy("screenshot.png", f"storage/screenshot-{int(time.time())}.png")

Expand All @@ -29,10 +29,11 @@ async def main():
custom_user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36"
browser = await pyppeteer.launch(
headless=True,
args=['--no-sandbox', '--disable-setuid-sandbox', f"--window-size=1470,832"]
args=['--no-sandbox', '--disable-setuid-sandbox']
)

page = await browser.newPage()
await page.setViewport(viewport={'width': 1280, 'height': 800})

await page.setUserAgent(custom_user_agent)

Expand Down Expand Up @@ -68,6 +69,13 @@ async def main():
prompt = h9.input()
except Exception as e:
print(f"Failed to use browser:\n```\n{e}\n```\n")

try:
await take_screenshot(page)
elements = await extract_elements(page)
except Exception as e:
print("Failed to get elements from page")

prompt = h9.input(f"Last request failed, should I retry?")
prompt = f"Failed to run the following code:\n\n{code}\n\nCode triggered the following error:\n\n{e}.\n\nAsked users to retry, user replied: " + prompt

Expand Down

0 comments on commit 237c687

Please sign in to comment.