Skip to content

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

restore global screenshot lock

Nick Sweeting428d7340725d
diff --git a/browser_use/browser/session.py b/browser_use/browser/session.py
index 32ffd60fc..a85f709ac 100644
--- a/browser_use/browser/session.py
+++ b/browser_use/browser/session.py
@@ -714,6 +714,10 @@ class BrowserSession(BaseModel):
wait=1, # wait 1s between each attempt to take a screenshot
retries=2, # try up to 2 times to take the screenshot
timeout=20, # allow up to 20s for each attempt to take a screenshot
+ semaphore_limit=1, # Only one screenshot at a time across all processes
+ semaphore_name='screenshot_global',
+ semaphore_scope='multiprocess',
+ semaphore_lax=True, # Continue without semaphore if it can't be acquired
)
async def _take_screenshot_hybrid(self, page: Page, clip: dict[str, int] | None = None) -> str:
"""Take screenshot using Playwright, with retry and semaphore protection."""