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
more stealth browser launch tuning
Nick Sweetingc6504da9ea3d
diff --git a/browser_use/browser/profile.py b/browser_use/browser/profile.pyindex e2a0e8da2..76b95859f 100644--- a/browser_use/browser/profile.py+++ b/browser_use/browser/profile.py@@ -92,8 +92,8 @@ CHROME_DOCKER_ARGS = ['--disable-setuid-sandbox','--disable-dev-shm-usage','--no-xshm',- # '--no-zygote',- # '--single-process',+ '--no-zygote',+ '--single-process',]CHROME_DISABLE_SECURITY_ARGS = [@@ -109,7 +109,7 @@ CHROME_DISABLE_SECURITY_ARGS = [CHROME_DETERMINISTIC_RENDERING_ARGS = ['--deterministic-mode','--js-flags=--random-seed=1157259159',- '--force-device-scale-factor=1',+ '--force-device-scale-factor=2','--enable-webgl',# '--disable-skia-runtime-opts',# '--disable-2d-canvas-clip-aa',@@ -140,7 +140,7 @@ CHROME_DEFAULT_ARGS = ['--disable-popup-blocking','--disable-prompt-on-repost','--disable-renderer-backgrounding',- '--force-color-profile=srgb',+ # '--force-color-profile=srgb', # moved to CHROME_DETERMINISTIC_RENDERING_ARGS'--metrics-recording-only','--no-first-run','--password-store=basic',@@ -407,6 +407,7 @@ class BrowserLaunchArgs(BaseModel):from_attributes=True,validate_by_name=True,validate_by_alias=True,+ populate_by_name=True,)env: dict[str, str | float | bool] = Field(diff --git a/browser_use/browser/session.py b/browser_use/browser/session.pyindex 7e0865b1a..0338d2a8f 100644--- a/browser_use/browser/session.py+++ b/browser_use/browser/session.py@@ -228,7 +228,8 @@ class BrowserSession(BaseModel):try:psutil.Process(pid=self.chrome_pid).terminate()except Exception as e:- logger.debug(f'❌ Error terminating chrome subprocess pid={self.chrome_pid}: {type(e).__name__}: {e}')+ if 'NoSuchProcess' not in type(e).__name__:+ logger.debug(f'❌ Error terminating chrome subprocess pid={self.chrome_pid}: {type(e).__name__}: {e}')async def close(self) -> None:"""Shortcut for self.stop()"""@@ -396,7 +397,7 @@ class BrowserSession(BaseModel):assert self.browser.is_connected(), (f'Browser is not connected, did the browser process crash or get killed? (connection method: {connection_method})')- logger.debug(f'🌎 {connection_method} Browser connected: {self.browser.version}')+ logger.debug(f'🌎 {connection_method} Browser connected: v{self.browser.version}')assert self.browser_context, f'BrowserContext {self.browser_context} is not set up'return self.browser_context@@ -1804,7 +1805,7 @@ class BrowserSession(BaseModel):await new_page.set_viewport_size(self.browser_profile.viewport)if url:- await new_page.goto(url)+ await new_page.goto(url, wait_until='domcontentloaded', timeout=10000)await self._wait_for_page_and_frames_load(timeout_overwrite=1)assert self.human_current_page is not Nonediff --git a/examples/browser/stealth.py b/examples/browser/stealth.pyindex 970adaa3e..316b9695b 100644--- a/examples/browser/stealth.py+++ b/examples/browser/stealth.py@@ -13,7 +13,6 @@ load_dotenv()from imgcat import imgcatfrom langchain_openai import ChatOpenAIfrom patchright.async_api import async_playwright as async_patchright-from playwright.async_api import async_playwrightfrom browser_use.browser import BrowserSession@@ -23,15 +22,21 @@ terminal_width, terminal_height = shutil.get_terminal_size((80, 20))async def main():- browser_session = BrowserSession(- playwright=await async_playwright().start(),+ # Default Playwright Chromium Browser+ normal_browser_session = BrowserSession(headless=False,- disable_security=True,user_data_dir=None,- deterministic_rendering=True,+ # deterministic_rendering=False,)+ await normal_browser_session.start()+ await normal_browser_session.create_new_tab('https://abrahamjuliot.github.io/creepjs/')+ await asyncio.sleep(5)+ await (await normal_browser_session.get_current_page()).screenshot(path='normal_browser.png')+ imgcat(Path('normal_browser.png').read_bytes(), height=max(terminal_height - 15, 40))+ await normal_browser_session.close()- stealth_browser_session = BrowserSession(+ print('\n\nPATCHRIGHT STEALTH BROWSER:')+ patchright_browser_session = BrowserSession(# cdp_url='wss://browser.zenrows.com?apikey=your-api-key-here&proxy_region=na',# or try anchor browser, browserless, steel.dev, browserbase, oxylabs, brightdata, etc.playwright=await async_patchright().start(),@@ -40,20 +45,50 @@ async def main():user_data_dir='~/.config/browseruse/profiles/stealth',deterministic_rendering=False,)- await browser_session.start()- await stealth_browser_session.start()- await browser_session.create_new_tab('https://abrahamjuliot.github.io/creepjs/')- await stealth_browser_session.create_new_tab('https://abrahamjuliot.github.io/creepjs/')+ await patchright_browser_session.start()+ await patchright_browser_session.create_new_tab('https://abrahamjuliot.github.io/creepjs/')await asyncio.sleep(5)- await (await browser_session.get_current_page()).screenshot(path='normal_browser.png')- print('NORMAL BROWSER:')- imgcat(Path('normal_browser.png').read_bytes(), height=max(terminal_height - 15, 40))- print()- print()-- print('STEALTH BROWSER:')- await (await stealth_browser_session.get_current_page()).screenshot(path='stealth_browser.png')- imgcat(Path('stealth_browser.png').read_bytes(), height=max(terminal_height - 15, 40))+ await (await patchright_browser_session.get_current_page()).screenshot(path='patchright_browser.png')+ imgcat(Path('patchright_browser.png').read_bytes(), height=max(terminal_height - 15, 40))+ await patchright_browser_session.close()++ # Brave Browser+ if Path('/Applications/Brave Browser.app/Contents/MacOS/Brave Browser').is_file():+ print('\n\nBRAVE BROWSER:')+ brave_browser_session = BrowserSession(+ executable_path='/Applications/Brave Browser.app/Contents/MacOS/Brave Browser',+ headless=False,+ disable_security=False,+ user_data_dir='~/.config/browseruse/profiles/brave',+ deterministic_rendering=False,+ )+ await brave_browser_session.start()+ await brave_browser_session.create_new_tab('https://abrahamjuliot.github.io/creepjs/')+ await asyncio.sleep(5)+ await (await brave_browser_session.get_current_page()).screenshot(path='brave_browser.png')+ imgcat(Path('brave_browser.png').read_bytes(), height=max(terminal_height - 15, 40))+ await brave_browser_session.close()++ if Path('/Applications/Brave Browser.app/Contents/MacOS/Brave Browser').is_file():+ print('\n\nBRAVE + PATCHRIGHT STEALTH BROWSER:')+ brave_patchright_browser_session = BrowserSession(+ executable_path='/Applications/Brave Browser.app/Contents/MacOS/Brave Browser',+ playwright=await async_patchright().start(),+ headless=False,+ disable_security=False,+ user_data_dir=None,+ deterministic_rendering=False,+ )+ await brave_patchright_browser_session.start()+ await brave_patchright_browser_session.create_new_tab('https://abrahamjuliot.github.io/creepjs/')+ await asyncio.sleep(5)+ await (await brave_patchright_browser_session.get_current_page()).screenshot(path='brave_patchright_browser.png')+ imgcat(Path('brave_patchright_browser.png').read_bytes(), height=max(terminal_height - 15, 40))++ input('Press [Enter] to close the browser...')+ await brave_patchright_browser_session.close()++ # print()# agent = Agent(# task="""# Go to https://abrahamjuliot.github.io/creepjs/ and verify that the detection score is >50%.@@ -103,7 +138,7 @@ async def main():# )# await agent.run()- input('Press Enter to close the browser...')+ # input('Press Enter to close the browser...')if __name__ == '__main__':