Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
manually copy over browser_context instance when forking BrowserSession
Nick Sweetingc3bd596961a4
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.pyindex ddb800613..5bf7e9328 100644--- a/browser_use/agent/service.py+++ b/browser_use/agent/service.py@@ -349,12 +349,19 @@ class Agent(Generic[Context]):)# always copy sessions that are passed in to avoid agents overwriting each other's agent_current_page and human_current_page by accident+ # model_copy() doesn't copy excluded fields, so we need to manually copy themself.browser_session = browser_session.model_copy(# update={# 'agent_current_page': None, # dont reset these, let the next agent start on the same page as the last agent# 'human_current_page': None,# },)+ # Manually copy over the excluded fields that are needed for browser connection+ self.browser_session.playwright = browser_session.playwright+ self.browser_session.browser = browser_session.browser+ self.browser_session.browser_context = browser_session.browser_context+ self.browser_session.agent_current_page = browser_session.agent_current_page+ self.browser_session.human_current_page = browser_session.human_current_pageelse:if browser is not None:assert isinstance(browser, Browser), 'Browser is not set up'