Skip to content

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

only steal human tab focus when absolutely necessary

Nick Sweeting4b7cbf23fa8e
diff --git a/browser_use/browser/session.py b/browser_use/browser/session.py
index caca1d04e..c08840311 100644
--- a/browser_use/browser/session.py
+++ b/browser_use/browser/session.py
@@ -2587,10 +2587,15 @@ class BrowserSession(BaseModel):
# Update both tab references - agent wants this tab, and it's now in the foreground
self.agent_current_page = page
+
+ # in order for a human watching to be able to follow along with what the agent is doing
+ # bring the agent's active tab to the foreground
+ if self.human_current_page != page:
+ # TODO: figure out how to do this without bringing the entire window to the foreground and stealing foreground app focus
+ await page.bring_to_front()
+
self.human_current_page = page
- # Bring tab to front and wait for it to load
- await page.bring_to_front()
await page.wait_for_load_state()
# Set the viewport size for the tab