Skip to content

Commit

Permalink
add navigation timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
lalalune committed Aug 2, 2023
1 parent 082e7c8 commit a896b1c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
8 changes: 4 additions & 4 deletions agentbrowser/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def close_page(page):
asyncio.get_event_loop().run_until_complete(async_close_page(page))


def navigate_to(url, page, wait_until="domcontentloaded"):
def navigate_to(url, page, wait_until="domcontentloaded", timeout=10000):
"""
Navigate to a URL in a page.
Expand All @@ -97,7 +97,7 @@ def navigate_to(url, page, wait_until="domcontentloaded"):
:rtype: playwright.async_api.Page
"""
ensure_event_loop()
return asyncio.get_event_loop().run_until_complete(async_navigate_to(url, page, wait_until=wait_until))
return asyncio.get_event_loop().run_until_complete(async_navigate_to(url, page, wait_until=wait_until, timeout=timeout))


def get_document_html(page):
Expand Down Expand Up @@ -255,7 +255,7 @@ async def async_close_page(page):
await page.close()


async def async_navigate_to(url, page, wait_until="domcontentloaded"):
async def async_navigate_to(url, page, wait_until="domcontentloaded", timeout=10000):
"""
Navigate to a URL in a page asynchronously.
Expand All @@ -269,7 +269,7 @@ async def async_navigate_to(url, page, wait_until="domcontentloaded"):
if not page:
page = await async_create_page(None)
try:
await page.goto(url, wait_until=wait_until)
await page.goto(url, wait_until=wait_until, timeout=timeout)
except Exception as e:
print("Error navigating to: " + url)
print(e)
Expand Down
1 change: 1 addition & 0 deletions agentbrowser/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def test_document_html():
def test_body_text():
test_page = create_page(test_article)
body = get_body_text(test_page)
print(body)
assert body is not None, "Failed to get body text."
print("test_body_text passed.")

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

setup(
name="agentbrowser",
version="0.2.1",
version="0.2.2",
description="A browser for your agent, built on Playwright.",
long_description=long_description, # added this line
long_description_content_type="text/markdown", # and this line
Expand Down

0 comments on commit a896b1c

Please sign in to comment.