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
Option to keep browser open
magmuellerdbcd24c4bfd8
diff --git a/src/agent/service.py b/src/agent/service.pyindex 4619b3ccf..244743fee 100644--- a/src/agent/service.py+++ b/src/agent/service.py@@ -70,8 +70,8 @@ class AgentService:return action, resultasync def _take_human_input(self, question: str) -> AgentOutput:- human_input = input(f'Human input required: {question}')-+ human_input = input(f'Human input required: {question}\n\n')+ print('-' * 50)self.messages.append(HumanMessage(content=human_input))structured_llm = self.llm.with_structured_output(AgentOutput)diff --git a/src/browser/service.py b/src/browser/service.pyindex ace85f674..93e9718bf 100644--- a/src/browser/service.py+++ b/src/browser/service.py@@ -25,14 +25,15 @@ from src.utils import time_execution_syncclass BrowserService:- def __init__(self, headless: bool = False):+ def __init__(self, headless: bool = False, keep_open: bool = False):self.headless = headlessself.driver: webdriver.Chrome | None = Noneself._ob = Screenshot.Screenshot()self.MINIMUM_WAIT_TIME = 0.5self.MAXIMUM_WAIT_TIME = 5self._current_handle = None # Track current handle- self._tab_cache = {} # Cache tab info+ self._tab_cache = {}+ self.keep_open = keep_opendef init(self) -> webdriver.Chrome:"""@@ -93,6 +94,9 @@ class BrowserService:)self.driver = driver++ # driver.get('https://www.google.com')+return driverdef _get_driver(self) -> webdriver.Chrome:@@ -147,9 +151,12 @@ class BrowserService:return self.current_statedef close(self):- driver = self._get_driver()- driver.quit()- self.driver = None+ if not self.keep_open:+ driver = self._get_driver()+ driver.quit()+ self.driver = None+ else:+ input('Press Enter to close Browser...')def __del__(self):"""diff --git a/src/controller/service.py b/src/controller/service.pyindex ef47e7c15..16e9f6603 100644--- a/src/controller/service.py+++ b/src/controller/service.py@@ -16,8 +16,8 @@ class ControllerService:TODO#2: from the state generate functions that can be passed directly into the LLM as function calls. Then it could actually in the same call request for example multiple actions and new state."""- def __init__(self):- self.browser = BrowserService()+ def __init__(self, keep_open: bool = False):+ self.browser = BrowserService(keep_open=keep_open)self.cached_browser_state: BrowserState | None = None@time_execution_sync('--get_cached_browser_state')