Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

limit screenshot wait for load timeout

Nick Sweeting26e585315003
diff --git a/browser_use/browser/session.py b/browser_use/browser/session.py
index a4dc11171..016bfc8cc 100644
--- a/browser_use/browser/session.py
+++ b/browser_use/browser/session.py
@@ -1633,6 +1633,7 @@ class BrowserSession(BaseModel):
raise
# region - Browser Actions
+ @require_initialization
@time_execution_async('--take_screenshot')
async def take_screenshot(self, full_page: bool = False) -> str:
"""
@@ -1643,7 +1644,9 @@ class BrowserSession(BaseModel):
# We no longer force tabs to the foreground as it disrupts user focus
# await self.agent_current_page.bring_to_front()
page = await self.get_current_page()
- await page.wait_for_load_state()
+ await page.wait_for_load_state(
+ timeout=5000,
+ ) # page has already loaded by this point, this is extra for previous action animations/frame loads to settle
screenshot = await self.agent_current_page.screenshot(
full_page=full_page,