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 dead code removal
Nick Sweeting0e6102db3bde
diff --git a/browser_use/browser/compat.py b/browser_use/browser/compat.pydeleted file mode 100644index 53465da6d..000000000--- a/browser_use/browser/compat.py+++ /dev/null@@ -1,86 +0,0 @@-DEPRECATION_MESSAGE = """-↗️ We have moved to a new, simplified BrowserProfile and BrowserSession API. Old code that uses browser_use.browser.{} must be updated.--👍 Thank you for your patience as we work to simplify our API! Migration is easy:-- from browser_use.browser import BrowserProfile, BrowserSession-- # the new 👤 BrowserProfile(...) and 🚀 BrowserSession(...) support 100% standard 🎭 playwright options:- #-- # 1. 👤 create a BrowserProfile() object and put *all* your browser-related config into it- browser_profile = BrowserProfile(- # 🎭 all the standard Playwright launch & context options can go here:- executable_path='/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',- user_data_dir='/path/to/user_data_dir',- headless=False,- args=['--start-maximized'],- ignore_default_args=['--enable-automation'],- viewport={{'width': 1920, 'height': 1080}},- has_touch=False,- user_agent='...',- # ... see more: https://playwright.dev/python/docs/api/class-browsertype#browser-type-launch-persistent-context-- # ♾️ Browser-Use's browser options can also go here:- # Browser(...) ➡️ move here ⬇️ ...- # BrowserConfig(...) ➡️ move here ⬇️ ...- # BrowserContextConfig(...) ➡️ move here ⬇️ ...- highlight_elements=True,- allowed_domains=['example.com', '*.google.com'],- disable_security=False,- keep_alive=True,- window_size={{'width': 1920, 'height': 1080}},- # ... see more: https://docs.browser-use.com/customize/browser-settings#context-configuration- )-- # 2. 🚀 create a BrowserSession() to connect to a browser- browser_session = BrowserSession(- # A. Local: pass a 👤 BrowserProfile to launch a local browser with that config- browser_profile=browser_profile,- # ... extra kwargs can be passed to override browser_profile settings on a per-session basis, e.g.:- # executable_path='/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary',- # user_data_dir='~/Desktop/new-test-profile',- # headless=True,-- # OR B. Remote: pass 🔗 cdp_url or wss_URL to use an existing remote browser- # cdp_url='http://localhost:9222',- # wss_url='ws://some-playwright-node-server:9292',-- # OR C. Existing: pass existing playwright/patchright browser objects- # browser=playwright_browser_obj,- # browser_context=playwright_browser_context_obj,- )- agent = Agent(browser_session=browser_session, ...)- ...-- # custom actions should be updated to take browser_session instead of browser_context:- @controller.registry.action('Custom action to insert some text into a field')- def insert_text_into_field(text: str, browser_session: BrowserSession):- page = await browser_session.get_current_page()- await page.keyboard.type(text)- return ActionResult(result=text)-"""---class DeprecatedClass:- def __init__(self, *_args, **_kwargs):- print(DEPRECATION_MESSAGE.format(type(self).__name__))- raise NotImplementedError(- 'The old Browser, BrowserConfig, BrowserContext, BrowserContextConfig have been deprecated in favor of a simplified BrowserProfile + BrowserSession.'- )---class BrowserConfig(DeprecatedClass):- pass---class BrowserContextConfig(DeprecatedClass):- pass---class Browser(DeprecatedClass):- pass---class BrowserContext(DeprecatedClass):- passdiff --git a/browser_use/browser/profile.py b/browser_use/browser/profile.pyindex 76b95859f..cf06c5348 100644--- a/browser_use/browser/profile.py+++ b/browser_use/browser/profile.py@@ -746,23 +746,3 @@ class BrowserProfile(BrowserConnectArgs, BrowserLaunchPersistentContextArgs, Broself.viewport = Noneself.device_scale_factor = Noneself.screen = None---# For convenience, example function signatures:-"""-def launch(- **kwargs: Unpack[LaunchArgs]-) -> Browser:- ...--def new_context(- **kwargs: Unpack[NewContextArgs]-) -> BrowserContext:- ...--def launch_persistent_context(- user_data_dir: str | Path,- **kwargs: Unpack[LaunchPersistentContextArgs]-) -> BrowserContext:- ...-"""diff --git a/browser_use/browser/session.py b/browser_use/browser/session.pyindex 0338d2a8f..c2920e7fc 100644--- a/browser_use/browser/session.py+++ b/browser_use/browser/session.py@@ -1910,71 +1910,3 @@ class BrowserSession(BaseModel):new_filename = f'{base} ({counter}){ext}'counter += 1return new_filename-- # async def _resize_window(self, context: PlaywrightBrowserContext) -> None:- # """Old approach to resize the browser window to match the configured size"""-- #- # BROWSER_NAVBAR_HEIGHT = {- # 'windows': 85,- # 'darwin': 80,- # 'linux': 90,- # }.get(platform.system().lower(), 85)-- # try:- # if not context.pages:- # return-- # page = context.pages[0]- # window_size = {'width': self.browser_profile.window_width, 'height': self.browser_profile.window_height}-- # # First, set the viewport size- # if self.browser_profile.viewport:- # await page.set_viewport_size(self.browser_profile.viewport)-- # # Then, try to set the actual window size using CDP- # try:- # cdp_session = await context.new_cdp_session(page)-- # # Get the window ID- # window_id_result = await cdp_session.send('Browser.getWindowForTarget')-- # # Set the window bounds- # await cdp_session.send(- # 'Browser.setWindowBounds',- # {- # 'windowId': window_id_result['windowId'],- # 'bounds': {- # 'width': window_size['width'],- # 'height': window_size['height'] + BROWSER_NAVBAR_HEIGHT, # Add height for browser chrome- # 'windowState': 'normal', # Ensure window is not minimized/maximized- # },- # },- # )-- # await cdp_session.detach()- # logger.debug(f'Set window size to {window_size["width"]}x{window_size["height"] + BROWSER_NAVBAR_HEIGHT}')- # except Exception as e:- # logger.debug(f'CDP window resize failed: {e}')-- # # Fallback to using JavaScript- # try:- # await page.evaluate(- # """- # (width, height) => {- # window.resizeTo(width, height);- # }- # """,- # window_size['width'],- # window_size['height'] + BROWSER_NAVBAR_HEIGHT,- # )- # logger.debug(- # f'Used JavaScript to set window size to {window_size["width"]}x{window_size["height"] + BROWSER_NAVBAR_HEIGHT}'- # )- # except Exception as e:- # logger.debug(f'JavaScript window resize failed: {e}')-- # logger.debug(f'Attempted to resize window to {window_size["width"]}x{window_size["height"]}')- # except Exception as e:- # logger.debug(f'Failed to resize browser window: {e}')- # # Non-critical error, continue execution